@paradow/ledge-relay 0.0.0-stage → 0.61.0-pre.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/LICENSE +75 -0
  2. package/README.md +233 -2
  3. package/dist/chunk-HTYEMUSI.js +5158 -0
  4. package/dist/cli.js +434 -0
  5. package/dist/main.js +25 -0
  6. package/package.json +42 -4
  7. package/web/assets/App-zclWYn2G.js +23 -0
  8. package/web/assets/boot-GtprRTxP.js +1 -0
  9. package/web/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
  10. package/web/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
  11. package/web/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
  12. package/web/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
  13. package/web/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2 +0 -0
  14. package/web/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2 +0 -0
  15. package/web/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2 +0 -0
  16. package/web/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
  17. package/web/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2 +0 -0
  18. package/web/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2 +0 -0
  19. package/web/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
  20. package/web/assets/index-C0ikeXTk.css +1 -0
  21. package/web/assets/index-CytIBIB5.js +52 -0
  22. package/web/assets/label-8OD9J9FC.js +1 -0
  23. package/web/assets/xterm-CATQzocj.js +9 -0
  24. package/web/assets/xterm-DYP7pi_n.css +32 -0
  25. package/web/build.json +1 -0
  26. package/web/favicon-32.png +0 -0
  27. package/web/favicon.svg +1 -0
  28. package/web/icon-180.png +0 -0
  29. package/web/icon-192.png +0 -0
  30. package/web/icon-512.png +0 -0
  31. package/web/icon-maskable-512.png +0 -0
  32. package/web/index.html +22 -0
  33. package/web/manifest.webmanifest +29 -0
  34. package/web/sw.js +2 -0
package/LICENSE ADDED
@@ -0,0 +1,75 @@
1
+ Required Notice: Copyright the kl-ledge authors (https://kl-ledge.dev)
2
+
3
+ # PolyForm Noncommercial License 1.0.0
4
+
5
+ <https://polyformproject.org/licenses/noncommercial/1.0.0>
6
+
7
+ ## Acceptance
8
+
9
+ In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
10
+
11
+ ## Copyright License
12
+
13
+ The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
14
+
15
+ ## Distribution License
16
+
17
+ The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
18
+
19
+ ## Notices
20
+
21
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
22
+
23
+ > Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
24
+
25
+ ## Changes and New Works License
26
+
27
+ The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
28
+
29
+ ## Patent License
30
+
31
+ The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
32
+
33
+ ## Noncommercial Purposes
34
+
35
+ Any noncommercial purpose is a permitted purpose.
36
+
37
+ ## Personal Uses
38
+
39
+ Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, is use for a permitted purpose.
40
+
41
+ ## Noncommercial Organizations
42
+
43
+ Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution is use for a permitted purpose regardless of the source of funding or obligations resulting from the funding.
44
+
45
+ ## Fair Use
46
+
47
+ You may have "fair use" rights for the software under the law. These terms do not limit them.
48
+
49
+ ## No Other Rights
50
+
51
+ These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
52
+
53
+ ## Patent Defense
54
+
55
+ If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
56
+
57
+ ## Violations
58
+
59
+ The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
60
+
61
+ ## No Liability
62
+
63
+ ***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
64
+
65
+ ## Definitions
66
+
67
+ The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
68
+
69
+ **You** refers to the individual or entity agreeing to these terms.
70
+
71
+ **Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
72
+
73
+ **Your licenses** are all the licenses granted to you for the software under these terms.
74
+
75
+ **Use** means anything you do with the software requiring one of your licenses.
package/README.md CHANGED
@@ -1,3 +1,234 @@
1
- # Temporary Holding Version
1
+ # @paradow/ledge-relay
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Relay between phones and a PC. It routes opaque end-to-end-encrypted bodies and never decrypts them; no content is stored or logged. Websocket path: `/ws`; health check: `GET /healthz` answers `ok`.
4
+
5
+ ## Run your own relay
6
+
7
+ The relay can run on your own server, with no database to install: `ledge-relay launch` keeps everything in one data directory.
8
+
9
+ 1. **Requirements.** Node 22 or later, a domain name, and an HTTPS reverse proxy in front of the relay (the relay speaks plain HTTP and listens on `127.0.0.1` by default).
10
+ 2. **Install.**
11
+
12
+ ```sh
13
+ npm i -g @paradow/ledge-relay
14
+ ```
15
+
16
+ 3. **Launch.**
17
+
18
+ ```sh
19
+ ledge-relay launch
20
+ ```
21
+
22
+ The first time, it asks in the terminal and saves the answers in `config.json`:
23
+ - the public URL of the relay (`https`, no path), for example `https://relay.example.com`;
24
+ - the GitHub OAuth App values. It prints them for you: create the App in GitHub, Settings, Developer settings, OAuth Apps, with Homepage URL `<public URL>`, Authorization callback URL `<public URL>/auth/github/callback`, and "Enable Device Flow" ticked (no permission is needed). Then it asks for the App's client id and client secret;
25
+ - the GitHub login (or numeric id) allowed to use the relay; it shows the account it found and asks you to confirm it;
26
+ - a contact for Web Push (an email address, a `mailto:` address or an `https://` URL).
27
+
28
+ It generates the Web Push keys itself, then starts the relay. Ctrl-C during the questions saves nothing (`setup interrupted, nothing saved`). The next launches ask nothing. Without a terminal (a service), it never asks: it exits with `missing settings: ...` unless the settings are in `config.json` or in the environment variables below.
29
+ 4. **HTTPS proxy.** Any proxy works; with Caddy, which gets the certificate by itself:
30
+
31
+ ```
32
+ relay.example.com {
33
+ reverse_proxy 127.0.0.1:8787
34
+ }
35
+ ```
36
+
37
+ 5. **Keep it running with systemd.** Install Node system-wide for the service (your distribution's package, or NodeSource), not through nvm: `sudo` resets `PATH` (`secure_path`), and the service user cannot read another user's `~/.nvm`. Install `@paradow/ledge-relay` with that Node, create a dedicated user and its data directory, answer the questions once as that user, then install the service:
38
+
39
+ ```sh
40
+ sudo useradd --system --no-create-home ledge-relay
41
+ sudo install -d -m 0700 -o ledge-relay /var/lib/ledge-relay
42
+ sudo -u ledge-relay "$(command -v ledge-relay)" launch --data /var/lib/ledge-relay
43
+ ```
44
+
45
+ When Node lives in a directory every user can read but `sudo` does not search (for example `/opt/node/bin`), give it the path: `sudo -u ledge-relay env PATH=/opt/node/bin:/usr/bin:/bin ledge-relay launch --data /var/lib/ledge-relay`.
46
+
47
+ Stop that first run with Ctrl-C, then write `/etc/systemd/system/ledge-relay.service`. `ExecStart` takes the absolute path `command -v ledge-relay` printed (typically `/usr/bin/ledge-relay` or `/usr/local/bin/ledge-relay`):
48
+
49
+ ```ini
50
+ [Unit]
51
+ Description=Ledge relay
52
+ Wants=network-online.target
53
+ After=network-online.target
54
+
55
+ [Service]
56
+ ExecStart=/usr/local/bin/ledge-relay launch --data /var/lib/ledge-relay
57
+ StateDirectory=ledge-relay
58
+ StateDirectoryMode=0700
59
+ Restart=on-failure
60
+ RestartSec=5
61
+ User=ledge-relay
62
+
63
+ [Install]
64
+ WantedBy=multi-user.target
65
+ ```
66
+
67
+ Then `systemctl enable --now ledge-relay`. `StateDirectory=` makes systemd create `/var/lib/ledge-relay` for the user if it is missing, private with `StateDirectoryMode=0700`. `ledge-relay` starts through `/usr/bin/env node`: when Node is not in `/usr/bin` or `/usr/local/bin` (for example in `/opt/node/bin`), add an `Environment=PATH=/opt/node/bin:/usr/bin:/bin` line to `[Service]`. To answer the questions again (`--setup`), stop the service first.
68
+ 6. **In Ledge Desktop.** Settings, Mobile access (in French, Réglages › Accès mobile): enter the relay address (your public URL), then sign in with GitHub. On the phone, open the same address.
69
+
70
+ ### Data directory and options
71
+
72
+ The data directory is `--data <dir>`, else the `LEDGE_RELAY_HOME` environment variable, else `~/.ledge-relay`. It is created with mode `0700`, or tightened to it when it exists, and holds:
73
+
74
+ - `config.json` (mode `0600`): `publicUrl`, `githubClientId`, `githubClientSecret`, `allowedGithubIds`, `vapid`. It contains secrets: keep it private.
75
+ - `db/`: the embedded database (pglite) with accounts, sessions, linked phones and push subscriptions. Set `DATABASE_URL` to use Postgres instead.
76
+ - `ledge-relay.lock`: the process id of the `ledge-relay` using the directory. A second `ledge-relay` on the same directory exits with `another ledge-relay is using <dir>`, so the database is never opened twice; a lock left by a process that is gone is taken over.
77
+
78
+ The environment variables of the sections below override `config.json`.
79
+
80
+ | Option | Meaning |
81
+ | --- | --- |
82
+ | `--port <port>` | Port to listen on (default `8787`, or `PORT`). |
83
+ | `--host <host>` | Address to listen on (default `127.0.0.1`). |
84
+ | `--data <dir>` | The data directory. |
85
+ | `--setup` | Ask the questions again, with the saved answers as defaults (needs a terminal, and the relay stopped). |
86
+
87
+ `ledge-relay --version` prints the version. `launch` always applies the production rules: an `https` public URL, the phone app present, Web Push keys present. It always serves the phone app packed with it and ignores `LEDGE_RELAY_WEB_DIR`. If `config.json` is not valid, it exits naming the file and leaves it untouched; fix it or run `ledge-relay launch --setup`.
88
+
89
+ ### Letting someone else in
90
+
91
+ Edit `allowedGithubIds` in `config.json` (numeric GitHub ids, as strings), then restart the relay. A login's id is at `https://api.github.com/users/<login>` (field `id`). Removing an id and restarting cuts that account.
92
+
93
+ ### If the database cannot be opened after an upgrade
94
+
95
+ The relay exits with `cannot open the embedded database at <data>/db`, and never touches that directory itself. To start afresh, stop the relay and move `<data>/db` aside (rename it), then launch again. A fresh database loses the accounts, sessions, linked phones and push subscriptions: each phone must sign in and link again. `config.json` is kept.
96
+
97
+ ### Publishing (owner)
98
+
99
+ The relay is licensed under the PolyForm Noncommercial License 1.0.0 (`LICENSE`, with its required notice). Do these three steps, in this order, once a release containing the relay package exists, and before the release tag that follows the licence choice. Otherwise the `npm` job of that release fails at the relay publish (no Trusted Publisher yet) and blocks the production deploy.
100
+
101
+ 1. Choose the licence: set `license` in `apps/relay/package.json` (while it is `UNLICENSED`, the release publishes nothing and only runs `npm pack --dry-run`), and add the `LICENSE` file. Done: `PolyForm-Noncommercial-1.0.0`. Tag no release until step 3 is done.
102
+ 2. Publish once by hand the version of the last release, from a checkout of its tag (`vX.Y.Z`, where `X.Y.Z` is the `version` in `apps/relay/package.json` at that tag), on Linux or WSL, so that the packed `web/build.json` equals the release's `ledge-mobile-build.json`. Set the same `license` and `LICENSE` in that checkout, then build the phone app, the relay and its copy, check the package and publish:
103
+
104
+ ```sh
105
+ git checkout vX.Y.Z
106
+ pnpm install
107
+ pnpm --filter @ledge/mobile build
108
+ pnpm --filter @paradow/ledge-relay build
109
+ pnpm --filter @paradow/ledge-relay pack:web
110
+ cd apps/relay
111
+ npm pack --dry-run --json > /tmp/relay-pack.json && node ../../scripts/relay-pack.mjs check /tmp/relay-pack.json
112
+ npm publish --access public
113
+ ```
114
+
115
+ To compare with the release itself: `gh release download vX.Y.Z -p ledge-mobile-build.json`, then `diff ledge-mobile-build.json web/build.json`.
116
+
117
+ 3. On npmjs.com, in the package's settings, add a Trusted Publisher: this repository, workflow `release.yml`.
118
+
119
+ From then on, every release publishes the relay with its phone build (`.github/workflows/release.yml`).
120
+
121
+ ## Modes
122
+
123
+ `DATABASE_URL` selects the mode. Present: accounts mode. Absent: dev mode, which is refused when `NODE_ENV=production`.
124
+
125
+ ### Accounts mode
126
+
127
+ Accounts are GitHub users from an allow-list. The relay keeps accounts and sessions in Postgres (only the sha256 of a session token is stored) and creates its tables at startup.
128
+
129
+ | Variable | Meaning |
130
+ | --- | --- |
131
+ | `DATABASE_URL` | Postgres connection string. |
132
+ | `GITHUB_CLIENT_ID`, `GITHUB_CLIENT_SECRET` | The GitHub OAuth App. |
133
+ | `LEDGE_RELAY_ALLOWED_GITHUB_IDS` | Numeric GitHub ids, positive integers separated by commas, at least one. Checked at every authentication. |
134
+ | `LEDGE_RELAY_PUBLIC_URL` | The relay's public origin, `http(s)://host[:port]`, no path. https is required when `NODE_ENV=production`. A cookie session is accepted only from this `Origin`. |
135
+ | `LEDGE_RELAY_WEB_DIR` | Directory of the built phone app (`@ledge/mobile`), served as static files. Required in production, where it must hold `index.html`, `sw.js`, `build.json` and `manifest.webmanifest`. |
136
+ | `LEDGE_RELAY_VAPID_PUBLIC_KEY`, `LEDGE_RELAY_VAPID_PRIVATE_KEY`, `LEDGE_RELAY_VAPID_SUBJECT` | Web Push identity: an uncompressed P-256 point and a 32-byte scalar (base64url), and a `mailto:` or `https:` contact. Required in production; elsewhere all three or none. |
137
+ | `PORT` | Default `8787`. |
138
+ | `LEDGE_RELAY_GITHUB_WEB_URL`, `LEDGE_RELAY_GITHUB_API_URL` | Point GitHub calls at another server (tests). Refused in production. |
139
+
140
+ In production, every missing required variable is reported at once (`missing in production: ...`). A configuration error is printed on stderr, naming the variable and never its value, and the process exits with code 1.
141
+
142
+ ### Dev mode
143
+
144
+ ```sh
145
+ LEDGE_RELAY_DEV_TOKENS='{"tok-pc-0123456789abcdef":{"accountId":"me","peer":"pc"}}' pnpm --filter @paradow/ledge-relay dev
146
+ curl -s localhost:8787/healthz # ok
147
+ ```
148
+
149
+ - `PORT` (default `8787`).
150
+ - `LEDGE_RELAY_DEV_TOKENS`: JSON `{ "<token>": { "accountId": "...", "peer": "pc" | "d_<id>" } }`. The daemon presents the token as `Authorization: Bearer <token>`, a browser as the websocket subprotocol `ledge-relay.<token>`.
151
+
152
+ Static tokens: never deploy this mode.
153
+
154
+ ## Create the GitHub OAuth App
155
+
156
+ GitHub, Settings, Developer settings, OAuth Apps, New OAuth App:
157
+
158
+ - Authorization callback URL: `<LEDGE_RELAY_PUBLIC_URL>/auth/github/callback`.
159
+ - Tick "Enable Device Flow" (the PC signs in with it).
160
+ - No permission is needed: the relay asks for an empty scope and only reads the user's id and login.
161
+
162
+ Generate a client secret and set `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET`.
163
+
164
+ ## Run locally with Docker Postgres
165
+
166
+ ```sh
167
+ docker run --name ledge-pg -e POSTGRES_PASSWORD=ledge -p 5432:5432 -d postgres:16
168
+ pnpm --filter @paradow/ledge-relay build
169
+ DATABASE_URL=postgres://postgres:ledge@localhost:5432/postgres \
170
+ GITHUB_CLIENT_ID=<id> GITHUB_CLIENT_SECRET=<secret> \
171
+ LEDGE_RELAY_ALLOWED_GITHUB_IDS=<your numeric id> \
172
+ LEDGE_RELAY_PUBLIC_URL=http://localhost:8787 \
173
+ node apps/relay/dist/main.js
174
+ curl -s localhost:8787/healthz # ok
175
+ ```
176
+
177
+ For a local callback, register `http://localhost:8787/auth/github/callback` in the OAuth App.
178
+
179
+ ## Deploy on Railway
180
+
181
+ Production runbook: one Docker image (`apps/relay/Dockerfile`, build context = the repository root) holds the relay and the built phone app, served at `https://app.kl-ledge.dev`. Run exactly one replica: the socket routing hub lives in memory.
182
+
183
+ 1. **VAPID keys.** `pnpm --filter @paradow/ledge-relay vapid-keys <contact email>` prints three lines (from a checkout without `pnpm install`, `node apps/relay/scripts/vapid-keys.mjs <contact email>` works too: it only imports `node:crypto`). They go into Railway variables only, never into the repository.
184
+ 2. **GitHub OAuth App.** Homepage URL `https://app.kl-ledge.dev`, Authorization callback URL `https://app.kl-ledge.dev/auth/github/callback`, tick "Enable Device Flow", then generate a client secret.
185
+ 3. **Railway project.** Hobby plan, region `europe-west4`. Create the service from the repository root (not `apps/relay`) and set its config file to `apps/relay/railway.json` (Dockerfile build, one replica, `/healthz` check, restart on failure). Add a Postgres. Once step 6 has created the branch `production`, point the service at it, with auto-deploy.
186
+ 4. **Service variables.**
187
+
188
+ | Variable | Value |
189
+ | --- | --- |
190
+ | `DATABASE_URL` | `${{Postgres.DATABASE_URL}}` (Railway reference, private network). |
191
+ | `GITHUB_CLIENT_ID`, `GITHUB_CLIENT_SECRET` | From the OAuth App. |
192
+ | `LEDGE_RELAY_ALLOWED_GITHUB_IDS` | Numeric ids, comma-separated (`https://api.github.com/users/<login>`, field `id`). |
193
+ | `LEDGE_RELAY_PUBLIC_URL` | `https://app.kl-ledge.dev`, no trailing slash. |
194
+ | `LEDGE_RELAY_VAPID_PUBLIC_KEY` | 87 base64url characters. |
195
+ | `LEDGE_RELAY_VAPID_PRIVATE_KEY` | 43 base64url characters. |
196
+ | `LEDGE_RELAY_VAPID_SUBJECT` | `mailto:<contact>`. |
197
+
198
+ `NODE_ENV`, `LEDGE_RELAY_WEB_DIR` and `PORT` are not set: the image sets the first two, Railway provides `PORT`.
199
+ 5. **Domain.** In the service, Settings, Networking, Custom Domain: `app.kl-ledge.dev`. Create the DNS record Railway shows (CNAME `app` to the target it gives, plus a TXT verification record if asked) wherever the DNS of `kl-ledge.dev` is served: in Railway itself when the domain was bought through Railway; behind Cloudflare the record is "DNS only". Wait for the certificate.
200
+ 6. **Deploying a release.** Deploy only release commits, and only ones whose `packages/ledge/package.json` already carries the tag's version (the `chore: X.Y.Z` commit that precedes the tag). The service worker and `build.json` embed that version and the release workflow stamps it from the tag, so otherwise the served fingerprint differs from the release's. The first deploy is the first release tagged after lot 7 is merged: earlier tags have neither the Dockerfile nor a published `ledge-mobile-build.json`. Push that release commit to `production` first (this creates the branch), then select it in Railway (step 3). Advance the branch with:
201
+
202
+ ```sh
203
+ git push origin vX.Y.Z^{commit}:refs/heads/production
204
+ ```
205
+
206
+ The Release workflow does this itself (job `production`) once the daemon is on npm and the installer and `ledge-mobile-build.json` are on the release: fast-forward only, and only when the tagged commit carries the tag's version. It pushes with the repository secret `PRODUCTION_PUSH_TOKEN`: a fine-grained personal access token on this repository only, with Contents and Workflows read and write (the workflow's own token may not push a change under `.github/workflows`). By hand only for the first deploy or after that job failed.
207
+ 7. **After a deploy, check.**
208
+ - `https://app.kl-ledge.dev/healthz` answers `ok`.
209
+ - The logs show `{"ev":"listening",…,"mode":"accounts"}`.
210
+ - `https://app.kl-ledge.dev/build.json` is identical to the release asset `ledge-mobile-build.json`. Use curl, a browser may be answered by the service worker: `diff <(curl -s https://app.kl-ledge.dev/build.json) <(gh release download vX.Y.Z -p ledge-mobile-build.json -O -)` prints nothing when they match.
211
+ 8. **When it fails.** A missing or mistyped variable: the process exits 1 with one line naming the missing variables (never their values); the healthcheck fails and Railway keeps the previous deployment. A database not ready yet: exit 1 with `ledge-relay: cannot start: the database is unreachable…`, then Railway restarts it.
212
+
213
+ ## Allow-list
214
+
215
+ To let someone in, add their numeric GitHub id to `LEDGE_RELAY_ALLOWED_GITHUB_IDS`, then restart the service. Removing an id and restarting cuts that account: its sessions stay in the database but no longer authenticate. A login's id is at `https://api.github.com/users/<login>` (field `id`).
216
+
217
+ ## Auth routes
218
+
219
+ | Route | Use |
220
+ | --- | --- |
221
+ | `POST /auth/device/start` | PC: starts GitHub's device flow; answers the user code and verification URL. |
222
+ | `POST /auth/device/poll` | PC: body `{ "deviceCode": "..." }`; answers `pending`, `slow_down`, `expired`, `denied`, `not_allowed` or `ok` with the session token. A new PC sign-in revokes the account's earlier PC sessions. |
223
+ | `GET /auth/github/start` | Phone: redirects to GitHub, with a `state` cookie. |
224
+ | `GET /auth/github/callback` | Phone: GitHub's return; sets the `HttpOnly` session cookie and redirects to `/?signin=<issue>`. |
225
+ | `GET /auth/me` | The current session: account id, login, peer and kind. |
226
+ | `POST /auth/logout` | Ends the current session. |
227
+
228
+ ## Websocket close codes
229
+
230
+ | Code | Meaning |
231
+ | --- | --- |
232
+ | 4000 | Replaced: a newer connection of the same account and peer took over. |
233
+ | 4001 | Signed out: the session was revoked (logout, or a new PC sign-in). |
234
+ | 4008 | Limit: a rate or size limit was exceeded. |