@connextar/house 0.22.2 → 0.23.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 +574 -62
- package/dist/admin/index.d.ts +2 -2
- package/dist/admin/index.d.ts.map +1 -1
- package/dist/admin/index.js +2 -2
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/proof.d.ts +49 -9
- package/dist/admin/proof.d.ts.map +1 -1
- package/dist/admin/proof.js +83 -4
- package/dist/admin/proof.js.map +1 -1
- package/dist/admin/second-factor.d.ts +3 -1
- package/dist/admin/second-factor.d.ts.map +1 -1
- package/dist/admin/second-factor.js +3 -2
- package/dist/admin/second-factor.js.map +1 -1
- package/dist/admin/view-as.d.ts +37 -5
- package/dist/admin/view-as.d.ts.map +1 -1
- package/dist/admin/view-as.js +67 -6
- package/dist/admin/view-as.js.map +1 -1
- package/dist/analytics/browser.d.ts +108 -0
- package/dist/analytics/browser.d.ts.map +1 -0
- package/dist/analytics/browser.js +319 -0
- package/dist/analytics/browser.js.map +1 -0
- package/dist/analytics/client-index.d.ts +6 -0
- package/dist/analytics/client-index.d.ts.map +1 -0
- package/dist/analytics/client-index.js +6 -0
- package/dist/analytics/client-index.js.map +1 -0
- package/dist/analytics/config.d.ts +50 -0
- package/dist/analytics/config.d.ts.map +1 -0
- package/dist/analytics/config.js +39 -0
- package/dist/analytics/config.js.map +1 -0
- package/dist/analytics/index.d.ts +10 -0
- package/dist/analytics/index.d.ts.map +1 -0
- package/dist/analytics/index.js +10 -0
- package/dist/analytics/index.js.map +1 -0
- package/dist/analytics/ingest.d.ts +30 -0
- package/dist/analytics/ingest.d.ts.map +1 -0
- package/dist/analytics/ingest.js +64 -0
- package/dist/analytics/ingest.js.map +1 -0
- package/dist/analytics/react-index.d.ts +6 -0
- package/dist/analytics/react-index.d.ts.map +1 -0
- package/dist/analytics/react-index.js +6 -0
- package/dist/analytics/react-index.js.map +1 -0
- package/dist/analytics/react.d.ts +75 -0
- package/dist/analytics/react.d.ts.map +1 -0
- package/dist/analytics/react.js +159 -0
- package/dist/analytics/react.js.map +1 -0
- package/dist/analytics/redact.d.ts +35 -0
- package/dist/analytics/redact.d.ts.map +1 -0
- package/dist/analytics/redact.js +109 -0
- package/dist/analytics/redact.js.map +1 -0
- package/dist/analytics/server-index.d.ts +6 -0
- package/dist/analytics/server-index.d.ts.map +1 -0
- package/dist/analytics/server-index.js +6 -0
- package/dist/analytics/server-index.js.map +1 -0
- package/dist/analytics/server.d.ts +89 -0
- package/dist/analytics/server.d.ts.map +1 -0
- package/dist/analytics/server.js +211 -0
- package/dist/analytics/server.js.map +1 -0
- package/dist/jobs/idle.d.ts +49 -0
- package/dist/jobs/idle.d.ts.map +1 -0
- package/dist/jobs/idle.js +61 -0
- package/dist/jobs/idle.js.map +1 -0
- package/dist/jobs/index.d.ts +2 -1
- package/dist/jobs/index.d.ts.map +1 -1
- package/dist/jobs/index.js +2 -1
- package/dist/jobs/index.js.map +1 -1
- package/dist/jobs/next-index.d.ts +5 -0
- package/dist/jobs/next-index.d.ts.map +1 -0
- package/dist/jobs/next-index.js +5 -0
- package/dist/jobs/next-index.js.map +1 -0
- package/dist/jobs/next.d.ts +25 -0
- package/dist/jobs/next.d.ts.map +1 -0
- package/dist/jobs/next.js +51 -0
- package/dist/jobs/next.js.map +1 -0
- package/dist/jobs/prisma-index.d.ts +6 -0
- package/dist/jobs/prisma-index.d.ts.map +1 -0
- package/dist/jobs/prisma-index.js +6 -0
- package/dist/jobs/prisma-index.js.map +1 -0
- package/dist/jobs/prisma.d.ts +77 -0
- package/dist/jobs/prisma.d.ts.map +1 -0
- package/dist/jobs/prisma.js +92 -0
- package/dist/jobs/prisma.js.map +1 -0
- package/dist/jobs/scheduler.d.ts +7 -0
- package/dist/jobs/scheduler.d.ts.map +1 -1
- package/dist/jobs/scheduler.js +10 -0
- package/dist/jobs/scheduler.js.map +1 -1
- package/dist/maintenance/react.d.ts +9 -2
- package/dist/maintenance/react.d.ts.map +1 -1
- package/dist/maintenance/react.js +15 -4
- package/dist/maintenance/react.js.map +1 -1
- package/dist/rate-limit/better-auth.d.ts +50 -0
- package/dist/rate-limit/better-auth.d.ts.map +1 -0
- package/dist/rate-limit/better-auth.js +64 -0
- package/dist/rate-limit/better-auth.js.map +1 -0
- package/dist/rate-limit/index.d.ts +13 -0
- package/dist/rate-limit/index.d.ts.map +1 -0
- package/dist/rate-limit/index.js +13 -0
- package/dist/rate-limit/index.js.map +1 -0
- package/dist/rate-limit/keys.d.ts +45 -0
- package/dist/rate-limit/keys.d.ts.map +1 -0
- package/dist/rate-limit/keys.js +95 -0
- package/dist/rate-limit/keys.js.map +1 -0
- package/dist/rate-limit/limiter.d.ts +114 -0
- package/dist/rate-limit/limiter.d.ts.map +1 -0
- package/dist/rate-limit/limiter.js +166 -0
- package/dist/rate-limit/limiter.js.map +1 -0
- package/dist/rate-limit/prisma-index.d.ts +6 -0
- package/dist/rate-limit/prisma-index.d.ts.map +1 -0
- package/dist/rate-limit/prisma-index.js +6 -0
- package/dist/rate-limit/prisma-index.js.map +1 -0
- package/dist/rate-limit/prisma.d.ts +116 -0
- package/dist/rate-limit/prisma.d.ts.map +1 -0
- package/dist/rate-limit/prisma.js +79 -0
- package/dist/rate-limit/prisma.js.map +1 -0
- package/dist/rate-limit/store.d.ts +27 -0
- package/dist/rate-limit/store.d.ts.map +1 -0
- package/dist/rate-limit/store.js +28 -0
- package/dist/rate-limit/store.js.map +1 -0
- package/docs/Maintenance.md +7 -2
- package/package.json +36 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where windows are counted — the app's table, behind this interface, as `jobs` keeps its ledger.
|
|
3
|
+
*
|
|
4
|
+
* The package owns no schema. Ten apps already have a `rate_limit` table of one shape (`key`, `window_at`, `count`,
|
|
5
|
+
* unique on the first two) and MAS keeps the same model in MongoDB; `@connextar/house/rate-limit/prisma` is the
|
|
6
|
+
* adapter for all of them, so adopting the limiter needs no migration.
|
|
7
|
+
*/
|
|
8
|
+
export interface RateLimitStore {
|
|
9
|
+
/**
|
|
10
|
+
* Add `amount` to the window `(key, windowAt)`, creating it at `amount`, and resolve with its count afterwards —
|
|
11
|
+
* in one atomic step, so two requests at once can never both read the count before either adds to it.
|
|
12
|
+
*/
|
|
13
|
+
increment(key: string, windowAt: Date, amount: number): Promise<number>;
|
|
14
|
+
/** The window's count, or 0 when there is none. Never writes. */
|
|
15
|
+
read(key: string, windowAt: Date): Promise<number>;
|
|
16
|
+
/** Delete at most `limit` windows that started before `before`, oldest first, and resolve with how many went. */
|
|
17
|
+
prune(before: Date, limit: number): Promise<number>;
|
|
18
|
+
}
|
|
19
|
+
/** The whole contract in memory — for tests, the app's included. */
|
|
20
|
+
export declare function memoryRateLimitStore(): RateLimitStore & {
|
|
21
|
+
windows: Map<string, {
|
|
22
|
+
key: string;
|
|
23
|
+
windowAt: Date;
|
|
24
|
+
count: number;
|
|
25
|
+
}>;
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/rate-limit/store.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACxE,iEAAiE;IACjE,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACnD,iHAAiH;IACjH,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACrD;AAED,oEAAoE;AACpE,wBAAgB,oBAAoB,IAAI,cAAc,GAAG;IACvD,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,IAAI,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACtE,CAwBA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** The whole contract in memory — for tests, the app's included. */
|
|
2
|
+
export function memoryRateLimitStore() {
|
|
3
|
+
const windows = new Map();
|
|
4
|
+
const id = (key, windowAt) => `${windowAt.getTime()}\u0000${key}`;
|
|
5
|
+
return {
|
|
6
|
+
windows,
|
|
7
|
+
async increment(key, windowAt, amount) {
|
|
8
|
+
const at = id(key, windowAt);
|
|
9
|
+
const row = windows.get(at) ?? { key, windowAt, count: 0 };
|
|
10
|
+
row.count += amount;
|
|
11
|
+
windows.set(at, row);
|
|
12
|
+
return row.count;
|
|
13
|
+
},
|
|
14
|
+
async read(key, windowAt) {
|
|
15
|
+
return windows.get(id(key, windowAt))?.count ?? 0;
|
|
16
|
+
},
|
|
17
|
+
async prune(before, limit) {
|
|
18
|
+
const doomed = [...windows.entries()]
|
|
19
|
+
.filter(([, row]) => row.windowAt.getTime() < before.getTime())
|
|
20
|
+
.sort(([, a], [, b]) => a.windowAt.getTime() - b.windowAt.getTime())
|
|
21
|
+
.slice(0, limit);
|
|
22
|
+
for (const [at] of doomed)
|
|
23
|
+
windows.delete(at);
|
|
24
|
+
return doomed.length;
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/rate-limit/store.ts"],"names":[],"mappings":"AAmBA,oEAAoE;AACpE,MAAM,UAAU,oBAAoB;IAGlC,MAAM,OAAO,GAAG,IAAI,GAAG,EAA0D,CAAC;IAClF,MAAM,EAAE,GAAG,CAAC,GAAW,EAAE,QAAc,EAAE,EAAE,CAAC,GAAG,QAAQ,CAAC,OAAO,EAAE,S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C,MAAM,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/docs/Maintenance.md
CHANGED
|
@@ -96,7 +96,7 @@ Two entry points. The README has the API and the adoption steps.
|
|
|
96
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
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
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.
|
|
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. Re-read every 15 s during a window, 30 s in the quarter hour before, five minutes otherwise. |
|
|
100
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
101
|
| `isUnavailableError` | For an API route's catch: an unreachable database or file store is a `503`, not a `500`. |
|
|
102
102
|
|
|
@@ -107,7 +107,7 @@ Two entry points. The README has the API and the adoption steps.
|
|
|
107
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
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
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.**
|
|
110
|
+
4. **Webhooks.** An app answers `503` during a window, so the sender retries later instead of the event being half-handled. Stripe events reach the apps through cx-stripe-gateway, whose database is on Neon: it stays up, queues a failed delivery and retries after 5, 10, 20 and 40 minutes, which outlasts any window.
|
|
111
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
112
|
6. **Search engines and AI crawlers.** `503` with `Retry-After` keeps the maintenance page out of every index.
|
|
113
113
|
|
|
@@ -119,3 +119,8 @@ Two entry points. The README has the API and the adoption steps.
|
|
|
119
119
|
2. **cx-house:** the module in §3, with tests. Publishing needs the owner's npm 2FA.
|
|
120
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
121
|
4. **Every other app whose database or files are on the server:** the feed URL and the same few files.
|
|
122
|
+
|
|
123
|
+
## 6. Where it stands (4 November 2026)
|
|
124
|
+
|
|
125
|
+
- **First real window, the 23:00 UTC reboot:** the server was back and the window ended at 23:00:35. AltEd's proxy answered `503` with the maintenance page from 22:59:07 to 23:00:19 (the last request seen before the end), its crons were skipped at 22:59, 23:00 and 23:00:32, ordinary pages were served again from 23:00:44, and no error was logged between 22:50 and 23:15. Instances whose feed fetch failed during the reboot kept their copy as designed (logged as a warning). The one fault: an open tab's banner re-read the state only every five minutes once a window was under way, so after an early finish it could keep saying "under way"; fixed in 0.22.3.
|
|
126
|
+
- **Step 4:** AltEd is the only app with a database (`config/databases/`) or a bucket (`config/objects/`) on CX_PGSQL_Node_1. The other house apps are on Neon, and an app subscribes only to the feeds of servers it uses, so none of them adopts the module yet. An app moving to the server adds `HOUSE_MAINTENANCE_FEEDS` and the files AltEd added in v0.173.0: `proxy.ts`, the state route, the banner in the root layout, the `error.tsx` check, `isUnavailableError` in its API error handler and a connect timeout.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@connextar/house",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
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": {
|
|
@@ -106,6 +106,38 @@
|
|
|
106
106
|
"types": "./dist/jobs/react-index.d.ts",
|
|
107
107
|
"default": "./dist/jobs/react-index.js"
|
|
108
108
|
},
|
|
109
|
+
"./jobs/prisma": {
|
|
110
|
+
"types": "./dist/jobs/prisma-index.d.ts",
|
|
111
|
+
"default": "./dist/jobs/prisma-index.js"
|
|
112
|
+
},
|
|
113
|
+
"./jobs/next": {
|
|
114
|
+
"types": "./dist/jobs/next-index.d.ts",
|
|
115
|
+
"default": "./dist/jobs/next-index.js"
|
|
116
|
+
},
|
|
117
|
+
"./rate-limit": {
|
|
118
|
+
"types": "./dist/rate-limit/index.d.ts",
|
|
119
|
+
"default": "./dist/rate-limit/index.js"
|
|
120
|
+
},
|
|
121
|
+
"./rate-limit/prisma": {
|
|
122
|
+
"types": "./dist/rate-limit/prisma-index.d.ts",
|
|
123
|
+
"default": "./dist/rate-limit/prisma-index.js"
|
|
124
|
+
},
|
|
125
|
+
"./analytics": {
|
|
126
|
+
"types": "./dist/analytics/index.d.ts",
|
|
127
|
+
"default": "./dist/analytics/index.js"
|
|
128
|
+
},
|
|
129
|
+
"./analytics/client": {
|
|
130
|
+
"types": "./dist/analytics/client-index.d.ts",
|
|
131
|
+
"default": "./dist/analytics/client-index.js"
|
|
132
|
+
},
|
|
133
|
+
"./analytics/react": {
|
|
134
|
+
"types": "./dist/analytics/react-index.d.ts",
|
|
135
|
+
"default": "./dist/analytics/react-index.js"
|
|
136
|
+
},
|
|
137
|
+
"./analytics/server": {
|
|
138
|
+
"types": "./dist/analytics/server-index.d.ts",
|
|
139
|
+
"default": "./dist/analytics/server-index.js"
|
|
140
|
+
},
|
|
109
141
|
"./web-search": {
|
|
110
142
|
"types": "./dist/web-search/index.d.ts",
|
|
111
143
|
"default": "./dist/web-search/index.js"
|
|
@@ -204,6 +236,7 @@
|
|
|
204
236
|
"@anthropic-ai/sdk": "^0.128.0",
|
|
205
237
|
"@better-auth/core": "1.7.2",
|
|
206
238
|
"@better-auth/passkey": "1.7.2",
|
|
239
|
+
"@electric-sql/pglite": "0.5.13",
|
|
207
240
|
"@eslint/js": "^9.39.5",
|
|
208
241
|
"@testing-library/react": "^16.3.3",
|
|
209
242
|
"@types/node": "^26.4.1",
|
|
@@ -218,6 +251,8 @@
|
|
|
218
251
|
"jsdom": "^27.4.0",
|
|
219
252
|
"next": "^16.3.3",
|
|
220
253
|
"openai": "^7.23.0",
|
|
254
|
+
"posthog-js": "1.438.13",
|
|
255
|
+
"posthog-node": "5.56.2",
|
|
221
256
|
"prettier": "^3.0.0",
|
|
222
257
|
"react": "^19.2.8",
|
|
223
258
|
"react-dom": "^19.2.8",
|