@connextar/house 0.21.2 → 0.22.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.
- package/README.md +91 -0
- package/dist/maintenance/core.d.ts +102 -0
- package/dist/maintenance/core.d.ts.map +1 -0
- package/dist/maintenance/core.js +164 -0
- package/dist/maintenance/core.js.map +1 -0
- package/dist/maintenance/gate.d.ts +48 -0
- package/dist/maintenance/gate.d.ts.map +1 -0
- package/dist/maintenance/gate.js +114 -0
- package/dist/maintenance/gate.js.map +1 -0
- package/dist/maintenance/index.d.ts +7 -0
- package/dist/maintenance/index.d.ts.map +1 -0
- package/dist/maintenance/index.js +7 -0
- package/dist/maintenance/index.js.map +1 -0
- package/dist/maintenance/page.d.ts +21 -0
- package/dist/maintenance/page.d.ts.map +1 -0
- package/dist/maintenance/page.js +53 -0
- package/dist/maintenance/page.js.map +1 -0
- package/dist/maintenance/proxy.d.ts +41 -0
- package/dist/maintenance/proxy.d.ts.map +1 -0
- package/dist/maintenance/proxy.js +33 -0
- package/dist/maintenance/proxy.js.map +1 -0
- package/dist/maintenance/react-index.d.ts +2 -0
- package/dist/maintenance/react-index.d.ts.map +1 -0
- package/dist/maintenance/react-index.js +2 -0
- package/dist/maintenance/react-index.js.map +1 -0
- package/dist/maintenance/react.d.ts +36 -0
- package/dist/maintenance/react.d.ts.map +1 -0
- package/dist/maintenance/react.js +141 -0
- package/dist/maintenance/react.js.map +1 -0
- package/dist/maintenance/route.d.ts +37 -0
- package/dist/maintenance/route.d.ts.map +1 -0
- package/dist/maintenance/route.js +41 -0
- package/dist/maintenance/route.js.map +1 -0
- package/dist/maintenance/unavailable.d.ts +11 -0
- package/dist/maintenance/unavailable.d.ts.map +1 -0
- package/dist/maintenance/unavailable.js +63 -0
- package/dist/maintenance/unavailable.js.map +1 -0
- package/docs/Maintenance.md +121 -0
- package/package.json +9 -1
package/README.md
CHANGED
|
@@ -1591,6 +1591,97 @@ export async function GET() {
|
|
|
1591
1591
|
}
|
|
1592
1592
|
```
|
|
1593
1593
|
|
|
1594
|
+
### `@connextar/house/maintenance`, `/maintenance/react`
|
|
1595
|
+
|
|
1596
|
+
Planned maintenance on the database server an app depends on, shown to people
|
|
1597
|
+
instead of database errors: a dismissible **planned maintenance** notice while a
|
|
1598
|
+
window is coming, a **maintenance page** while it's under way, and everything back
|
|
1599
|
+
by itself — usually within 15 seconds of the server saying it's done, long before
|
|
1600
|
+
the window's end. The design, the feed's contract and the order of work are in
|
|
1601
|
+
[docs/Maintenance.md](docs/Maintenance.md).
|
|
1602
|
+
|
|
1603
|
+
Each server publishes `GET /maintenance.json` (CX_PGSQL_Node_1:
|
|
1604
|
+
`https://pgsql-node-1.connextar.com/maintenance.json`); the app reads it. The
|
|
1605
|
+
server's reboots announce themselves; anything else is booked with
|
|
1606
|
+
`cx-pgsql maintenance plan|start|extend|end|cancel`.
|
|
1607
|
+
|
|
1608
|
+
**Server half** (`@connextar/house/maintenance`, no package imported — it runs in
|
|
1609
|
+
`proxy.ts` before every request):
|
|
1610
|
+
|
|
1611
|
+
- `maintenanceGateFromEnv(env?, options?)` → a gate, from `HOUSE_MAINTENANCE_FEEDS`
|
|
1612
|
+
(feed URLs, commas or spaces) and `HOUSE_MAINTENANCE` (`on` forces the page,
|
|
1613
|
+
`off` never shows it, `auto` or unset follows the feeds). `createMaintenanceGate({
|
|
1614
|
+
feeds, override, timing, timeoutMs, … })` is the same with everything said.
|
|
1615
|
+
Keep one per process (module scope). It re-reads a feed when its copy is a minute
|
|
1616
|
+
old — 15 seconds near or during a window — with a one-second timeout, and **keeps
|
|
1617
|
+
its copy when the server doesn't answer**: during a reboot nothing does, and the
|
|
1618
|
+
copy is what turns the page on at the start. It never throws; `onError(feed,
|
|
1619
|
+
error)` hears about failures.
|
|
1620
|
+
- `maintenanceResponse(request, gate, { page: { appName }, keepUp?, statePath?,
|
|
1621
|
+
cronPrefix?, apiPrefix? })` → the response to send during a window, or
|
|
1622
|
+
`undefined` to carry on. Pages get the maintenance page itself
|
|
1623
|
+
(`maintenancePageHtml`: a whole document, no script, no stylesheet, no app
|
|
1624
|
+
layout, so it renders with the database down; it reloads itself every 30
|
|
1625
|
+
seconds) with `503` and `Retry-After`; `/api/` gets `503` JSON; `/api/cron/` gets
|
|
1626
|
+
`200 { skipped: "maintenance" }`; the state route, `/_next/`, static files and
|
|
1627
|
+
`keepUp` prefixes pass. The gate starts a minute before the window
|
|
1628
|
+
(`timing.leadSeconds`), so requests in flight finish before Postgres cuts them off.
|
|
1629
|
+
- `createMaintenanceRoute(gate, { probe })` → `{ GET }` for
|
|
1630
|
+
`app/api/house/maintenance/route.ts`: the state as JSON for the browser. With
|
|
1631
|
+
`?probe=1` it also runs the app's probe (a `SELECT 1`; 1.5 s timeout, one probe
|
|
1632
|
+
per 5 s whoever asks) and says `service: "up" | "down"`.
|
|
1633
|
+
- `isUnavailableError(error)` — a connection refused, a pool timeout, Postgres
|
|
1634
|
+
shutting down (Prisma P1001/P1002/P1017/P2024, SQLSTATE 57P0x/08xxx/53300,
|
|
1635
|
+
socket errnos), followed through `cause`, Prisma's `meta.driverAdapterError` and
|
|
1636
|
+
`AggregateError`. For an API route's catch: a 503, not a 500.
|
|
1637
|
+
- `maintenanceState(windows, now, timing)`, `parseMaintenanceFeed(json)`,
|
|
1638
|
+
`describeWindow(window, { timeZone })` ("Wed 4 Nov, 23:00–23:15 GMT") — the pure
|
|
1639
|
+
rules underneath.
|
|
1640
|
+
|
|
1641
|
+
**Browser half** (`@connextar/house/maintenance/react`, client components):
|
|
1642
|
+
|
|
1643
|
+
- `<MaintenanceBanner appName="AltEd" />` — at the top of the root layout. Drawn
|
|
1644
|
+
after load from the state route, so a page built ahead of time shows it without
|
|
1645
|
+
a rebuild. Dismissal is remembered per window (a moved window shows again);
|
|
1646
|
+
under way it says until when and can't be dismissed. Tailwind token classes, as
|
|
1647
|
+
every house component.
|
|
1648
|
+
- `useServiceCheck()` → `"checking" | "up" | "down" | "maintenance" | "unknown"`,
|
|
1649
|
+
for `error.tsx`. In production an error page gets a digest, never the message,
|
|
1650
|
+
so it asks the state route to probe instead: `maintenance` and `down` deserve
|
|
1651
|
+
"temporarily unavailable, try again shortly".
|
|
1652
|
+
|
|
1653
|
+
Adoption, per app:
|
|
1654
|
+
|
|
1655
|
+
```ts
|
|
1656
|
+
// lib/maintenance.ts
|
|
1657
|
+
import { maintenanceGateFromEnv } from "@connextar/house/maintenance";
|
|
1658
|
+
export const maintenanceGate = maintenanceGateFromEnv(process.env, {
|
|
1659
|
+
onError: (feed, error) => console.warn("maintenance feed", feed, error),
|
|
1660
|
+
});
|
|
1661
|
+
|
|
1662
|
+
// proxy.ts (Next 16)
|
|
1663
|
+
import type { NextRequest } from "next/server";
|
|
1664
|
+
import { maintenanceResponse } from "@connextar/house/maintenance";
|
|
1665
|
+
import { maintenanceGate } from "./lib/maintenance";
|
|
1666
|
+
export async function proxy(request: NextRequest) {
|
|
1667
|
+
return maintenanceResponse(request, maintenanceGate, { page: { appName: "AltEd" }, keepUp: ["/blog"] });
|
|
1668
|
+
}
|
|
1669
|
+
export const config = { matcher: ["/((?!_next/static|_next/image|favicon.ico|healthz).*)"] };
|
|
1670
|
+
|
|
1671
|
+
// app/api/house/maintenance/route.ts
|
|
1672
|
+
import { createMaintenanceRoute } from "@connextar/house/maintenance";
|
|
1673
|
+
import { maintenanceGate } from "@/lib/maintenance";
|
|
1674
|
+
import { prisma } from "@/lib/db/prisma";
|
|
1675
|
+
export const { GET } = createMaintenanceRoute(maintenanceGate, { probe: () => prisma.$queryRaw`select 1` });
|
|
1676
|
+
```
|
|
1677
|
+
|
|
1678
|
+
Then `HOUSE_MAINTENANCE_FEEDS=https://pgsql-node-1.connextar.com/maintenance.json`
|
|
1679
|
+
in the deployment's environment, the banner in the root layout, `useServiceCheck`
|
|
1680
|
+
in `error.tsx`, and a connect timeout on the database pool (pg waits for ever by
|
|
1681
|
+
default: `connectionTimeoutMillis: 5000`). An offline-capable app's service worker
|
|
1682
|
+
must show a `503` page as it is — never cache it, never swap it for the offline
|
|
1683
|
+
page.
|
|
1684
|
+
|
|
1594
1685
|
### `@connextar/house/trail`
|
|
1595
1686
|
|
|
1596
1687
|
Where you came from, rather than where the URL says you are. A breadcrumb built
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Planned maintenance: what a database server says about its downtime, and what
|
|
3
|
+
* an app should do about it now.
|
|
4
|
+
*
|
|
5
|
+
* Each server publishes `GET /maintenance.json` (the contract is in
|
|
6
|
+
* docs/Maintenance.md §2). This module reads that document and decides, from
|
|
7
|
+
* the window times alone, whether the app is in a window, has one coming, or
|
|
8
|
+
* neither. It decides from the times — not from the `state` the server worked
|
|
9
|
+
* out when it served the document — because an app keeps its last copy and must
|
|
10
|
+
* reach the right answer at 23:00 when the server it would ask is the thing
|
|
11
|
+
* that's down.
|
|
12
|
+
*
|
|
13
|
+
* Pure: no I/O, no clock of its own, no framework.
|
|
14
|
+
*/
|
|
15
|
+
/** The feed version this module understands. A different one is ignored, never guessed at. */
|
|
16
|
+
export declare const MAINTENANCE_FEED_VERSION = 1;
|
|
17
|
+
export type MaintenanceWindowKind = "reboot" | "maintenance";
|
|
18
|
+
/** One window, as an app holds it. Times are ISO strings in UTC. */
|
|
19
|
+
export interface MaintenanceWindow {
|
|
20
|
+
id: string;
|
|
21
|
+
/** `reboot`: booked by the server itself (an update). `maintenance`: booked by hand. */
|
|
22
|
+
kind: MaintenanceWindowKind;
|
|
23
|
+
startsAt: string;
|
|
24
|
+
/** The latest it should be over. After it, the app serves again whatever the server says. */
|
|
25
|
+
endsBy: string;
|
|
26
|
+
/** The honest estimate of the downtime, which is what people are told. */
|
|
27
|
+
expectedMinutes: number;
|
|
28
|
+
/** Set when the work finished — usually well before `endsBy`. */
|
|
29
|
+
endedAt: string | null;
|
|
30
|
+
cancelled: boolean;
|
|
31
|
+
/** What is unavailable meanwhile: `postgres`, `objects`. */
|
|
32
|
+
affects: string[];
|
|
33
|
+
/** Public text from whoever booked it. */
|
|
34
|
+
message: string | null;
|
|
35
|
+
/** The server that published it. */
|
|
36
|
+
server: string;
|
|
37
|
+
}
|
|
38
|
+
export interface MaintenanceFeed {
|
|
39
|
+
server: string;
|
|
40
|
+
generatedAt: string | null;
|
|
41
|
+
windows: MaintenanceWindow[];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The feed, or null when it isn't one this module understands. Malformed
|
|
45
|
+
* windows are dropped one by one rather than failing the whole document, and
|
|
46
|
+
* nothing beyond the contract's fields is kept.
|
|
47
|
+
*/
|
|
48
|
+
export declare function parseMaintenanceFeed(input: unknown): MaintenanceFeed | null;
|
|
49
|
+
export type MaintenancePhase = "none" | "upcoming" | "active";
|
|
50
|
+
export interface MaintenanceState {
|
|
51
|
+
phase: MaintenancePhase;
|
|
52
|
+
/** The window the phase is about: the active one, or the next one coming. */
|
|
53
|
+
window: MaintenanceWindow | null;
|
|
54
|
+
/** While active: seconds until the window's `endsBy`, for a `Retry-After` header. */
|
|
55
|
+
retryAfterSeconds: number | null;
|
|
56
|
+
}
|
|
57
|
+
export interface MaintenanceTiming {
|
|
58
|
+
/**
|
|
59
|
+
* How long before the start an app stops serving: requests in flight finish
|
|
60
|
+
* before Postgres terminates their connections. Default 60 seconds.
|
|
61
|
+
*/
|
|
62
|
+
leadSeconds?: number;
|
|
63
|
+
/** How far ahead a window is announced. Default 7 days. */
|
|
64
|
+
announceHours?: number;
|
|
65
|
+
}
|
|
66
|
+
export declare const NO_MAINTENANCE: MaintenanceState;
|
|
67
|
+
/**
|
|
68
|
+
* The phase now, from the windows' times:
|
|
69
|
+
*
|
|
70
|
+
* - **active** from `leadSeconds` before a window starts until it ended
|
|
71
|
+
* (`endedAt`) or ran out (`endsBy`), unless it was cancelled;
|
|
72
|
+
* - **upcoming** when a window starts within `announceHours`;
|
|
73
|
+
* - **none** otherwise.
|
|
74
|
+
*
|
|
75
|
+
* Of several active windows the one ending last wins; of several coming, the
|
|
76
|
+
* soonest.
|
|
77
|
+
*/
|
|
78
|
+
export declare function maintenanceState(windows: readonly MaintenanceWindow[], now: Date, timing?: MaintenanceTiming): MaintenanceState;
|
|
79
|
+
/** A window standing in for `HOUSE_MAINTENANCE=on`: from now, for an hour, renewed on every read. */
|
|
80
|
+
export declare function overrideWindow(now: Date): MaintenanceWindow;
|
|
81
|
+
export interface WindowWording {
|
|
82
|
+
timeZone?: string;
|
|
83
|
+
locale?: string;
|
|
84
|
+
}
|
|
85
|
+
export interface DescribedWindow {
|
|
86
|
+
/** "Wed 4 Nov" */
|
|
87
|
+
day: string;
|
|
88
|
+
/** "23:00" */
|
|
89
|
+
start: string;
|
|
90
|
+
/** "23:15" */
|
|
91
|
+
end: string;
|
|
92
|
+
/** "GMT" or "BST" */
|
|
93
|
+
zone: string;
|
|
94
|
+
/** "Wed 4 Nov, 23:00–23:15 GMT", or both days when it crosses midnight. */
|
|
95
|
+
text: string;
|
|
96
|
+
/** "a few minutes", "about 30 minutes", "about 2 hours" */
|
|
97
|
+
expected: string;
|
|
98
|
+
}
|
|
99
|
+
/** A window in words, in the app's time zone (Europe/London unless said otherwise). */
|
|
100
|
+
export declare function describeWindow(window: MaintenanceWindow, { timeZone, locale }?: WindowWording): DescribedWindow;
|
|
101
|
+
export declare function expectedText(minutes: number): string;
|
|
102
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/maintenance/core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,8FAA8F;AAC9F,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAE1C,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,aAAa,CAAC;AAE7D,oEAAoE;AACpE,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,wFAAwF;IACxF,IAAI,EAAE,qBAAqB,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;I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,CAa3D;AAID,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAmBD,MAAM,WAAW,eAAe;IAC9B,kBAAkB;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,cAAc;IACd,KAAK,EAAE,MAAM,CAAC;IACd,cAAc;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,2EAA2E;IAC3E,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,uFAAuF;AACvF,wBAAgB,cAAc,CAC5B,MAAM,EAAE,iBAAiB,EACzB,EAAE,QAA0B,EAAE,MAAgB,EAAE,GAAE,aAAkB,GACnE,eAAe,CAUjB;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAMpD"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Planned maintenance: what a database server says about its downtime, and what
|
|
3
|
+
* an app should do about it now.
|
|
4
|
+
*
|
|
5
|
+
* Each server publishes `GET /maintenance.json` (the contract is in
|
|
6
|
+
* docs/Maintenance.md §2). This module reads that document and decides, from
|
|
7
|
+
* the window times alone, whether the app is in a window, has one coming, or
|
|
8
|
+
* neither. It decides from the times — not from the `state` the server worked
|
|
9
|
+
* out when it served the document — because an app keeps its last copy and must
|
|
10
|
+
* reach the right answer at 23:00 when the server it would ask is the thing
|
|
11
|
+
* that's down.
|
|
12
|
+
*
|
|
13
|
+
* Pure: no I/O, no clock of its own, no framework.
|
|
14
|
+
*/
|
|
15
|
+
/** The feed version this module understands. A different one is ignored, never guessed at. */
|
|
16
|
+
export const MAINTENANCE_FEED_VERSION = 1;
|
|
17
|
+
const KINDS = new Set(["reboot", "maintenance"]);
|
|
18
|
+
const MESSAGE_MAX = 280;
|
|
19
|
+
function isRecord(value) {
|
|
20
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21
|
+
}
|
|
22
|
+
function time(value) {
|
|
23
|
+
if (typeof value !== "string" || value === "")
|
|
24
|
+
return null;
|
|
25
|
+
const ms = Date.parse(value);
|
|
26
|
+
return Number.isNaN(ms) ? null : ms;
|
|
27
|
+
}
|
|
28
|
+
function iso(ms) {
|
|
29
|
+
return new Date(ms).toISOString();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The feed, or null when it isn't one this module understands. Malformed
|
|
33
|
+
* windows are dropped one by one rather than failing the whole document, and
|
|
34
|
+
* nothing beyond the contract's fields is kept.
|
|
35
|
+
*/
|
|
36
|
+
export function parseMaintenanceFeed(input) {
|
|
37
|
+
if (!isRecord(input) || input.version !== MAINTENANCE_FEED_VERSION || !Array.isArray(input.windows))
|
|
38
|
+
return null;
|
|
39
|
+
const server = typeof input.server === "string" && input.server ? input.server.slice(0, 100) : "server";
|
|
40
|
+
const windows = [];
|
|
41
|
+
for (const raw of input.windows) {
|
|
42
|
+
if (!isRecord(raw) || typeof raw.id !== "string" || !raw.id)
|
|
43
|
+
continue;
|
|
44
|
+
const startsAt = time(raw.starts_at);
|
|
45
|
+
const endsBy = time(raw.ends_by);
|
|
46
|
+
if (startsAt === null || endsBy === null || endsBy <= startsAt)
|
|
47
|
+
continue;
|
|
48
|
+
const endedAt = time(raw.ended_at);
|
|
49
|
+
const expected = typeof raw.expected_minutes === "number" && raw.expected_minutes > 0 ? raw.expected_minutes : null;
|
|
50
|
+
windows.push({
|
|
51
|
+
id: raw.id.slice(0, 100),
|
|
52
|
+
kind: KINDS.has(raw.kind) ? raw.kind : "maintenance",
|
|
53
|
+
startsAt: iso(startsAt),
|
|
54
|
+
endsBy: iso(endsBy),
|
|
55
|
+
expectedMinutes: Math.ceil(expected ?? (endsBy - startsAt) / 60_000),
|
|
56
|
+
endedAt: endedAt === null ? null : iso(endedAt),
|
|
57
|
+
cancelled: raw.state === "cancelled",
|
|
58
|
+
affects: Array.isArray(raw.affects)
|
|
59
|
+
? raw.affects.filter((a) => typeof a === "string").slice(0, 10)
|
|
60
|
+
: [],
|
|
61
|
+
message: typeof raw.message === "string" && raw.message.trim() ? raw.message.trim().slice(0, MESSAGE_MAX) : null,
|
|
62
|
+
server,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return { server, generatedAt: typeof input.generated_at === "string" ? input.generated_at : null, windows };
|
|
66
|
+
}
|
|
67
|
+
export const NO_MAINTENANCE = Object.freeze({ phase: "none", window: null, retryAfterSeconds: null });
|
|
68
|
+
/**
|
|
69
|
+
* The phase now, from the windows' times:
|
|
70
|
+
*
|
|
71
|
+
* - **active** from `leadSeconds` before a window starts until it ended
|
|
72
|
+
* (`endedAt`) or ran out (`endsBy`), unless it was cancelled;
|
|
73
|
+
* - **upcoming** when a window starts within `announceHours`;
|
|
74
|
+
* - **none** otherwise.
|
|
75
|
+
*
|
|
76
|
+
* Of several active windows the one ending last wins; of several coming, the
|
|
77
|
+
* soonest.
|
|
78
|
+
*/
|
|
79
|
+
export function maintenanceState(windows, now, timing = {}) {
|
|
80
|
+
const t = now.getTime();
|
|
81
|
+
const lead = (timing.leadSeconds ?? 60) * 1000;
|
|
82
|
+
const announce = (timing.announceHours ?? 168) * 3_600_000;
|
|
83
|
+
let active = null;
|
|
84
|
+
let upcoming = null;
|
|
85
|
+
for (const w of windows) {
|
|
86
|
+
if (w.cancelled)
|
|
87
|
+
continue;
|
|
88
|
+
const ended = time(w.endedAt);
|
|
89
|
+
if (ended !== null && ended <= t)
|
|
90
|
+
continue;
|
|
91
|
+
const start = Date.parse(w.startsAt);
|
|
92
|
+
const end = Date.parse(w.endsBy);
|
|
93
|
+
if (t >= end)
|
|
94
|
+
continue;
|
|
95
|
+
if (t >= start - lead) {
|
|
96
|
+
if (!active || end > Date.parse(active.endsBy))
|
|
97
|
+
active = w;
|
|
98
|
+
}
|
|
99
|
+
else if (start - t <= announce) {
|
|
100
|
+
if (!upcoming || start < Date.parse(upcoming.startsAt))
|
|
101
|
+
upcoming = w;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (active)
|
|
105
|
+
return {
|
|
106
|
+
phase: "active",
|
|
107
|
+
window: active,
|
|
108
|
+
retryAfterSeconds: Math.max(1, Math.ceil((Date.parse(active.endsBy) - t) / 1000)),
|
|
109
|
+
};
|
|
110
|
+
if (upcoming)
|
|
111
|
+
return { phase: "upcoming", window: upcoming, retryAfterSeconds: null };
|
|
112
|
+
return NO_MAINTENANCE;
|
|
113
|
+
}
|
|
114
|
+
/** A window standing in for `HOUSE_MAINTENANCE=on`: from now, for an hour, renewed on every read. */
|
|
115
|
+
export function overrideWindow(now) {
|
|
116
|
+
return {
|
|
117
|
+
id: "override",
|
|
118
|
+
kind: "maintenance",
|
|
119
|
+
startsAt: iso(now.getTime()),
|
|
120
|
+
endsBy: iso(now.getTime() + 3_600_000),
|
|
121
|
+
expectedMinutes: 60,
|
|
122
|
+
endedAt: null,
|
|
123
|
+
cancelled: false,
|
|
124
|
+
affects: ["postgres"],
|
|
125
|
+
message: null,
|
|
126
|
+
server: "app",
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function parts(ms, timeZone, locale) {
|
|
130
|
+
return Object.fromEntries(new Intl.DateTimeFormat(locale, {
|
|
131
|
+
timeZone,
|
|
132
|
+
weekday: "short",
|
|
133
|
+
day: "numeric",
|
|
134
|
+
month: "short",
|
|
135
|
+
hour: "2-digit",
|
|
136
|
+
minute: "2-digit",
|
|
137
|
+
hourCycle: "h23",
|
|
138
|
+
timeZoneName: "short",
|
|
139
|
+
})
|
|
140
|
+
.formatToParts(new Date(ms))
|
|
141
|
+
.map((p) => [p.type, p.value]));
|
|
142
|
+
}
|
|
143
|
+
/** A window in words, in the app's time zone (Europe/London unless said otherwise). */
|
|
144
|
+
export function describeWindow(window, { timeZone = "Europe/London", locale = "en-GB" } = {}) {
|
|
145
|
+
const s = parts(Date.parse(window.startsAt), timeZone, locale);
|
|
146
|
+
const e = parts(Date.parse(window.endsBy), timeZone, locale);
|
|
147
|
+
const day = `${s.weekday} ${s.day} ${s.month}`;
|
|
148
|
+
const endDay = `${e.weekday} ${e.day} ${e.month}`;
|
|
149
|
+
const start = `${s.hour}:${s.minute}`;
|
|
150
|
+
const end = `${e.hour}:${e.minute}`;
|
|
151
|
+
const zone = e.timeZoneName ?? "";
|
|
152
|
+
const text = day === endDay ? `${day}, ${start}–${end} ${zone}` : `${day} ${start} – ${endDay} ${end} ${zone}`;
|
|
153
|
+
return { day, start, end, zone, text, expected: expectedText(window.expectedMinutes) };
|
|
154
|
+
}
|
|
155
|
+
export function expectedText(minutes) {
|
|
156
|
+
const m = Math.max(1, Math.ceil(minutes));
|
|
157
|
+
if (m <= 5)
|
|
158
|
+
return "a few minutes";
|
|
159
|
+
if (m < 90)
|
|
160
|
+
return `about ${m} minutes`;
|
|
161
|
+
const hours = Math.round(m / 30) / 2;
|
|
162
|
+
return `about ${hours} hour${hours === 1 ? "" : "s"}`;
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/maintenance/core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,8FAA8F;AAC9F,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC;AA+B1C,MAAM,KAAK,GAAG,IAAI,GAAG,CAAwB,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC;AACxE,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,IAAI,CAAC,KAAc;IAC1B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,K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EAAE,CAAC;IACpC,MAAM,IAAI,GAAG,CAAC,CAAC,YAAY,IAAI,EAAE,CAAC;IAClC,MAAM,IAAI,GAAG,GAAG,KAAK,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,KAAK,KAAK,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,KAAK,MAAM,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IAC/G,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,YAAY,CAAC,MAAM,CAAC,eAAe,CAAC,EAAE,CAAC;AACzF,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,OAAe;IAC1C,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1C,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,eAAe,CAAC;IACnC,IAAI,CAAC,GAAG,EAAE;QAAE,OAAO,SAAS,CAAC,UAAU,CAAC;IACxC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;IACrC,OAAO,SAAS,KAAK,QAAQ,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type MaintenanceState, type MaintenanceTiming } from "./core.js";
|
|
2
|
+
/**
|
|
3
|
+
* The app's view of every server it depends on, kept in memory.
|
|
4
|
+
*
|
|
5
|
+
* One gate per process (module scope), read on every request by the proxy. It
|
|
6
|
+
* fetches a feed only when its copy is older than a minute — every 15 seconds
|
|
7
|
+
* near or during a window — with a short timeout, so a request never waits on a
|
|
8
|
+
* slow server for long. A failed fetch keeps the copy it has: during a reboot
|
|
9
|
+
* nothing answers, and the copy is what turns the maintenance page on at 23:00.
|
|
10
|
+
* A gate never throws.
|
|
11
|
+
*/
|
|
12
|
+
export interface MaintenanceGateOptions {
|
|
13
|
+
/** Each server's feed, e.g. `https://pgsql-node-1.connextar.com/maintenance.json`. */
|
|
14
|
+
feeds: readonly string[];
|
|
15
|
+
/** `on` forces the maintenance page, `off` never shows it, `auto` (or unset) follows the feeds. */
|
|
16
|
+
override?: string | undefined;
|
|
17
|
+
timing?: MaintenanceTiming;
|
|
18
|
+
/** Per fetch. Default 1000 ms. */
|
|
19
|
+
timeoutMs?: number;
|
|
20
|
+
/** How old a copy may get with nothing near. Default 60 s. */
|
|
21
|
+
idleRefreshSeconds?: number;
|
|
22
|
+
/** How old a copy may get within ten minutes of a window, or during one. Default 15 s. */
|
|
23
|
+
nearRefreshSeconds?: number;
|
|
24
|
+
fetch?: typeof fetch;
|
|
25
|
+
now?: () => Date;
|
|
26
|
+
/** A feed that failed (network, status, shape). Called on each failure; the app decides what to log. */
|
|
27
|
+
onError?: (feed: string, error: unknown) => void;
|
|
28
|
+
}
|
|
29
|
+
export interface MaintenanceGate {
|
|
30
|
+
/** The state now, refreshing a feed first when its copy is stale. */
|
|
31
|
+
state(): Promise<MaintenanceState>;
|
|
32
|
+
/** The state from the copies held, without fetching. */
|
|
33
|
+
peek(): MaintenanceState;
|
|
34
|
+
/** Fetch every feed now. */
|
|
35
|
+
refresh(): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
type Override = "on" | "off" | "auto";
|
|
38
|
+
export declare function parseOverride(value: string | undefined): Override;
|
|
39
|
+
export declare function createMaintenanceGate(options: MaintenanceGateOptions): MaintenanceGate;
|
|
40
|
+
/**
|
|
41
|
+
* A gate from the environment: `HOUSE_MAINTENANCE_FEEDS` (feed URLs, separated
|
|
42
|
+
* by commas or spaces) and `HOUSE_MAINTENANCE` (`on` / `off` / `auto`). Anything
|
|
43
|
+
* in a feed list that isn't an https URL (http on localhost) is left out.
|
|
44
|
+
*/
|
|
45
|
+
export declare function maintenanceGateFromEnv(env?: Record<string, string | undefined>, options?: Omit<MaintenanceGateOptions, "feeds" | "override">): MaintenanceGate;
|
|
46
|
+
export declare function feedsFromEnv(value: string | undefined): string[];
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=gate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../../src/maintenance/gate.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EAEvB,MAAM,WAAW,CAAC;AAEnB;;;;;;;;;GASG;AACH,MAAM,WAAW,sBAAsB;IACrC,sFAAsF;IACtF,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,mGAAmG;IACnG,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,kCAAkC;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8DAA8D;IAC9D,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,0FAA0F;IAC1F,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;IACjB,wGAAwG;IACxG,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CAClD;AAED,MAAM,WAAW,eAAe;IAC9B,qEAAqE;IACrE,KAAK,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACnC,wDAAwD;IACxD,IAAI,IAAI,gBAAgB,CAAC;IACzB,4BAA4B;IAC5B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED,KAAK,QAAQ,GAAG,IAAI,GAAG,KAAK,GAAG,MAAM,CAAC;AAEtC,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,QAAQ,CAKjE;AASD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,GAAG,eAAe,CA0EtF;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,EACrD,OAAO,GAAE,IAAI,CAAC,sBAAsB,EAAE,OAAO,GAAG,UAAU,CAAM,GAC/D,eAAe,CAMjB;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,CAehE"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { maintenanceState, NO_MAINTENANCE, overrideWindow, parseMaintenanceFeed, } from "./core.js";
|
|
2
|
+
export function parseOverride(value) {
|
|
3
|
+
const v = (value ?? "").trim().toLowerCase();
|
|
4
|
+
if (["on", "true", "1", "yes"].includes(v))
|
|
5
|
+
return "on";
|
|
6
|
+
if (["off", "false", "0", "no"].includes(v))
|
|
7
|
+
return "off";
|
|
8
|
+
return "auto";
|
|
9
|
+
}
|
|
10
|
+
const NEAR_MS = 10 * 60_000;
|
|
11
|
+
export function createMaintenanceGate(options) {
|
|
12
|
+
const feeds = [...new Set(options.feeds.filter(Boolean))];
|
|
13
|
+
const override = parseOverride(options.override);
|
|
14
|
+
const now = options.now ?? (() => new Date());
|
|
15
|
+
const doFetch = options.fetch ?? ((...args) => fetch(...args));
|
|
16
|
+
const timeoutMs = options.timeoutMs ?? 1000;
|
|
17
|
+
const idleMs = (options.idleRefreshSeconds ?? 60) * 1000;
|
|
18
|
+
const nearMs = (options.nearRefreshSeconds ?? 15) * 1000;
|
|
19
|
+
const lead = (options.timing?.leadSeconds ?? 60) * 1000;
|
|
20
|
+
const copies = new Map();
|
|
21
|
+
let inflight = null;
|
|
22
|
+
const allWindows = () => [...copies.values()].flatMap((c) => c.windows);
|
|
23
|
+
function peek() {
|
|
24
|
+
const at = now();
|
|
25
|
+
if (override === "off")
|
|
26
|
+
return NO_MAINTENANCE;
|
|
27
|
+
if (override === "on")
|
|
28
|
+
return maintenanceState([overrideWindow(at)], at, options.timing);
|
|
29
|
+
return maintenanceState(allWindows(), at, options.timing);
|
|
30
|
+
}
|
|
31
|
+
/** Near a window (within ten minutes of its start, or in it): fetch more often. */
|
|
32
|
+
function isNear(at) {
|
|
33
|
+
return allWindows().some((w) => {
|
|
34
|
+
if (w.cancelled || w.endedAt)
|
|
35
|
+
return false;
|
|
36
|
+
const start = Date.parse(w.startsAt) - lead;
|
|
37
|
+
return at >= start - NEAR_MS && at < Date.parse(w.endsBy);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async function fetchOne(feed) {
|
|
41
|
+
const at = now().getTime();
|
|
42
|
+
const previous = copies.get(feed);
|
|
43
|
+
try {
|
|
44
|
+
const res = await doFetch(feed, {
|
|
45
|
+
cache: "no-store",
|
|
46
|
+
headers: { accept: "application/json" },
|
|
47
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
48
|
+
});
|
|
49
|
+
if (!res.ok)
|
|
50
|
+
throw new Error(`HTTP ${res.status}`);
|
|
51
|
+
const parsed = parseMaintenanceFeed(await res.json());
|
|
52
|
+
if (!parsed)
|
|
53
|
+
throw new Error("not a maintenance feed this version understands");
|
|
54
|
+
copies.set(feed, { windows: parsed.windows, fetchedAt: at });
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
// Keep what we had; only the time moves, so a dead server is asked again on schedule, not on every request.
|
|
58
|
+
copies.set(feed, { windows: previous?.windows ?? [], fetchedAt: at });
|
|
59
|
+
options.onError?.(feed, error);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function refresh() {
|
|
63
|
+
if (!inflight) {
|
|
64
|
+
inflight = Promise.all(feeds.map(fetchOne))
|
|
65
|
+
.then(() => undefined)
|
|
66
|
+
.finally(() => {
|
|
67
|
+
inflight = null;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return inflight;
|
|
71
|
+
}
|
|
72
|
+
async function state() {
|
|
73
|
+
if (override !== "auto" || feeds.length === 0)
|
|
74
|
+
return peek();
|
|
75
|
+
const at = now().getTime();
|
|
76
|
+
const ttl = isNear(at) ? nearMs : idleMs;
|
|
77
|
+
const stale = feeds.some((f) => {
|
|
78
|
+
const copy = copies.get(f);
|
|
79
|
+
return !copy || at - copy.fetchedAt >= ttl;
|
|
80
|
+
});
|
|
81
|
+
if (stale)
|
|
82
|
+
await refresh();
|
|
83
|
+
return peek();
|
|
84
|
+
}
|
|
85
|
+
return { state, peek, refresh };
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* A gate from the environment: `HOUSE_MAINTENANCE_FEEDS` (feed URLs, separated
|
|
89
|
+
* by commas or spaces) and `HOUSE_MAINTENANCE` (`on` / `off` / `auto`). Anything
|
|
90
|
+
* in a feed list that isn't an https URL (http on localhost) is left out.
|
|
91
|
+
*/
|
|
92
|
+
export function maintenanceGateFromEnv(env = process.env, options = {}) {
|
|
93
|
+
return createMaintenanceGate({
|
|
94
|
+
...options,
|
|
95
|
+
feeds: feedsFromEnv(env.HOUSE_MAINTENANCE_FEEDS),
|
|
96
|
+
override: env.HOUSE_MAINTENANCE,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
export function feedsFromEnv(value) {
|
|
100
|
+
return (value ?? "")
|
|
101
|
+
.split(/[\s,]+/)
|
|
102
|
+
.map((s) => s.trim())
|
|
103
|
+
.filter((s) => {
|
|
104
|
+
try {
|
|
105
|
+
const url = new URL(s);
|
|
106
|
+
return (url.protocol === "https:" ||
|
|
107
|
+
(url.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname)));
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=gate.js.map
|
|
@@ -0,0 +1 @@
|
|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AC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SACpB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;QACZ,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC;YACvB,OAAO,CACL,GAAG,CAAC,QAAQ,KAAK,QAAQ;gBACzB,CAAC,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CACzF,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { describeWindow, expectedText, MAINTENANCE_FEED_VERSION, maintenanceState, NO_MAINTENANCE, overrideWindow, parseMaintenanceFeed, type DescribedWindow, type MaintenanceFeed, type MaintenancePhase, type MaintenanceState, type MaintenanceTiming, type MaintenanceWindow, type MaintenanceWindowKind, type WindowWording, } from "./core.js";
|
|
2
|
+
export { createMaintenanceGate, feedsFromEnv, maintenanceGateFromEnv, parseOverride, type MaintenanceGate, type MaintenanceGateOptions, } from "./gate.js";
|
|
3
|
+
export { maintenancePageHtml, type MaintenancePageOptions } from "./page.js";
|
|
4
|
+
export { maintenanceOnlyResponse, maintenanceResponse, passesDuringMaintenance, type MaintenanceProxyOptions, } from "./proxy.js";
|
|
5
|
+
export { createMaintenanceRoute, publicWindow, type MaintenanceRouteOptions, type MaintenanceStateBody, type PublicMaintenanceWindow, } from "./route.js";
|
|
6
|
+
export { isUnavailableError } from "./unavailable.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/maintenance/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,YAAY,EACZ,wBAAwB,EACxB,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,aAAa,GACnB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,qBAAqB,EACrB,YAAY,EACZ,sBAAsB,EACtB,aAAa,EACb,KAAK,eAAe,EACpB,KAAK,sBAAsB,GAC5B,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,mBAAmB,EAAE,KAAK,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAC7E,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,uBAAuB,EACvB,KAAK,uBAAuB,GAC7B,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,GAC7B,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { describeWindow, expectedText, MAINTENANCE_FEED_VERSION, maintenanceState, NO_MAINTENANCE, overrideWindow, parseMaintenanceFeed, } from "./core.js";
|
|
2
|
+
export { createMaintenanceGate, feedsFromEnv, maintenanceGateFromEnv, parseOverride, } from "./gate.js";
|
|
3
|
+
export { maintenancePageHtml } from "./page.js";
|
|
4
|
+
export { maintenanceOnlyResponse, maintenanceResponse, passesDuringMaintenance, } from "./proxy.js";
|
|
5
|
+
export { createMaintenanceRoute, publicWindow, } from "./route.js";
|
|
6
|
+
export { isUnavailableError } from "./unavailable.js";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/maintenance/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,YAAY,EACZ,wBAAwB,EACxB,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,oBAAoB,GASrB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,qBAAqB,EACrB,YAAY,EACZ,sBAAsB,EACtB,aAAa,GAGd,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,mBAAmB,EAA+B,MAAM,WAAW,CAAC;AAC7E,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,uBAAuB,GAExB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,sBAAsB,EACtB,YAAY,GAIb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type MaintenanceWindow, type WindowWording } from "./core.js";
|
|
2
|
+
/**
|
|
3
|
+
* The maintenance page: a whole HTML document, returned by the proxy itself.
|
|
4
|
+
*
|
|
5
|
+
* Not an app route, on purpose. While the database is down an app's own pages
|
|
6
|
+
* can't be trusted to render — a layout reads the session, a header counts
|
|
7
|
+
* notifications — and an App Router page can't answer 503. This needs nothing:
|
|
8
|
+
* no React, no script, no stylesheet, no font. It reloads itself with a meta
|
|
9
|
+
* refresh, so it needs no script either (and so no CSP exception): when the
|
|
10
|
+
* window ends, the next reload is the real page.
|
|
11
|
+
*/
|
|
12
|
+
export interface MaintenancePageOptions extends WindowWording {
|
|
13
|
+
/** The app's name as people know it: "AltEd". */
|
|
14
|
+
appName: string;
|
|
15
|
+
/** Seconds between reloads. Default 30. */
|
|
16
|
+
refreshSeconds?: number;
|
|
17
|
+
/** Where to ask a question meanwhile, shown as a mailto link. */
|
|
18
|
+
contactEmail?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function maintenancePageHtml(window: MaintenanceWindow, options: MaintenancePageOptions): string;
|
|
21
|
+
//# sourceMappingURL=page.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../../src/maintenance/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,iBAAiB,EAAE,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAEvF;;;;;;;;;GASG;AACH,MAAM,WAAW,sBAAuB,SAAQ,aAAa;IAC3D,iDAAiD;IACjD,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,iEAAiE;IACjE,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AASD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,sBAAsB,GAAG,MAAM,CA+CtG"}
|