@connextar/house 0.21.2 → 0.22.2

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 (39) hide show
  1. package/README.md +91 -0
  2. package/dist/maintenance/core.d.ts +109 -0
  3. package/dist/maintenance/core.d.ts.map +1 -0
  4. package/dist/maintenance/core.js +189 -0
  5. package/dist/maintenance/core.js.map +1 -0
  6. package/dist/maintenance/gate.d.ts +48 -0
  7. package/dist/maintenance/gate.d.ts.map +1 -0
  8. package/dist/maintenance/gate.js +114 -0
  9. package/dist/maintenance/gate.js.map +1 -0
  10. package/dist/maintenance/index.d.ts +7 -0
  11. package/dist/maintenance/index.d.ts.map +1 -0
  12. package/dist/maintenance/index.js +7 -0
  13. package/dist/maintenance/index.js.map +1 -0
  14. package/dist/maintenance/page.d.ts +21 -0
  15. package/dist/maintenance/page.d.ts.map +1 -0
  16. package/dist/maintenance/page.js +53 -0
  17. package/dist/maintenance/page.js.map +1 -0
  18. package/dist/maintenance/proxy.d.ts +41 -0
  19. package/dist/maintenance/proxy.d.ts.map +1 -0
  20. package/dist/maintenance/proxy.js +33 -0
  21. package/dist/maintenance/proxy.js.map +1 -0
  22. package/dist/maintenance/react-index.d.ts +2 -0
  23. package/dist/maintenance/react-index.d.ts.map +1 -0
  24. package/dist/maintenance/react-index.js +2 -0
  25. package/dist/maintenance/react-index.js.map +1 -0
  26. package/dist/maintenance/react.d.ts +36 -0
  27. package/dist/maintenance/react.d.ts.map +1 -0
  28. package/dist/maintenance/react.js +141 -0
  29. package/dist/maintenance/react.js.map +1 -0
  30. package/dist/maintenance/route.d.ts +37 -0
  31. package/dist/maintenance/route.d.ts.map +1 -0
  32. package/dist/maintenance/route.js +41 -0
  33. package/dist/maintenance/route.js.map +1 -0
  34. package/dist/maintenance/unavailable.d.ts +11 -0
  35. package/dist/maintenance/unavailable.d.ts.map +1 -0
  36. package/dist/maintenance/unavailable.js +63 -0
  37. package/dist/maintenance/unavailable.js.map +1 -0
  38. package/docs/Maintenance.md +121 -0
  39. package/package.json +21 -13
@@ -0,0 +1,121 @@
1
+ # Planned maintenance
2
+
3
+ > How a house app tells its users that the database server it depends on is about to go down, shows a maintenance page while it is down, and comes back by itself as soon as it is up again — with no database errors in front of anyone. Shared by the cohort as `@connextar/house/maintenance`; the server side lives in CX_PGSQL_Node_1.
4
+
5
+ _Written 2026-11-04. Status: step 1 (the server's feed) is live since 2026-11-04 15:09 UTC; step 2 (the house module) is built in 0.22.0; AltEd follows._
6
+
7
+ ---
8
+
9
+ ## 1. What people see
10
+
11
+ | When | What |
12
+ | -------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
13
+ | From the moment a window is booked until it starts | A **planned maintenance** notice at the top of every page: the window in UK time ("Wed 4 Nov, 23:00–23:15 GMT"), and a countdown in the last hour. Dismissible; a moved window brings it back. |
14
+ | From one minute before the start until it is over | A **maintenance** page in place of every page: what is happening, when it should be back by, and that it reloads by itself. APIs answer `503` with JSON; crons are skipped. |
15
+ | As soon as the server says it is done | Everything back, within about 15 seconds — usually long before the window's end. |
16
+ | An outage nobody planned | The app's error page asks the app whether the database is reachable and says "temporarily unavailable, try again shortly" instead of a generic error. |
17
+
18
+ ---
19
+
20
+ ## 2. The feed (the contract between a server and the apps)
21
+
22
+ Each database server publishes one public document. The apps **pull** it; nothing is pushed.
23
+
24
+ ```
25
+ GET https://pgsql-node-1.connextar.com/maintenance.json
26
+ ```
27
+
28
+ ```json
29
+ {
30
+ "version": 1,
31
+ "server": "cx-pgsql-node-1",
32
+ "generated_at": "2026-11-04T18:00:00Z",
33
+ "windows": [
34
+ {
35
+ "id": "reboot-20261104T2300Z",
36
+ "kind": "reboot",
37
+ "state": "planned",
38
+ "starts_at": "2026-11-04T23:00:00Z",
39
+ "ends_by": "2026-11-04T23:15:00Z",
40
+ "expected_minutes": 2,
41
+ "ended_at": null,
42
+ "affects": ["postgres", "objects"],
43
+ "message": null
44
+ }
45
+ ]
46
+ }
47
+ ```
48
+
49
+ | Field | Meaning |
50
+ | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
51
+ | `id` | Stable for one booking. A moved booking gets a new id, so a dismissed notice comes back. |
52
+ | `kind` | `reboot` (booked by the server itself, from an update) or `maintenance` (booked by hand). |
53
+ | `state` | `planned` · `active` · `ended` · `cancelled`, computed from the times when the document is served. An app recomputes it from the times when it can't reach the server. |
54
+ | `starts_at` | When the service goes down. Apps start their maintenance page one minute earlier, so requests in flight finish before Postgres cuts them off. |
55
+ | `ends_by` | The latest it should be over: at least 15 minutes, or three times the expected downtime. After it, an app stops gating even without word from the server. |
56
+ | `expected_minutes` | The honest estimate (for a reboot: the last reboot's measured gap plus a minute for Postgres) — what the notice says. |
57
+ | `ended_at` | Set when the work actually finished. An app seeing it stops gating at once: this is how an early finish reaches everyone. |
58
+ | `affects` | `postgres`, `objects` — what will be unavailable. |
59
+ | `message` | Optional public text written by whoever booked the window. Nothing else in the document says why: no package names, no internals. |
60
+
61
+ Windows that ended or were cancelled more than a day ago drop out of the document. An unknown `version` or field is ignored, not an error.
62
+
63
+ ### Why pull, not push
64
+
65
+ - **The apps have nowhere to keep a pushed message.** An app's durable store is the database that is about to go down; Vercel functions keep nothing between invocations.
66
+ - **A server would need a register of apps**, a secret for each, and retries for each. A public document needs nothing: an app opts in by setting one URL.
67
+ - **The hard case is solved by the times themselves.** During a reboot nothing on the server answers, including the feed. Every app already holds the window from the hours of notice before it, so the maintenance page turns on by the clock.
68
+
69
+ ### How a window starts and ends on the server
70
+
71
+ - **A reboot** booked by unattended-upgrades (`AUTO_REBOOT`, 23:00 UTC) or by `shutdown -r <time>` is noticed the moment it is booked (a path unit on `/run/systemd/shutdown`) and written as a window. Moving it with another `shutdown -r` replaces the window; `shutdown -c` marks it cancelled.
72
+ - **After the reboot,** a job at boot waits until Postgres, PgBouncer and the object store are healthy (up to ten minutes) and sets `ended_at`.
73
+ - **Work booked by hand:**
74
+
75
+ ```bash
76
+ cx-pgsql maintenance plan "2026-11-10 02:00" 30m "Upgrading the database"
77
+ cx-pgsql maintenance start 20m # now
78
+ cx-pgsql maintenance extend 15m # running over: push ends_by out
79
+ cx-pgsql maintenance end # finished early, or on time
80
+ cx-pgsql maintenance cancel
81
+ cx-pgsql maintenance status
82
+ ```
83
+
84
+ From a laptop, the same through `bin/remote.sh cx maintenance …`. Booking, moving and cancelling email the planned-downtime notice, as a booked reboot does.
85
+
86
+ ---
87
+
88
+ ## 3. `@connextar/house/maintenance` (built in 0.22.0)
89
+
90
+ Two entry points. The README has the API and the adoption steps.
91
+
92
+ | Part | What it does |
93
+ | -------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
94
+ | **core** (no I/O) | `parseMaintenanceFeed` keeps only the contract's fields and drops bad windows one by one. `maintenanceState(windows, now)` → `{ phase: "none" \| "upcoming" \| "active", window, retryAfterSeconds }`, from the times alone. The rules in §2, tested with an injected clock. |
95
+ | **gate** | `createMaintenanceGate` / `maintenanceGateFromEnv`: re-reads every 60 s — every 15 s within ten minutes of a window and during one — with a one-second timeout, and keeps its copy when the server doesn't answer. `HOUSE_MAINTENANCE=on \| off \| auto` overrides it (on Vercel, a change needs a redeploy). |
96
+ | **proxy helper** | `maintenanceResponse` for the app's `proxy.ts`. During a window pages get the **maintenance page** itself with `503`, `Retry-After` and `no-store`; APIs get a JSON `503`; crons get `200 { skipped: "maintenance" }`. The state route, `/_next/`, static files and each app's `keepUp` paths pass. |
97
+ | **the maintenance page** | `maintenancePageHtml`: a whole HTML document returned by the proxy, not an app route. While the database is down an app's own layouts can't be trusted to render, and an App Router page can't answer `503`. No script (it reloads with a meta refresh every 30 s, so no CSP exception), no stylesheet, no font; light and dark. When the window ends, the next reload is the real page. |
98
+ | **state route** | `createMaintenanceRoute`: `/api/house/maintenance`, the gate's state as JSON, without touching the database. With `?probe=1`, also the app's `SELECT 1` (1.5 s timeout, one probe per 5 s whoever asks). |
99
+ | `<MaintenanceBanner>` (`/maintenance/react`) | Drawn in the browser from the state route, so pages built ahead of time show it without a rebuild. Dismissal remembered per window id; not dismissible once under way. |
100
+ | `useServiceCheck()` (`/maintenance/react`) | For `error.tsx`. In production the App Router hands an error page only a digest, never the message, so it can't tell a connection error from any other: it asks the state route's probe instead. |
101
+ | `isUnavailableError` | For an API route's catch: an unreachable database or file store is a `503`, not a `500`. |
102
+
103
+ ---
104
+
105
+ ## 4. Things that would still show database errors, and the answer to each
106
+
107
+ 1. **Requests in flight at the start.** Postgres terminates their connections ("terminating connection due to administrator command"). The gate starts one minute early.
108
+ 2. **A fresh instance started mid-reboot, with no copy of the feed.** It can't know about the window, so it falls through to the error page's unavailable check, which also covers unplanned outages. Mirroring the feed off the server (Vercel Edge Config) would close this completely but puts a Vercel API token on the database server; kept as a later upgrade.
109
+ 3. **No connect timeout.** pg's default is to wait for ever; against a host that drops packets a request hangs until the platform kills it. Each app sets a connect timeout of about five seconds.
110
+ 4. **Webhooks.** A gateway answers `503` during a window, so the sender (Stripe) retries later instead of the event being half-handled.
111
+ 5. **Service workers.** An offline-capable app shows the `503` maintenance page as it is — never caches it, never swaps it for the offline page.
112
+ 6. **Search engines and AI crawlers.** `503` with `Retry-After` keeps the maintenance page out of every index.
113
+
114
+ ---
115
+
116
+ ## 5. Order of work
117
+
118
+ 1. **Server (CX_PGSQL_Node_1):** the window file, the feed route, the boot-time completion job, the `maintenance` commands, the notice for windows booked by hand. The owner runs `apply`.
119
+ 2. **cx-house:** the module in §3, with tests. Publishing needs the owner's npm 2FA.
120
+ 3. **AltEd first:** a `proxy.ts` (it has none yet), the banner in the root layout, `/maintenance`, the `error.tsx` check, the connect timeout, the service-worker rule. Then a release.
121
+ 4. **Every other app whose database or files are on the server:** the feed URL and the same few files.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@connextar/house",
3
- "version": "0.21.2",
3
+ "version": "0.22.2",
4
4
  "description": "The pieces every app we build needs and none of them should own a copy of.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -146,6 +146,14 @@
146
146
  "types": "./dist/password/estimate-index.d.ts",
147
147
  "default": "./dist/password/estimate-index.js"
148
148
  },
149
+ "./maintenance": {
150
+ "types": "./dist/maintenance/index.d.ts",
151
+ "default": "./dist/maintenance/index.js"
152
+ },
153
+ "./maintenance/react": {
154
+ "types": "./dist/maintenance/react-index.d.ts",
155
+ "default": "./dist/maintenance/react-index.js"
156
+ },
149
157
  "./house.css": {
150
158
  "style": "./dist/house.css",
151
159
  "default": "./dist/house.css"
@@ -229,18 +237,18 @@
229
237
  "@radix-ui/react-dialog": "^1.3.1",
230
238
  "@radix-ui/react-dropdown-menu": "^2.1.24",
231
239
  "@radix-ui/react-popover": "^1.1.23",
232
- "@tiptap/core": "^3.31.3",
233
- "@tiptap/extension-drag-handle": "^3.31.3",
234
- "@tiptap/extension-drag-handle-react": "^3.31.3",
235
- "@tiptap/extension-image": "^3.31.3",
236
- "@tiptap/extension-node-range": "^3.31.3",
237
- "@tiptap/extension-task-item": "^3.31.3",
238
- "@tiptap/extension-task-list": "^3.31.3",
239
- "@tiptap/extensions": "^3.31.3",
240
- "@tiptap/pm": "^3.31.3",
241
- "@tiptap/react": "^3.31.3",
242
- "@tiptap/starter-kit": "^3.31.3",
243
- "@tiptap/suggestion": "^3.31.3",
240
+ "@tiptap/core": "3.31.3",
241
+ "@tiptap/extension-drag-handle": "3.31.3",
242
+ "@tiptap/extension-drag-handle-react": "3.31.3",
243
+ "@tiptap/extension-image": "3.31.3",
244
+ "@tiptap/extension-node-range": "3.31.3",
245
+ "@tiptap/extension-task-item": "3.31.3",
246
+ "@tiptap/extension-task-list": "3.31.3",
247
+ "@tiptap/extensions": "3.31.3",
248
+ "@tiptap/pm": "3.31.3",
249
+ "@tiptap/react": "3.31.3",
250
+ "@tiptap/starter-kit": "3.31.3",
251
+ "@tiptap/suggestion": "3.31.3",
244
252
  "lucide-react": "^0.561.0",
245
253
  "tiptap-markdown": "^0.9.0"
246
254
  }