feat(api): maintenance operations with the operator's opt-in

Merged
EV
3d ago
+1458-36

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_operations in app.ever.co (consent), and TR_EVER_CONNECT_INTEGRATIONS_DENY does 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.

KindHereDatabases
health_reportAPI up, database reachableall
backupbetter-sqlite3 online backup plus a manifest (size, SHA-256) in the operator's backup directorySQLite
restore_checkthe named (or newest) backup still matches its manifestSQLite
backup / restore_check on PostgreSQL or MySQLrefused, unsupported_dialect: the image ships no pg_dump/mysqldump, and a consistent dump needs themn/a
updatenever run, update_not_supported: the API cannot replace its own container image from inside itn/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 only backupDirSet.
  • History: the last 50 operations. Audit rows: managed.opt_in / opt_out / policy / refused / result.
  • New tables ever_connect_managed_policy and ever_connect_managed_operation. They share one renderer for postgres/mysql/sqlite with the person tables of #625 (utils/ever-platform-tables.ts).
  • managed_operations is now listed with Traduora's integrations (it shows coming_soon until 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 result failed)
    • 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.ts is dialect-aware: SQLite backs up for real, PostgreSQL/MySQL refuse unsupported_dialect. It also covers operator-only routes, refusal before opt-in, and the audit.
  • ever-connect-off.e2e-spec.ts: /ever-connect/managed does not exist with the module off.
  • Run locally on SQLite: all test/ever-connect* e2e suites and src/ever-connect unit suites green; tslint and prettier clean. The three-database ci matrix 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=false turns 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).