create-stitchkit 0.6.16 → 0.6.18
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 +24 -0
- package/examples/repository/packages/frontend/src/app/[locale]/page.tsx +2 -0
- package/examples/repository/packages/frontend/src/app/[locale]/starter-page.tsx +12 -8
- package/examples/repository/project.json +9 -0
- package/package.json +2 -2
- package/template/README.md +7 -0
- package/template/_env.example +5 -0
- package/template/bun.lock +2 -2
- package/template/docs/ADMIN_MOCK.md +38 -0
- package/template/package.json +2 -1
- package/template/packages/backend/src/index.ts +2 -1
- package/template/packages/backend/src/surface.ts +7 -6
- package/template/packages/backend/src/trusted-origins.test.ts +40 -0
- package/template/packages/backend/src/trusted-origins.ts +21 -0
- package/template/packages/config/src/variables.ts +16 -1
- package/template/packages/frontend/next.config.ts +10 -1
- package/template/packages/frontend/src/app/[locale]/admin/[[...section]]/page.dev.tsx +21 -0
- package/template/packages/frontend/src/app/[locale]/page.tsx +2 -1
- package/template/packages/frontend/src/app/[locale]/starter-page.tsx +12 -8
- package/template/packages/frontend/src/app/api/[...path]/route.ts +2 -37
- package/template/packages/frontend/src/app/sitemap.ts +4 -1
- package/template/packages/frontend/src/env.ts +11 -1
- package/template/packages/frontend/src/features/admin/admin-data.ts +13 -0
- package/template/packages/frontend/src/features/admin/admin-sections.ts +78 -0
- package/template/packages/frontend/src/features/admin/admin-workspace.test.tsx +59 -0
- package/template/packages/frontend/src/features/admin/admin-workspace.tsx +127 -0
- package/template/packages/frontend/src/features/admin/fixture/admin-fixture.ts +35 -0
- package/template/packages/frontend/src/lib/api-proxy.test.ts +131 -0
- package/template/packages/frontend/src/lib/api-proxy.ts +89 -0
- package/template/packages/frontend/src/proxy.ts +12 -1
- package/template/project.json +9 -0
- package/template/scripts/acceptance-local.ts +8 -1
- package/template/scripts/fixture-boundary.test.ts +34 -0
- package/template/scripts/fixture-boundary.ts +25 -0
- package/template/scripts/service-surfaces-closed.ts +13 -0
- package/template/scripts/web-surface-smoke.ts +33 -0
package/CHANGELOG.md
CHANGED
|
@@ -12,6 +12,30 @@ step is overwritten by the next release.
|
|
|
12
12
|
|
|
13
13
|
## [Unreleased]
|
|
14
14
|
|
|
15
|
+
## [0.6.18] - 2026-11-02
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
|
|
19
|
+
- `/en/admin`: an admin panel on fixture for development, with sections, roles, a table and a dialog, and no
|
|
20
|
+
database. A production build drops it and its rows, which `bun run acceptance:local` proves on the built
|
|
21
|
+
files. [`docs/ADMIN_MOCK.md`](template/docs/ADMIN_MOCK.md) holds its addresses and the way off fixture.
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- The web role's `/api` forwarding keeps a session and a download: `cookie`, `origin`, each `set-cookie`,
|
|
26
|
+
`content-disposition`, `content-length` and `location` now pass.
|
|
27
|
+
- The component catalogue and `/openapi.json` answer 404 in production unless the deployment sets
|
|
28
|
+
`SERVICE_SURFACES=open`. `bun run acceptance:local` proves both answers on one artifact.
|
|
29
|
+
|
|
30
|
+
## [0.6.17] - 2026-10-20
|
|
31
|
+
|
|
32
|
+
### Changed
|
|
33
|
+
|
|
34
|
+
- Generated projects track Stitchkit `^0.111.3`; the template lockfile resolves 0.111.3. The
|
|
35
|
+
template uses none of the exports the 0.109.0, 0.110.0 and 0.111.0 breaking items change
|
|
36
|
+
(`runCli`, the lifecycle termination schemas, `parseBody`, `mountOAuthProvider`), so its code is
|
|
37
|
+
unchanged.
|
|
38
|
+
|
|
15
39
|
## [0.6.16] - 2026-10-06
|
|
16
40
|
|
|
17
41
|
### Changed
|
|
@@ -2,6 +2,7 @@ import { appDeclaration } from '@app/config/declaration';
|
|
|
2
2
|
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
|
3
3
|
import type { Metadata } from 'next';
|
|
4
4
|
import { getTranslations } from 'next-intl/server';
|
|
5
|
+
import { catalogueIsOpen } from '@/env';
|
|
5
6
|
import { LocaleSchema } from '@/i18n/locales';
|
|
6
7
|
import { publicRealtimeOrigin } from '@/lib/api/place';
|
|
7
8
|
import { useRepository } from '@/lib/api/queries';
|
|
@@ -39,6 +40,7 @@ export default async function Page({ params }: { params: Promise<{ locale: strin
|
|
|
39
40
|
applicationDescription={appDeclaration.identity.description[appLocale]}
|
|
40
41
|
heroTitle={t('heroTitle')}
|
|
41
42
|
catalogueLabel={t('ui')}
|
|
43
|
+
catalogueOpen={catalogueIsOpen()}
|
|
42
44
|
locale={appLocale}
|
|
43
45
|
realtimeOrigin={publicRealtimeOrigin()}
|
|
44
46
|
/>
|
|
@@ -16,6 +16,7 @@ interface StarterPageProps {
|
|
|
16
16
|
applicationDescription: string;
|
|
17
17
|
heroTitle: string;
|
|
18
18
|
catalogueLabel: string;
|
|
19
|
+
catalogueOpen: boolean;
|
|
19
20
|
realtimeOrigin?: string;
|
|
20
21
|
locale: AppLocale;
|
|
21
22
|
}
|
|
@@ -64,6 +65,7 @@ export async function StarterPage({
|
|
|
64
65
|
applicationDescription,
|
|
65
66
|
heroTitle,
|
|
66
67
|
catalogueLabel,
|
|
68
|
+
catalogueOpen,
|
|
67
69
|
realtimeOrigin,
|
|
68
70
|
locale,
|
|
69
71
|
}: StarterPageProps) {
|
|
@@ -90,14 +92,16 @@ export async function StarterPage({
|
|
|
90
92
|
<div className='flex items-center gap-2'>
|
|
91
93
|
<LanguageSwitcher />
|
|
92
94
|
<ThemeToggle />
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
95
|
+
{catalogueOpen ? (
|
|
96
|
+
<Link
|
|
97
|
+
aria-label={catalogueLabel}
|
|
98
|
+
className={cn(buttonVariants({ variant: 'outline', size: 'sm' }))}
|
|
99
|
+
href='/ui'
|
|
100
|
+
>
|
|
101
|
+
<span className='hidden sm:inline'>{catalogueLabel}</span>
|
|
102
|
+
<IconArrowUpRight />
|
|
103
|
+
</Link>
|
|
104
|
+
) : null}
|
|
101
105
|
</div>
|
|
102
106
|
</header>
|
|
103
107
|
|
|
@@ -184,6 +184,15 @@
|
|
|
184
184
|
"shape": "url",
|
|
185
185
|
"required": false
|
|
186
186
|
},
|
|
187
|
+
{
|
|
188
|
+
"name": "SERVICE_SURFACES",
|
|
189
|
+
"shape": "enum",
|
|
190
|
+
"required": false,
|
|
191
|
+
"members": [
|
|
192
|
+
"open",
|
|
193
|
+
"closed"
|
|
194
|
+
]
|
|
195
|
+
},
|
|
187
196
|
{
|
|
188
197
|
"name": "TRUSTED_HOSTS",
|
|
189
198
|
"shape": "string",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-stitchkit",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.18",
|
|
4
4
|
"description": "Create a production-shaped Stitchkit application",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Max Listov <maxlistov@gmail.com>",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"@types/react": "^19.3.0",
|
|
85
85
|
"ai": "^7.0.111",
|
|
86
86
|
"react": "^19.3.0",
|
|
87
|
-
"stitchkit": "0.
|
|
87
|
+
"stitchkit": "0.117.0",
|
|
88
88
|
"typescript": "^7.0.2"
|
|
89
89
|
},
|
|
90
90
|
"engines": {
|
package/template/README.md
CHANGED
|
@@ -45,6 +45,8 @@ database migrations you add and launches:
|
|
|
45
45
|
|
|
46
46
|
- Web: <http://localhost:3210>
|
|
47
47
|
- UI catalogue: <http://localhost:3210/en/ui>
|
|
48
|
+
- Admin panel on fixture, development only: <http://localhost:3210/en/admin>
|
|
49
|
+
([how to take it off fixture](docs/ADMIN_MOCK.md))
|
|
48
50
|
- API: <http://localhost:3211>
|
|
49
51
|
- OpenAPI: <http://localhost:3211/openapi.json>
|
|
50
52
|
- MCP: <http://localhost:3211/mcp>
|
|
@@ -84,6 +86,9 @@ server-delivered address, a client built on first use (hence the parentheses),
|
|
|
84
86
|
an ordering requirement relative to `<Providers>`, and `CORS_ORIGIN` on the API
|
|
85
87
|
role.
|
|
86
88
|
|
|
89
|
+
In production the catalogue and `/openapi.json` answer 404 unless the deployment
|
|
90
|
+
sets `SERVICE_SURFACES=open`; `bun run acceptance:local` proves both answers.
|
|
91
|
+
|
|
87
92
|
The `/en/ui` catalogue is isolated under
|
|
88
93
|
`packages/frontend/src/app/[locale]/ui` and can be removed as one directory;
|
|
89
94
|
reusable primitives remain in `components/ui`. It renders the complete
|
|
@@ -131,6 +136,8 @@ runtime:smoke` / `bun run e2e` directly. `runtime:smoke` asks the web role to
|
|
|
131
136
|
answer as two of the addresses `PUBLIC_WEB_HOSTS` claims, to prove one artifact
|
|
132
137
|
serves many; a deployment claiming fewer than two addresses besides the one
|
|
133
138
|
being dialled is told exactly what to add rather than failing on a refused host.
|
|
139
|
+
Both read the catalogue or `/openapi.json`, so that deployment needs
|
|
140
|
+
`SERVICE_SURFACES=open` while they run.
|
|
134
141
|
|
|
135
142
|
## Requirements
|
|
136
143
|
|
package/template/_env.example
CHANGED
|
@@ -23,6 +23,11 @@ SMOKE_WEB_ORIGIN=http://127.0.0.1:3210
|
|
|
23
23
|
PUBLIC_WEB_HOSTS=127.0.0.1:3210
|
|
24
24
|
LOG_FORMAT=pretty
|
|
25
25
|
|
|
26
|
+
# `/en/ui` and `/openapi.json` answer 404 in production and stay open otherwise.
|
|
27
|
+
# `open` keeps them on a production deployment that wants them; leave it unset
|
|
28
|
+
# anywhere else.
|
|
29
|
+
# SERVICE_SURFACES=open
|
|
30
|
+
|
|
26
31
|
# The web role reaches the API role internally, and forwards the browser's
|
|
27
32
|
# same-origin `/api/…` calls to it (packages/frontend/src/app/api/[...path]).
|
|
28
33
|
INTERNAL_API_URL=http://127.0.0.1:3211
|
package/template/bun.lock
CHANGED
|
@@ -145,7 +145,7 @@
|
|
|
145
145
|
"zod": "4.6.5",
|
|
146
146
|
},
|
|
147
147
|
"catalog": {
|
|
148
|
-
"stitchkit": "^0.
|
|
148
|
+
"stitchkit": "^0.111.3",
|
|
149
149
|
},
|
|
150
150
|
"packages": {
|
|
151
151
|
"@ai-sdk/gateway": ["@ai-sdk/gateway@4.0.89", "", { "dependencies": { "@ai-sdk/provider": "4.0.17", "@ai-sdk/provider-utils": "5.0.45", "@vercel/oidc": "3.2.0" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-n0Q88UUASYQBGK3Ogs9pCe8h3ZXeTHFSuGOLBJAyH73MVGNKUv9w8EJX2f340WUF3eDWWOV305gO7YBpSCPblA=="],
|
|
@@ -1128,7 +1128,7 @@
|
|
|
1128
1128
|
|
|
1129
1129
|
"std-env": ["std-env@3.10.0", "", {}, "sha512-5GS12FdOZNliM5mAOxFRg7Ir0pWz8MdpYm6AY6VPkGpbA7ZzmbzNcBJQ0GPvvyWgcY7QAhCgf9Uy89I03faLkg=="],
|
|
1130
1130
|
|
|
1131
|
-
"stitchkit": ["stitchkit@0.
|
|
1131
|
+
"stitchkit": ["stitchkit@0.111.3", "", { "dependencies": { "ky": "^2.1.0" }, "peerDependencies": { "@modelcontextprotocol/ext-apps": "^1.7.2 || ^2.0.0", "@modelcontextprotocol/server": "^2.0.0", "@openrouter/ai-sdk-provider": "^3.1.0", "@opentelemetry/api": "^1.9.0", "@socket.io/bun-engine": "^0.1.2", "@socket.io/component-emitter": "^3.1.2", "@tanstack/react-query": ">=5", "@types/bun": "^1.4.2", "ai": "^7.0.107", "google-auth-library": "^11.1.0", "grammy": "^1.46.0", "maxmind": "^5.0.7", "react": ">=18", "react-query-kit": "^3.3.3", "socket.io": "^4.8.3", "socket.io-client": "^4.8.3", "srvx": "^0.12.5 || ^1.0.5", "zod": "^4.6.5" }, "optionalPeers": ["@modelcontextprotocol/ext-apps", "@modelcontextprotocol/server", "@openrouter/ai-sdk-provider", "@opentelemetry/api", "@socket.io/bun-engine", "@socket.io/component-emitter", "@tanstack/react-query", "@types/bun", "ai", "google-auth-library", "grammy", "maxmind", "react", "react-query-kit", "socket.io", "socket.io-client", "srvx"], "bin": { "stitchkit": "dist/entrypoints/bin/upgrade-cli.js" } }, "sha512-X9R45Ksljavt9wLl97Xsy1VAkOyuN4HW+ki7Kb1zZym8GI/TnbAsqlIBpP0plAGMCzNT3ywWdBAYOsrivCge0g=="],
|
|
1132
1132
|
|
|
1133
1133
|
"stringify-entities": ["stringify-entities@4.0.4", "", { "dependencies": { "character-entities-html4": "^2.0.0", "character-entities-legacy": "^3.0.0" } }, "sha512-IwfBptatlO+QCJUo19AqvrPNqlVMpW9YEL2LIVY+Rpv2qsjCGxaDLNRgeGsQWJhfItebuJhsGSLjaBbNSQ+ieg=="],
|
|
1134
1134
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# The admin panel on fixture
|
|
2
|
+
|
|
3
|
+
`/en/admin` shows the shape of a future admin panel before any of its API exists: sections, roles, tables
|
|
4
|
+
and dialogs, on invented rows and with no database. A customer sees the system and answers questions
|
|
5
|
+
about it before the first migration.
|
|
6
|
+
|
|
7
|
+
It exists in development only. Its route is `app/[locale]/admin/[[...section]]/page.dev.tsx`, and `.dev.tsx`
|
|
8
|
+
is a page extension of the development server alone (`next.config.ts`), so a production build has no such
|
|
9
|
+
route: the address answers 404 and the rows are not in the artifact.
|
|
10
|
+
`bun run acceptance:local` proves that on the built files (`scripts/fixture-boundary.ts`).
|
|
11
|
+
|
|
12
|
+
## Addresses
|
|
13
|
+
|
|
14
|
+
| Address | Section | Read | Write | Status |
|
|
15
|
+
|---|---|---|---|---|
|
|
16
|
+
| `/admin` | Records | `records.read` | `records.write` | `mock` |
|
|
17
|
+
| `/admin/people` | People | `people.read` | `people.write` | `mock` |
|
|
18
|
+
|
|
19
|
+
`features/admin/admin-sections.ts` is the source of this table. Keep them in step.
|
|
20
|
+
|
|
21
|
+
## Changing it
|
|
22
|
+
|
|
23
|
+
Rename the sections and the columns of `AdminRow` to your domain, in `admin-sections.ts`, `admin-data.ts`
|
|
24
|
+
and `fixture/admin-fixture.ts`. `adminPermissions` must decide every role against every operation, and the
|
|
25
|
+
role buttons in the sidebar switch between them for a demonstration only: they prove nothing to a server.
|
|
26
|
+
|
|
27
|
+
## Taking a section off fixture
|
|
28
|
+
|
|
29
|
+
1. Build the vertical slice by [`ADDING_A_FEATURE.md`](ADDING_A_FEATURE.md), answering `AdminRow`.
|
|
30
|
+
2. Enforce the same operation on the server, with `adminPermissions` moved to `packages/shared` so both sides
|
|
31
|
+
read one matrix.
|
|
32
|
+
3. Set the section's `status` to `live`, supply its rows from the API, and rename the route to `page.tsx`, which
|
|
33
|
+
production builds. Keep a section that is still `mock` behind a page of its own in `page.dev.tsx`.
|
|
34
|
+
4. Delete its rows from the fixture.
|
|
35
|
+
|
|
36
|
+
When no section is `mock`, delete `features/admin/fixture/`, `scripts/fixture-boundary.ts` and its acceptance
|
|
37
|
+
step. If the panel is not wanted at all, delete `features/admin` and
|
|
38
|
+
`app/[locale]/admin` as two directories, with the same script and step.
|
package/template/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"packages/*"
|
|
8
8
|
],
|
|
9
9
|
"catalog": {
|
|
10
|
-
"stitchkit": "^0.
|
|
10
|
+
"stitchkit": "^0.111.3"
|
|
11
11
|
},
|
|
12
12
|
"overrides": {
|
|
13
13
|
"@playwright/test": "1.63.0",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"cli": "bun packages/backend/src/cli.ts",
|
|
34
34
|
"tools": "bun packages/backend/src/tools.ts",
|
|
35
35
|
"runtime:smoke": "bun scripts/runtime-smoke.ts",
|
|
36
|
+
"surfaces:closed": "bun scripts/service-surfaces-closed.ts",
|
|
36
37
|
"surface:snapshot": "bun scripts/surface-snapshot.ts",
|
|
37
38
|
"e2e": "playwright test",
|
|
38
39
|
"acceptance:local": "bun scripts/acceptance-local.ts",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { env } from '@app/config';
|
|
2
2
|
import { apiRole, appDeclaration } from '@app/config/declaration';
|
|
3
|
+
import { serviceSurfacesAreOpen } from '@app/config/variables';
|
|
3
4
|
import { wrapInRequestContext } from 'stitchkit/observability';
|
|
4
5
|
import {
|
|
5
6
|
bindProcessSignals,
|
|
@@ -44,7 +45,7 @@ async function main(): Promise<void> {
|
|
|
44
45
|
logging: { format: env.LOG_FORMAT },
|
|
45
46
|
socket,
|
|
46
47
|
rawRoutes: [
|
|
47
|
-
openApiRoute('/openapi.json', openApi),
|
|
48
|
+
...(serviceSurfacesAreOpen(env) ? [openApiRoute('/openapi.json', openApi)] : []),
|
|
48
49
|
createMcpHttpRoute({ path: '/mcp', handler: mcp }),
|
|
49
50
|
{
|
|
50
51
|
method: 'GET',
|
|
@@ -4,6 +4,7 @@ import { type BoardRuntime, openBoard } from './lib/board';
|
|
|
4
4
|
import { bindLive } from './lib/live';
|
|
5
5
|
import { createBoardService } from './transport/board-service';
|
|
6
6
|
import { createSystemService } from './transport/system-service';
|
|
7
|
+
import { trustedBrowserAuthorities } from './trusted-origins';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* The fence this deployment answers behind, or nothing.
|
|
@@ -13,15 +14,15 @@ import { createSystemService } from './transport/system-service';
|
|
|
13
14
|
* Unset means no fence, which is honest for a checkout on a laptop and wrong for
|
|
14
15
|
* anything a network can reach.
|
|
15
16
|
*
|
|
16
|
-
* The browser
|
|
17
|
-
* questions — CORS says what a page may *read*, the
|
|
18
|
-
* this server agreed to *answer on* — but a deployment
|
|
19
|
-
* browser has named it once, and asking twice is asking for two
|
|
20
|
-
* disagree.
|
|
17
|
+
* The browser origins are the ones already declared, for CORS and for the web
|
|
18
|
+
* role. They answer different questions — CORS says what a page may *read*, the
|
|
19
|
+
* fence says which authority this server agreed to *answer on* — but a deployment
|
|
20
|
+
* that names its browser has named it once, and asking twice is asking for two
|
|
21
|
+
* answers that disagree.
|
|
21
22
|
*/
|
|
22
23
|
function createFence(): TrustFence | undefined {
|
|
23
24
|
if (!env.TRUSTED_HOSTS) return undefined;
|
|
24
|
-
const browserOrigin =
|
|
25
|
+
const browserOrigin = trustedBrowserAuthorities(env);
|
|
25
26
|
return createTrustFence({
|
|
26
27
|
trustedHosts: env.TRUSTED_HOSTS.split(',').map((entry) => entry.trim()),
|
|
27
28
|
...(browserOrigin.length > 0 && { trustedOrigins: browserOrigin }),
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { createTrustFence } from 'stitchkit/server';
|
|
3
|
+
import { trustedBrowserAuthorities } from './trusted-origins';
|
|
4
|
+
|
|
5
|
+
function proxied(origin: string): Request {
|
|
6
|
+
return new Request('http://127.0.0.1:3211/api/board', {
|
|
7
|
+
method: 'POST',
|
|
8
|
+
headers: { host: '127.0.0.1:3211', origin },
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
describe('a fenced API role behind the web role', () => {
|
|
13
|
+
const fence = createTrustFence({
|
|
14
|
+
trustedHosts: ['127.0.0.1:3211'],
|
|
15
|
+
trustedOrigins: trustedBrowserAuthorities({
|
|
16
|
+
PUBLIC_WEB_HOSTS: 'app.example, www.app.example:8443',
|
|
17
|
+
}),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('admits a browser on an address the deployment claims', () => {
|
|
21
|
+
expect(fence.check(proxied('https://app.example'), 'http')).toBeUndefined();
|
|
22
|
+
expect(fence.check(proxied('https://www.app.example:8443'), 'http')).toBeUndefined();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('refuses a page anywhere else', () => {
|
|
26
|
+
expect(fence.check(proxied('https://evil.example'), 'http')?.reason).toBe(
|
|
27
|
+
'origin-mismatch',
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('names each declared host once', () => {
|
|
32
|
+
expect(
|
|
33
|
+
trustedBrowserAuthorities({
|
|
34
|
+
CORS_ORIGIN: 'https://app.example',
|
|
35
|
+
PUBLIC_WEB_ORIGIN: 'https://app.example',
|
|
36
|
+
PUBLIC_WEB_HOSTS: 'app.example,other.example',
|
|
37
|
+
}),
|
|
38
|
+
).toEqual(['app.example', 'other.example']);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The browser origins a fenced API role admits, all of them already declared.
|
|
3
|
+
*
|
|
4
|
+
* A browser on the web role's own address reaches this role through the `/api`
|
|
5
|
+
* forwarding, so its request arrives with that address as `Origin` and the
|
|
6
|
+
* internal one as `Host`. Those disagree by construction, and only the public
|
|
7
|
+
* hosts the deployment claims can tell it from a forged page.
|
|
8
|
+
*/
|
|
9
|
+
export function trustedBrowserAuthorities(env: {
|
|
10
|
+
CORS_ORIGIN?: string | undefined;
|
|
11
|
+
PUBLIC_WEB_ORIGIN?: string | undefined;
|
|
12
|
+
PUBLIC_WEB_HOSTS?: string | undefined;
|
|
13
|
+
}): string[] {
|
|
14
|
+
const authorities = [
|
|
15
|
+
...[env.CORS_ORIGIN, env.PUBLIC_WEB_ORIGIN].flatMap((origin) =>
|
|
16
|
+
origin ? [new URL(origin).host] : [],
|
|
17
|
+
),
|
|
18
|
+
...(env.PUBLIC_WEB_HOSTS ?? '').split(',').map((host) => host.trim()),
|
|
19
|
+
];
|
|
20
|
+
return [...new Set(authorities.filter((host) => host !== ''))];
|
|
21
|
+
}
|
|
@@ -17,8 +17,22 @@ import { featureServerSchema } from './features';
|
|
|
17
17
|
* Defaults, coercion and error messages live here and only here. The
|
|
18
18
|
* declaration carries names and shapes; it deliberately carries no values.
|
|
19
19
|
*/
|
|
20
|
+
/** The one reading of `SERVICE_SURFACES`, for both roles. */
|
|
21
|
+
export function serviceSurfacesAreOpen(env: {
|
|
22
|
+
NODE_ENV?: string | undefined;
|
|
23
|
+
SERVICE_SURFACES?: 'open' | 'closed' | undefined;
|
|
24
|
+
}): boolean {
|
|
25
|
+
return env.SERVICE_SURFACES ? env.SERVICE_SURFACES === 'open' : env.NODE_ENV !== 'production';
|
|
26
|
+
}
|
|
27
|
+
|
|
20
28
|
const baseVariables = {
|
|
21
29
|
NODE_ENV: z.enum(['development', 'test', 'production']).default('development'),
|
|
30
|
+
/**
|
|
31
|
+
* The component catalogue and `/openapi.json`: they describe how this
|
|
32
|
+
* application is built, so production answers 404 for them unless it says
|
|
33
|
+
* `open`, which is what a deployment under acceptance does.
|
|
34
|
+
*/
|
|
35
|
+
SERVICE_SURFACES: z.enum(['open', 'closed']).optional(),
|
|
22
36
|
DATABASE_URL: z.url(),
|
|
23
37
|
// Loopback by default — exposing the app to the network is an explicit
|
|
24
38
|
// opt-in (`BIND_HOST=0.0.0.0`), never something a forgotten edit causes.
|
|
@@ -86,7 +100,8 @@ const baseVariables = {
|
|
|
86
100
|
* and the realtime handshake, which never reaches a lifecycle hook on either
|
|
87
101
|
* runtime. Unset and there is no fence, which is honest for a local checkout
|
|
88
102
|
* and wrong for anything reachable from a network — a fence cannot invent the
|
|
89
|
-
* list of names it should answer to.
|
|
103
|
+
* list of names it should answer to. A browser reaching this role through the
|
|
104
|
+
* web role is admitted by its address in `PUBLIC_WEB_HOSTS` or `PUBLIC_WEB_ORIGIN`.
|
|
90
105
|
*/
|
|
91
106
|
TRUSTED_HOSTS: z.string().min(1).optional(),
|
|
92
107
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import type { NextConfig } from 'next';
|
|
3
|
+
import { PHASE_DEVELOPMENT_SERVER } from 'next/constants';
|
|
3
4
|
import createNextIntlPlugin from 'next-intl/plugin';
|
|
4
5
|
|
|
5
6
|
const config: NextConfig = {
|
|
@@ -16,4 +17,12 @@ const config: NextConfig = {
|
|
|
16
17
|
images: { remotePatterns: [] },
|
|
17
18
|
};
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
/**
|
|
21
|
+
* A `page.dev.tsx` exists for the development server alone, so what it imports
|
|
22
|
+
* is absent from a production build rather than guarded inside it.
|
|
23
|
+
*/
|
|
24
|
+
export default function nextConfig(phase: string): NextConfig {
|
|
25
|
+
const pageExtensions =
|
|
26
|
+
phase === PHASE_DEVELOPMENT_SERVER ? ['dev.tsx', 'tsx', 'ts'] : ['tsx', 'ts'];
|
|
27
|
+
return createNextIntlPlugin()({ ...config, pageExtensions });
|
|
28
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { notFound } from 'next/navigation';
|
|
2
|
+
import { sectionAt } from '@/features/admin/admin-sections';
|
|
3
|
+
import { AdminWorkspace } from '@/features/admin/admin-workspace';
|
|
4
|
+
import { adminFixture } from '@/features/admin/fixture/admin-fixture';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `.dev.tsx` is a page extension of the development server only (`next.config.ts`),
|
|
8
|
+
* so a production build has no such route and nothing here enters its graph.
|
|
9
|
+
* `scripts/fixture-boundary.ts` proves that on the built files. Once a section
|
|
10
|
+
* reads the API, name this file `page.tsx` and drop the fixture import.
|
|
11
|
+
*/
|
|
12
|
+
export default async function AdminPage({
|
|
13
|
+
params,
|
|
14
|
+
}: {
|
|
15
|
+
params: Promise<{ section?: string[] }>;
|
|
16
|
+
}) {
|
|
17
|
+
const { section: segments = [] } = await params;
|
|
18
|
+
const section = segments.length > 1 ? undefined : sectionAt(segments[0]);
|
|
19
|
+
if (!section) notFound();
|
|
20
|
+
return <AdminWorkspace section={section} data={adminFixture} />;
|
|
21
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { appIdentity } from '@app/config/app-identity';
|
|
2
2
|
import type { Metadata } from 'next';
|
|
3
3
|
import { getTranslations } from 'next-intl/server';
|
|
4
|
-
import { env } from '@/env';
|
|
4
|
+
import { catalogueIsOpen, env } from '@/env';
|
|
5
5
|
import { LocaleSchema } from '@/i18n/locales';
|
|
6
6
|
import { createPageMetadata } from '@/lib/seo/metadata';
|
|
7
7
|
import { StarterPage } from './starter-page';
|
|
@@ -28,6 +28,7 @@ export default async function Page({ params }: { params: Promise<{ locale: strin
|
|
|
28
28
|
applicationDescription={appIdentity.description[appLocale]}
|
|
29
29
|
heroTitle={t('heroTitle')}
|
|
30
30
|
catalogueLabel={t('ui')}
|
|
31
|
+
catalogueOpen={catalogueIsOpen()}
|
|
31
32
|
locale={appLocale}
|
|
32
33
|
realtimeOrigin={env.PUBLIC_REALTIME_ORIGIN}
|
|
33
34
|
/>
|
|
@@ -15,6 +15,7 @@ interface StarterPageProps {
|
|
|
15
15
|
applicationDescription: string;
|
|
16
16
|
heroTitle: string;
|
|
17
17
|
catalogueLabel: string;
|
|
18
|
+
catalogueOpen: boolean;
|
|
18
19
|
realtimeOrigin?: string;
|
|
19
20
|
locale: AppLocale;
|
|
20
21
|
}
|
|
@@ -63,6 +64,7 @@ export async function StarterPage({
|
|
|
63
64
|
applicationDescription,
|
|
64
65
|
heroTitle,
|
|
65
66
|
catalogueLabel,
|
|
67
|
+
catalogueOpen,
|
|
66
68
|
realtimeOrigin,
|
|
67
69
|
locale,
|
|
68
70
|
}: StarterPageProps) {
|
|
@@ -89,14 +91,16 @@ export async function StarterPage({
|
|
|
89
91
|
<div className='flex items-center gap-2'>
|
|
90
92
|
<LanguageSwitcher />
|
|
91
93
|
<ThemeToggle />
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
94
|
+
{catalogueOpen ? (
|
|
95
|
+
<Link
|
|
96
|
+
aria-label={catalogueLabel}
|
|
97
|
+
className={cn(buttonVariants({ variant: 'outline', size: 'sm' }))}
|
|
98
|
+
href='/ui'
|
|
99
|
+
>
|
|
100
|
+
<span className='hidden sm:inline'>{catalogueLabel}</span>
|
|
101
|
+
<IconArrowUpRight />
|
|
102
|
+
</Link>
|
|
103
|
+
) : null}
|
|
100
104
|
</div>
|
|
101
105
|
</header>
|
|
102
106
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { env } from '@/env';
|
|
2
|
+
import { forwardToApi } from '@/lib/api-proxy';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* The default shape: the browser talks to its OWN origin, and the web role
|
|
@@ -19,14 +20,6 @@ import { env } from '@/env';
|
|
|
19
20
|
*/
|
|
20
21
|
export const dynamic = 'force-dynamic';
|
|
21
22
|
|
|
22
|
-
const FORWARDED_REQUEST_HEADERS = [
|
|
23
|
-
'accept',
|
|
24
|
-
'accept-language',
|
|
25
|
-
'content-type',
|
|
26
|
-
'authorization',
|
|
27
|
-
];
|
|
28
|
-
const FORWARDED_RESPONSE_HEADERS = ['content-type', 'cache-control', 'etag'];
|
|
29
|
-
|
|
30
23
|
async function forward(request: Request): Promise<Response> {
|
|
31
24
|
const apiUrl = env.INTERNAL_API_URL;
|
|
32
25
|
if (!apiUrl) {
|
|
@@ -36,35 +29,7 @@ async function forward(request: Request): Promise<Response> {
|
|
|
36
29
|
{ status: 503 },
|
|
37
30
|
);
|
|
38
31
|
}
|
|
39
|
-
|
|
40
|
-
// Rebuilt from the incoming pathname rather than from the matched segments,
|
|
41
|
-
// so an encoded segment reaches the API role exactly as it arrived.
|
|
42
|
-
const target = new URL(`${incoming.pathname}${incoming.search}`, apiUrl);
|
|
43
|
-
|
|
44
|
-
const headers = new Headers();
|
|
45
|
-
for (const name of FORWARDED_REQUEST_HEADERS) {
|
|
46
|
-
const value = request.headers.get(name);
|
|
47
|
-
if (value !== null) headers.set(name, value);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Buffered rather than streamed: forwarding a stream needs the non-standard
|
|
51
|
-
// `duplex` init that this project's types do not carry, and every payload
|
|
52
|
-
// this contract accepts is a small JSON document.
|
|
53
|
-
const hasBody = request.method !== 'GET' && request.method !== 'HEAD';
|
|
54
|
-
const response = await fetch(target, {
|
|
55
|
-
method: request.method,
|
|
56
|
-
headers,
|
|
57
|
-
body: hasBody ? await request.arrayBuffer() : undefined,
|
|
58
|
-
// A redirect is the API role's answer, not something to resolve here.
|
|
59
|
-
redirect: 'manual',
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const responseHeaders = new Headers();
|
|
63
|
-
for (const name of FORWARDED_RESPONSE_HEADERS) {
|
|
64
|
-
const value = response.headers.get(name);
|
|
65
|
-
if (value !== null) responseHeaders.set(name, value);
|
|
66
|
-
}
|
|
67
|
-
return new Response(response.body, { status: response.status, headers: responseHeaders });
|
|
32
|
+
return await forwardToApi(request, apiUrl);
|
|
68
33
|
}
|
|
69
34
|
|
|
70
35
|
export const GET = forward;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { MetadataRoute } from 'next';
|
|
2
|
+
import { catalogueIsOpen } from '@/env';
|
|
2
3
|
import { sitemapForOrigin } from '@/lib/seo/metadata';
|
|
3
4
|
import { requestOrigin } from '@/lib/seo/request-origin';
|
|
4
5
|
|
|
@@ -6,5 +7,7 @@ import { requestOrigin } from '@/lib/seo/request-origin';
|
|
|
6
7
|
// this response is served on, and that is not known until the request arrives.
|
|
7
8
|
// The entries themselves are built once per origin, not once per request.
|
|
8
9
|
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
|
9
|
-
|
|
10
|
+
const entries = await sitemapForOrigin(await requestOrigin());
|
|
11
|
+
if (catalogueIsOpen()) return entries;
|
|
12
|
+
return entries.filter((entry) => !new URL(entry.url).pathname.includes('/ui/'));
|
|
10
13
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { applicationVariables } from '@app/config/variables';
|
|
2
|
+
import { applicationVariables, serviceSurfacesAreOpen } from '@app/config/variables';
|
|
3
3
|
import { createEnv } from '@t3-oss/env-nextjs';
|
|
4
4
|
import { config } from 'dotenv';
|
|
5
5
|
|
|
@@ -26,6 +26,7 @@ export const env = createEnv({
|
|
|
26
26
|
INTERNAL_API_URL: applicationVariables.INTERNAL_API_URL,
|
|
27
27
|
PUBLIC_API_ORIGIN: applicationVariables.PUBLIC_API_ORIGIN,
|
|
28
28
|
PUBLIC_REALTIME_ORIGIN: applicationVariables.PUBLIC_REALTIME_ORIGIN,
|
|
29
|
+
SERVICE_SURFACES: applicationVariables.SERVICE_SURFACES,
|
|
29
30
|
},
|
|
30
31
|
runtimeEnv: {
|
|
31
32
|
BIND_HOST: process.env.BIND_HOST,
|
|
@@ -35,6 +36,15 @@ export const env = createEnv({
|
|
|
35
36
|
INTERNAL_API_URL: process.env.INTERNAL_API_URL,
|
|
36
37
|
PUBLIC_API_ORIGIN: process.env.PUBLIC_API_ORIGIN,
|
|
37
38
|
PUBLIC_REALTIME_ORIGIN: process.env.PUBLIC_REALTIME_ORIGIN,
|
|
39
|
+
SERVICE_SURFACES: process.env.SERVICE_SURFACES,
|
|
38
40
|
},
|
|
39
41
|
emptyStringAsUndefined: true,
|
|
40
42
|
});
|
|
43
|
+
|
|
44
|
+
/** Read per request: a build runs without the deployment's environment. */
|
|
45
|
+
export function catalogueIsOpen(): boolean {
|
|
46
|
+
return serviceSurfacesAreOpen({
|
|
47
|
+
NODE_ENV: process.env.NODE_ENV,
|
|
48
|
+
SERVICE_SURFACES: env.SERVICE_SURFACES,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the panel renders, with nothing about where it comes from. A section's
|
|
3
|
+
* fixture and its API answer have this one shape, so moving a section to the API
|
|
4
|
+
* changes what supplies the rows and no component.
|
|
5
|
+
*/
|
|
6
|
+
export interface AdminRow {
|
|
7
|
+
id: string;
|
|
8
|
+
title: string;
|
|
9
|
+
owner: string;
|
|
10
|
+
state: 'active' | 'paused';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type AdminData = Readonly<Record<string, readonly AdminRow[]>>;
|