create-prenta 1.9.2 → 1.9.3
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/CHANGELOG.md +10 -0
- package/dist/templates/admin-page.ts.template.d.ts.map +1 -1
- package/dist/templates/admin-page.ts.template.js +9 -41
- package/dist/templates/admin-page.ts.template.js.map +1 -1
- package/dist/templates/login-page.ts.template.d.ts.map +1 -1
- package/dist/templates/login-page.ts.template.js +9 -41
- package/dist/templates/login-page.ts.template.js.map +1 -1
- package/dist/templates/status-check.snippet.d.ts +21 -0
- package/dist/templates/status-check.snippet.d.ts.map +1 -0
- package/dist/templates/status-check.snippet.js +140 -0
- package/dist/templates/status-check.snippet.js.map +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# create-actuate-cms
|
|
2
2
|
|
|
3
|
+
## 1.9.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 6d008fc: Stop the admin locking its own users out. Every admin read and write shared one budget of 100 requests a minute per IP. One admin screen issues about a dozen reads and every editor in an office shares an IP, so clicking through the sidebar for a minute returned "Too many requests" and took autosave down with it.
|
|
8
|
+
|
|
9
|
+
`GET` routes that require a session or API key now have their own budget of 600 a minute, counted apart from writes and sign-in, so neither can use up the other. The class is an allow-list of admin areas (documents, media, forms, SEO, jobs, settings, the admin search and so on); the route contract test fails if a route in it stops rejecting anonymous requests. Everything else keeps 100 a minute: writes, `/auth/*`, `/dev/*`, `/mcp/*`, exports, the cron and preview routes, `/setup/status`, `/captcha/config`, `/search`, the bare `/collections` listing, `/openapi.json`, `/docs`, the redirect list and lookup, and the generated public files (sitemaps, feeds, `robots.txt`, `llms.txt`). The public read and beacon classes (1,000 a minute) are unchanged. API-key clients reading the same admin routes get the 600-a-minute budget too.
|
|
10
|
+
|
|
11
|
+
New projects also stop reporting a rate limit as a setup failure. The scaffolded admin and login pages showed "Setup can't continue yet. Could not reach the CMS backend: Too many requests". They now show "The CMS is busy. Retrying…" and retry for up to a minute, treat a rate-limited sign-in check the same way instead of showing the login form, and in production name a missing rate limiter store (Upstash or KV) as the cause, since waiting never fixes that. Existing projects keep their generated `page.tsx`; copy `loadStatus` and the `useEffect` from a fresh scaffold to get the same behaviour.
|
|
12
|
+
|
|
3
13
|
## 1.9.2
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin-page.ts.template.d.ts","sourceRoot":"","sources":["../../src/templates/admin-page.ts.template.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"admin-page.ts.template.d.ts","sourceRoot":"","sources":["../../src/templates/admin-page.ts.template.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;OAQG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B;;;;;OAKG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAA;IAC/B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,gBAAqB,GAAG,MAAM,CAyHxE"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { STATUS_BUSY_HINT_SOURCE, STATUS_CHECK_SOURCE, STATUS_EFFECT_SOURCE, } from './status-check.snippet.js';
|
|
1
2
|
export function generateAdminPage(options = {}) {
|
|
2
3
|
return [
|
|
3
4
|
"'use client';",
|
|
@@ -18,52 +19,18 @@ export function generateAdminPage(options = {}) {
|
|
|
18
19
|
]
|
|
19
20
|
: []),
|
|
20
21
|
'',
|
|
22
|
+
...STATUS_CHECK_SOURCE.split('\n'),
|
|
23
|
+
'',
|
|
21
24
|
'export default function AdminPage() {',
|
|
22
25
|
' const [session, setSession] = useState<any>(null);',
|
|
23
26
|
' const [setupRequired, setSetupRequired] = useState(false);',
|
|
24
27
|
' const [loading, setLoading] = useState(true);',
|
|
25
28
|
' const [statusError, setStatusError] = useState<string | null>(null);',
|
|
29
|
+
' const [statusTitle, setStatusTitle] = useState(SETUP_TITLE);',
|
|
30
|
+
' const [busy, setBusy] = useState(false);',
|
|
26
31
|
' const [captchaConfig, setCaptchaConfig] = useState<CaptchaConfig | undefined>(undefined);',
|
|
27
32
|
'',
|
|
28
|
-
'
|
|
29
|
-
' async function checkAuth() {',
|
|
30
|
-
' const [setupRes, captchaRes] = await Promise.all([',
|
|
31
|
-
" cmsApi<{ setupRequired: boolean; migrationsRequired?: boolean }>('/setup/status'),",
|
|
32
|
-
" cmsApi<{ provider: string; siteKey: string | null }>('/captcha/config?for=login'),",
|
|
33
|
-
' ]);',
|
|
34
|
-
'',
|
|
35
|
-
' if (captchaRes.data) {',
|
|
36
|
-
' setCaptchaConfig(captchaRes.data as CaptchaConfig);',
|
|
37
|
-
' }',
|
|
38
|
-
'',
|
|
39
|
-
' // Database is reachable but has no Prenta CMS tables yet — tell the',
|
|
40
|
-
' // operator to run migrations instead of dropping them on the login screen.',
|
|
41
|
-
' if (setupRes.data?.migrationsRequired) {',
|
|
42
|
-
" setStatusError('Your database has no Prenta CMS tables yet. Run `npx prisma migrate deploy` against your database, then reload this page.');",
|
|
43
|
-
' setLoading(false);',
|
|
44
|
-
' return;',
|
|
45
|
-
' }',
|
|
46
|
-
'',
|
|
47
|
-
' // The status check itself failed (e.g. the database is unreachable).',
|
|
48
|
-
' if (setupRes.error) {',
|
|
49
|
-
" setStatusError('Could not reach the CMS backend: ' + setupRes.error);",
|
|
50
|
-
' setLoading(false);',
|
|
51
|
-
' return;',
|
|
52
|
-
' }',
|
|
53
|
-
'',
|
|
54
|
-
' if (setupRes.data?.setupRequired) {',
|
|
55
|
-
' setSetupRequired(true);',
|
|
56
|
-
' setLoading(false);',
|
|
57
|
-
' return;',
|
|
58
|
-
' }',
|
|
59
|
-
" const meRes = await cmsApi<{ id: string; email: string; name: string; role: string }>('/auth/me');",
|
|
60
|
-
' if (meRes.data) {',
|
|
61
|
-
' setSession({ user: meRes.data });',
|
|
62
|
-
' }',
|
|
63
|
-
' setLoading(false);',
|
|
64
|
-
' }',
|
|
65
|
-
' checkAuth();',
|
|
66
|
-
' }, []);',
|
|
33
|
+
...STATUS_EFFECT_SOURCE.split('\n'),
|
|
67
34
|
'',
|
|
68
35
|
' const handleLogin = async (email: string, password: string, captchaToken?: string) => {',
|
|
69
36
|
' const res = await cmsApi<{',
|
|
@@ -110,8 +77,9 @@ export function generateAdminPage(options = {}) {
|
|
|
110
77
|
'',
|
|
111
78
|
' if (loading) {',
|
|
112
79
|
' return (',
|
|
113
|
-
" <div className=\"prenta-admin\" style={{ minHeight: '100vh', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>",
|
|
80
|
+
" <div className=\"prenta-admin\" style={{ minHeight: '100vh', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center' }}>",
|
|
114
81
|
" <div style={{ width: 24, height: 24, border: '3px solid #e5e7eb', borderTopColor: '#2563eb', borderRadius: '50%', animation: 'spin 1s linear infinite' }} />",
|
|
82
|
+
STATUS_BUSY_HINT_SOURCE,
|
|
115
83
|
' <style>{`@keyframes spin { to { transform: rotate(360deg) } }`}</style>',
|
|
116
84
|
' </div>',
|
|
117
85
|
' );',
|
|
@@ -121,7 +89,7 @@ export function generateAdminPage(options = {}) {
|
|
|
121
89
|
' return (',
|
|
122
90
|
" <div className=\"prenta-admin\" style={{ minHeight: '100vh', display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 24 }}>",
|
|
123
91
|
" <div style={{ maxWidth: 520, width: '100%', border: '1px solid #e5e7eb', borderRadius: 12, padding: '28px 32px', background: '#fff', color: '#111827' }}>",
|
|
124
|
-
" <h1 style={{ fontSize: '1.25rem', fontWeight: 500, margin: '0 0 8px' }}>
|
|
92
|
+
" <h1 style={{ fontSize: '1.25rem', fontWeight: 500, margin: '0 0 8px' }}>{statusTitle}</h1>",
|
|
125
93
|
" <p style={{ margin: 0, color: '#6b7280', lineHeight: 1.5 }}>{statusError}</p>",
|
|
126
94
|
' </div>',
|
|
127
95
|
' </div>',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin-page.ts.template.js","sourceRoot":"","sources":["../../src/templates/admin-page.ts.template.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"admin-page.ts.template.js","sourceRoot":"","sources":["../../src/templates/admin-page.ts.template.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,2BAA2B,CAAA;AA4BlC,MAAM,UAAU,iBAAiB,CAAC,UAA4B,EAAE;IAC9D,OAAO;QACL,eAAe;QACf,EAAE;QACF,8CAA8C;QAC9C,oDAAoD;QACpD,qDAAqD;QACrD,iDAAiD;QACjD,4EAA4E;QAC5E,2EAA2E;QAC3E,2EAA2E;QAC3E,0EAA0E;QAC1E,kCAAkC;QAClC,qEAAqE;QACrE,GAAG,CAAC,OAAO,CAAC,gBAAgB;YAC1B,CAAC,CAAC;gBACE,+DAA+D,OAAO,CAAC,sBAAsB,IAAI,mCAAmC,IAAI;aACzI;YACH,CAAC,CAAC,EAAE,CAAC;QACP,EAAE;QACF,GAAG,mBAAmB,CAAC,KAAK,CAAC,IAAI,CAAC;QAClC,EAAE;QACF,uCAAuC;QACvC,sDAAsD;QACtD,8DAA8D;QAC9D,iDAAiD;QACjD,wEAAwE;QACxE,gEAAgE;QAChE,4CAA4C;QAC5C,6FAA6F;QAC7F,EAAE;QACF,GAAG,oBAAoB,CAAC,KAAK,CAAC,IAAI,CAAC;QACnC,EAAE;QACF,2FAA2F;QAC3F,gCAAgC;QAChC,uBAAuB;QACvB,mBAAmB;QACnB,+BAA+B;QAC/B,iCAAiC;QACjC,yBAAyB;QACzB,uBAAuB;QACvB,gEAAgE;QAChE,SAAS;QACT,iEAAiE;QACjE,+EAA+E;QAC/E,+DAA+D;QAC/D,iGAAiG;QACjG,OAAO;QACP,2BAA2B;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ourceRoot":"","sources":["../../src/templates/login-page.ts.template.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"login-page.ts.template.d.ts","sourceRoot":"","sources":["../../src/templates/login-page.ts.template.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,gBAAgB;IAC/B,6DAA6D;IAC7D,SAAS,EAAE,MAAM,CAAA;IACjB,2DAA2D;IAC3D,SAAS,EAAE,MAAM,CAAA;CAClB;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAsGnE"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { STATUS_BUSY_HINT_SOURCE, STATUS_CHECK_SOURCE, STATUS_EFFECT_SOURCE, } from './status-check.snippet.js';
|
|
1
2
|
/**
|
|
2
3
|
* Split-login installs: a standalone page (mounted at `loginPath`) that
|
|
3
4
|
* renders `LoginRoot` — login + MFA, the first-run setup wizard, and the
|
|
@@ -12,52 +13,18 @@ import { LoginRoot, cmsApi } from '@prenta/admin';
|
|
|
12
13
|
import type { CaptchaConfig } from '@prenta/admin';
|
|
13
14
|
import config from '../../../../prenta.config';
|
|
14
15
|
|
|
16
|
+
${STATUS_CHECK_SOURCE}
|
|
17
|
+
|
|
15
18
|
export default function LoginPage() {
|
|
16
19
|
const [session, setSession] = useState<any>(null);
|
|
17
20
|
const [setupRequired, setSetupRequired] = useState(false);
|
|
18
21
|
const [loading, setLoading] = useState(true);
|
|
19
22
|
const [statusError, setStatusError] = useState<string | null>(null);
|
|
23
|
+
const [statusTitle, setStatusTitle] = useState(SETUP_TITLE);
|
|
24
|
+
const [busy, setBusy] = useState(false);
|
|
20
25
|
const [captchaConfig, setCaptchaConfig] = useState<CaptchaConfig | undefined>(undefined);
|
|
21
26
|
|
|
22
|
-
|
|
23
|
-
async function checkAuth() {
|
|
24
|
-
const [setupRes, captchaRes] = await Promise.all([
|
|
25
|
-
cmsApi<{ setupRequired: boolean; migrationsRequired?: boolean }>('/setup/status'),
|
|
26
|
-
cmsApi<{ provider: string; siteKey: string | null }>('/captcha/config?for=login'),
|
|
27
|
-
]);
|
|
28
|
-
|
|
29
|
-
if (captchaRes.data) {
|
|
30
|
-
setCaptchaConfig(captchaRes.data as CaptchaConfig);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Database is reachable but has no Prenta CMS tables yet — tell the
|
|
34
|
-
// operator to run migrations instead of dropping them on the login screen.
|
|
35
|
-
if (setupRes.data?.migrationsRequired) {
|
|
36
|
-
setStatusError('Your database has no Prenta CMS tables yet. Run \`npx prisma migrate deploy\` against your database, then reload this page.');
|
|
37
|
-
setLoading(false);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// The status check itself failed (e.g. the database is unreachable).
|
|
42
|
-
if (setupRes.error) {
|
|
43
|
-
setStatusError('Could not reach the CMS backend: ' + setupRes.error);
|
|
44
|
-
setLoading(false);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (setupRes.data?.setupRequired) {
|
|
49
|
-
setSetupRequired(true);
|
|
50
|
-
setLoading(false);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const meRes = await cmsApi<{ id: string; email: string; name: string; role: string }>('/auth/me');
|
|
54
|
-
if (meRes.data) {
|
|
55
|
-
setSession({ user: meRes.data });
|
|
56
|
-
}
|
|
57
|
-
setLoading(false);
|
|
58
|
-
}
|
|
59
|
-
checkAuth();
|
|
60
|
-
}, []);
|
|
27
|
+
${STATUS_EFFECT_SOURCE}
|
|
61
28
|
|
|
62
29
|
const handleLogin = async (email: string, password: string, captchaToken?: string) => {
|
|
63
30
|
const res = await cmsApi<{
|
|
@@ -104,8 +71,9 @@ export default function LoginPage() {
|
|
|
104
71
|
|
|
105
72
|
if (loading) {
|
|
106
73
|
return (
|
|
107
|
-
<div className="prenta-admin" style={{ minHeight: '100vh', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
|
74
|
+
<div className="prenta-admin" style={{ minHeight: '100vh', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center' }}>
|
|
108
75
|
<div style={{ width: 24, height: 24, border: '3px solid #e5e7eb', borderTopColor: '#2563eb', borderRadius: '50%', animation: 'spin 1s linear infinite' }} />
|
|
76
|
+
${STATUS_BUSY_HINT_SOURCE}
|
|
109
77
|
<style>{\`@keyframes spin { to { transform: rotate(360deg) } }\`}</style>
|
|
110
78
|
</div>
|
|
111
79
|
);
|
|
@@ -115,7 +83,7 @@ export default function LoginPage() {
|
|
|
115
83
|
return (
|
|
116
84
|
<div className="prenta-admin" style={{ minHeight: '100vh', display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 24 }}>
|
|
117
85
|
<div style={{ maxWidth: 520, width: '100%', border: '1px solid #e5e7eb', borderRadius: 12, padding: '28px 32px', background: '#fff', color: '#111827' }}>
|
|
118
|
-
<h1 style={{ fontSize: '1.25rem', fontWeight: 500, margin: '0 0 8px' }}>
|
|
86
|
+
<h1 style={{ fontSize: '1.25rem', fontWeight: 500, margin: '0 0 8px' }}>{statusTitle}</h1>
|
|
119
87
|
<p style={{ margin: 0, color: '#6b7280', lineHeight: 1.5 }}>{statusError}</p>
|
|
120
88
|
</div>
|
|
121
89
|
</div>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login-page.ts.template.js","sourceRoot":"","sources":["../../src/templates/login-page.ts.template.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"login-page.ts.template.js","sourceRoot":"","sources":["../../src/templates/login-page.ts.template.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,2BAA2B,CAAA;AASlC;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAyB;IACzD,OAAO;;;;;;;EAOP,mBAAmB;;;;;;;;;;;EAWnB,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiDpB,uBAAuB;;;;;;;;;;;;;;;;;;;;;;oBAsBL,OAAO,CAAC,SAAS;qBAChB,OAAO,CAAC,SAAS;;;;;;;;;;CAUrC,CAAA;AACD,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The first-load status check shared by the generated admin page and the
|
|
3
|
+
* generated login page. Both pages are written into the project and owned by
|
|
4
|
+
* it, so the code is emitted as source rather than imported; keeping it in one
|
|
5
|
+
* place here stops the two pages drifting apart.
|
|
6
|
+
*
|
|
7
|
+
* `STATUS_CHECK_SOURCE` is a module-level function. It takes `cmsApi` as an
|
|
8
|
+
* argument, so the test can run the emitted source against a fake.
|
|
9
|
+
* `STATUS_EFFECT_SOURCE` is the body of the page's `useEffect`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const STATUS_CHECK_SOURCE: string;
|
|
12
|
+
/** Delays between retries while rate limited: 4 + 8 + 12 + 16 + 20 = 60s, one limiter window. */
|
|
13
|
+
export declare const STATUS_EFFECT_SOURCE: string;
|
|
14
|
+
/**
|
|
15
|
+
* Shown under the spinner while the page waits out a rate limit. The element
|
|
16
|
+
* is always mounted and empty until then: a live region only announces a
|
|
17
|
+
* change to text inside it, so one that appeared together with its text would
|
|
18
|
+
* leave a screen-reader user on a silent spinner for up to a minute.
|
|
19
|
+
*/
|
|
20
|
+
export declare const STATUS_BUSY_HINT_SOURCE = " <p role=\"status\" aria-live=\"polite\" style={{ margin: '16px 0 0', minHeight: 20, color: '#6b7280', fontSize: 14 }}>{busy ? 'The CMS is busy. Retrying\u2026' : ''}</p>";
|
|
21
|
+
//# sourceMappingURL=status-check.snippet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status-check.snippet.d.ts","sourceRoot":"","sources":["../../src/templates/status-check.snippet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,eAAO,MAAM,mBAAmB,QA2EpB,CAAA;AAEZ,iGAAiG;AACjG,eAAO,MAAM,oBAAoB,QA4CrB,CAAA;AAEZ;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,sLAC4I,CAAA"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The first-load status check shared by the generated admin page and the
|
|
3
|
+
* generated login page. Both pages are written into the project and owned by
|
|
4
|
+
* it, so the code is emitted as source rather than imported; keeping it in one
|
|
5
|
+
* place here stops the two pages drifting apart.
|
|
6
|
+
*
|
|
7
|
+
* `STATUS_CHECK_SOURCE` is a module-level function. It takes `cmsApi` as an
|
|
8
|
+
* argument, so the test can run the emitted source against a fake.
|
|
9
|
+
* `STATUS_EFFECT_SOURCE` is the body of the page's `useEffect`.
|
|
10
|
+
*/
|
|
11
|
+
export const STATUS_CHECK_SOURCE = [
|
|
12
|
+
'type StatusResult =',
|
|
13
|
+
" | { kind: 'ready'; setupRequired: boolean; user?: any; captcha?: CaptchaConfig }",
|
|
14
|
+
" | { kind: 'busy'; captcha?: CaptchaConfig }",
|
|
15
|
+
" | { kind: 'error'; title: string; message: string; captcha?: CaptchaConfig };",
|
|
16
|
+
'',
|
|
17
|
+
'const SETUP_TITLE = "Setup can\'t continue yet";',
|
|
18
|
+
'',
|
|
19
|
+
'/**',
|
|
20
|
+
' * Ask the CMS whether it is set up and who is signed in.',
|
|
21
|
+
' *',
|
|
22
|
+
" * A 429 is reported as 'busy', not as a setup failure: the backend is up and",
|
|
23
|
+
' * this network is over its request budget. The one case where waiting cannot',
|
|
24
|
+
' * help is a production deploy whose rate limiter has no store, which refuses',
|
|
25
|
+
' * every request; /health is exempt from the limit and says so.',
|
|
26
|
+
' */',
|
|
27
|
+
'async function loadStatus(',
|
|
28
|
+
' api: typeof cmsApi,',
|
|
29
|
+
' isProduction: boolean,',
|
|
30
|
+
'): Promise<StatusResult> {',
|
|
31
|
+
' const [setupRes, captchaRes] = await Promise.all([',
|
|
32
|
+
" api<{ setupRequired: boolean; migrationsRequired?: boolean }>('/setup/status'),",
|
|
33
|
+
" api<{ provider: string; siteKey: string | null }>('/captcha/config?for=login'),",
|
|
34
|
+
' ]);',
|
|
35
|
+
' const captcha = captchaRes.data ? (captchaRes.data as CaptchaConfig) : undefined;',
|
|
36
|
+
'',
|
|
37
|
+
' async function busy(): Promise<StatusResult> {',
|
|
38
|
+
' if (isProduction) {',
|
|
39
|
+
" const health = await api<{ rateLimitBackendReady?: boolean }>('/health');",
|
|
40
|
+
' if (health.data?.rateLimitBackendReady === false) {',
|
|
41
|
+
' return {',
|
|
42
|
+
" kind: 'error',",
|
|
43
|
+
" title: 'Rate limiter not configured',",
|
|
44
|
+
' message:',
|
|
45
|
+
" 'In production the CMS refuses requests until its rate limiter has a store. Set UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN (or KV_REST_API_URL and KV_REST_API_TOKEN), then redeploy.',",
|
|
46
|
+
' captcha,',
|
|
47
|
+
' };',
|
|
48
|
+
' }',
|
|
49
|
+
' }',
|
|
50
|
+
" return { kind: 'busy', captcha };",
|
|
51
|
+
' }',
|
|
52
|
+
'',
|
|
53
|
+
' // Database is reachable but has no Prenta CMS tables yet — tell the',
|
|
54
|
+
' // operator to run migrations instead of dropping them on the login screen.',
|
|
55
|
+
' if (setupRes.data?.migrationsRequired) {',
|
|
56
|
+
' return {',
|
|
57
|
+
" kind: 'error',",
|
|
58
|
+
' title: SETUP_TITLE,',
|
|
59
|
+
' message:',
|
|
60
|
+
" 'Your database has no Prenta CMS tables yet. Run `npx prisma migrate deploy` against your database, then reload this page.',",
|
|
61
|
+
' captcha,',
|
|
62
|
+
' };',
|
|
63
|
+
' }',
|
|
64
|
+
'',
|
|
65
|
+
' if (setupRes.status === 429) return busy();',
|
|
66
|
+
'',
|
|
67
|
+
' // The status check itself failed (e.g. the database is unreachable).',
|
|
68
|
+
' if (setupRes.error) {',
|
|
69
|
+
' return {',
|
|
70
|
+
" kind: 'error',",
|
|
71
|
+
' title: SETUP_TITLE,',
|
|
72
|
+
" message: 'Could not reach the CMS backend: ' + setupRes.error,",
|
|
73
|
+
' captcha,',
|
|
74
|
+
' };',
|
|
75
|
+
' }',
|
|
76
|
+
'',
|
|
77
|
+
" if (setupRes.data?.setupRequired) return { kind: 'ready', setupRequired: true, captcha };",
|
|
78
|
+
'',
|
|
79
|
+
" const meRes = await api<{ id: string; email: string; name: string; role: string }>('/auth/me');",
|
|
80
|
+
' // Sign-in state shares a budget with saving, so it can be limited when the',
|
|
81
|
+
' // status check was not. Treating its 429 as "signed out" would show the',
|
|
82
|
+
' // login form to someone who is signed in.',
|
|
83
|
+
' if (meRes.status === 429) return busy();',
|
|
84
|
+
" return { kind: 'ready', setupRequired: false, user: meRes.data ?? undefined, captcha };",
|
|
85
|
+
'}',
|
|
86
|
+
].join('\n');
|
|
87
|
+
/** Delays between retries while rate limited: 4 + 8 + 12 + 16 + 20 = 60s, one limiter window. */
|
|
88
|
+
export const STATUS_EFFECT_SOURCE = [
|
|
89
|
+
' useEffect(() => {',
|
|
90
|
+
' let cancelled = false;',
|
|
91
|
+
' let retryTimer: ReturnType<typeof setTimeout> | undefined;',
|
|
92
|
+
'',
|
|
93
|
+
' async function checkAuth(attempt = 0) {',
|
|
94
|
+
" const result = await loadStatus(cmsApi, process.env.NODE_ENV === 'production');",
|
|
95
|
+
' // The page unmounted while the request was in flight (React runs effects',
|
|
96
|
+
' // twice in development): do not set state or schedule another retry.',
|
|
97
|
+
' if (cancelled) return;',
|
|
98
|
+
' if (result.captcha) setCaptchaConfig(result.captcha);',
|
|
99
|
+
'',
|
|
100
|
+
" if (result.kind === 'busy') {",
|
|
101
|
+
' // Retries span one 60-second limiter window, so a limit hit at the',
|
|
102
|
+
' // start of a window has reset by the last attempt.',
|
|
103
|
+
' if (attempt < 5) {',
|
|
104
|
+
' setBusy(true);',
|
|
105
|
+
' retryTimer = setTimeout(() => checkAuth(attempt + 1), 4000 * (attempt + 1));',
|
|
106
|
+
' return;',
|
|
107
|
+
' }',
|
|
108
|
+
" setStatusTitle('Too many requests');",
|
|
109
|
+
" setStatusError('This network has sent the CMS too many requests. Wait a minute, then reload this page.');",
|
|
110
|
+
' setLoading(false);',
|
|
111
|
+
' return;',
|
|
112
|
+
' }',
|
|
113
|
+
'',
|
|
114
|
+
" if (result.kind === 'error') {",
|
|
115
|
+
' setStatusTitle(result.title);',
|
|
116
|
+
' setStatusError(result.message);',
|
|
117
|
+
' setLoading(false);',
|
|
118
|
+
' return;',
|
|
119
|
+
' }',
|
|
120
|
+
'',
|
|
121
|
+
' if (result.setupRequired) setSetupRequired(true);',
|
|
122
|
+
' else if (result.user) setSession({ user: result.user });',
|
|
123
|
+
' setLoading(false);',
|
|
124
|
+
' }',
|
|
125
|
+
'',
|
|
126
|
+
' checkAuth();',
|
|
127
|
+
' return () => {',
|
|
128
|
+
' cancelled = true;',
|
|
129
|
+
' if (retryTimer) clearTimeout(retryTimer);',
|
|
130
|
+
' };',
|
|
131
|
+
' }, []);',
|
|
132
|
+
].join('\n');
|
|
133
|
+
/**
|
|
134
|
+
* Shown under the spinner while the page waits out a rate limit. The element
|
|
135
|
+
* is always mounted and empty until then: a live region only announces a
|
|
136
|
+
* change to text inside it, so one that appeared together with its text would
|
|
137
|
+
* leave a screen-reader user on a silent spinner for up to a minute.
|
|
138
|
+
*/
|
|
139
|
+
export const STATUS_BUSY_HINT_SOURCE = " <p role=\"status\" aria-live=\"polite\" style={{ margin: '16px 0 0', minHeight: 20, color: '#6b7280', fontSize: 14 }}>{busy ? 'The CMS is busy. Retrying…' : ''}</p>";
|
|
140
|
+
//# sourceMappingURL=status-check.snippet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status-check.snippet.js","sourceRoot":"","sources":["../../src/templates/status-check.snippet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,qBAAqB;IACrB,oFAAoF;IACpF,+CAA+C;IAC/C,iFAAiF;IACjF,EAAE;IACF,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