@sssb/create 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/bin/create.js +135 -0
- package/package.json +22 -3
- package/src/args.js +270 -0
- package/src/files.js +660 -0
- package/src/generate.js +517 -0
- package/src/json.js +60 -0
- package/src/signals.js +72 -0
- package/src/template.js +496 -0
- package/src/yaml.js +17 -0
- package/template/app/DEMO-SIZE.md +55 -0
- package/template/app/config/app.ts +17 -0
- package/template/app/config/params.ts +70 -0
- package/template/app/infra/README.md +78 -0
- package/template/app/infra/app.ts +45 -0
- package/template/app/infra/cdk.json +9 -0
- package/template/app/infra/lib/tags.ts +35 -0
- package/template/app/infra/package.json +20 -0
- package/template/app/infra/tsconfig.json +13 -0
- package/template/app/messages/en.json +20 -0
- package/template/app/messages/es.json +20 -0
- package/template/app/next.config.ts +9 -0
- package/template/app/package.json +40 -0
- package/template/app/playwright.config.ts +50 -0
- package/template/app/playwright.demo.config.ts +10 -0
- package/template/app/src/app/[locale]/(protected)/dashboard/dashboard-glue.tsx +37 -0
- package/template/app/src/app/[locale]/(protected)/dashboard/page.tsx +21 -0
- package/template/app/src/app/[locale]/(protected)/header-glue.tsx +59 -0
- package/template/app/src/app/[locale]/(protected)/layout.tsx +43 -0
- package/template/app/src/app/[locale]/layout.tsx +55 -0
- package/template/app/src/app/[locale]/page.tsx +9 -0
- package/template/app/src/app/[locale]/signin/page.tsx +55 -0
- package/template/app/src/app/[locale]/signin/picker-glue.tsx +21 -0
- package/template/app/src/app/api/auth/dev-signin/route.ts +12 -0
- package/template/app/src/app/api/auth/org/route.ts +10 -0
- package/template/app/src/app/api/auth/signout/route.ts +9 -0
- package/template/app/src/app/api/items/route.ts +52 -0
- package/template/app/src/app/api/respond.ts +13 -0
- package/template/app/src/app/api/webhooks/cron/route.test.ts +59 -0
- package/template/app/src/app/api/webhooks/cron/route.ts +15 -0
- package/template/app/src/app/layout.tsx +7 -0
- package/template/app/src/app-config/abilities.ts +93 -0
- package/template/app/src/app-config/actors.ts +13 -0
- package/template/app/src/app-config/audit.ts +9 -0
- package/template/app/src/app-config/db/migrations/1001_items.ts +37 -0
- package/template/app/src/app-config/db/migrations/index.ts +11 -0
- package/template/app/src/app-config/db/rls-proofs.ts +81 -0
- package/template/app/src/app-config/db/schema.ts +23 -0
- package/template/app/src/app-config/digest.ts +10 -0
- package/template/app/src/app-config/identity.ts +8 -0
- package/template/app/src/app-config/inbound-email.ts +10 -0
- package/template/app/src/app-config/jobs.ts +28 -0
- package/template/app/src/app-config/messages.ts +18 -0
- package/template/app/src/app-config/notifications.ts +31 -0
- package/template/app/src/app-config/preset-operations.ts +9 -0
- package/template/app/src/app-config/presets.ts +18 -0
- package/template/app/src/app-config/seed.ts +7 -0
- package/template/app/src/app-config/simulator.ts +17 -0
- package/template/app/src/app-config/tours.ts +14 -0
- package/template/app/src/app-config/webhooks.ts +13 -0
- package/template/app/src/components/dashboard-screen.tsx +26 -0
- package/template/app/src/components/items-card.tsx +84 -0
- package/template/app/src/components/welcome-screen.tsx +20 -0
- package/template/app/src/demo-static/app.tsx +77 -0
- package/template/app/src/demo-static/index.html +12 -0
- package/template/app/src/demo-static/main.tsx +40 -0
- package/template/app/src/proxy.ts +9 -0
- package/template/app/src/seed/index.ts +93 -0
- package/template/app/src/sssb.conformance.test.ts +7 -0
- package/template/app/src/styles/index.css +1 -0
- package/template/app/tests/catalog.ts +15 -0
- package/template/app/tests/contract/rls-contract.test.ts +14 -0
- package/template/app/tests/demo-static/static-shell.spec.ts +32 -0
- package/template/app/tests/e2e/items.spec.ts +58 -0
- package/template/app/tsconfig.json +29 -0
- package/template/app/vite.demo.config.ts +8 -0
- package/template/guide.md +118 -0
- package/template/meta.json +633 -0
- package/template/root/_dot_editorconfig +12 -0
- package/template/root/_dot_husky/commit-msg +1 -0
- package/template/root/_dot_husky/pre-commit +1 -0
- package/template/root/_dot_nvmrc +1 -0
- package/template/root/_dot_prettierrc.json +5 -0
- package/template/root/commitlint.config.mjs +1 -0
- package/README.md +0 -3
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# infra/ — this app's CDK app (DRAFT)
|
|
2
|
+
|
|
3
|
+
This app's deployment, per ADR-0001 and ADR-0014 (D8): one stack holding SSSB's `SssbApp` construct
|
|
4
|
+
(`@sssb/cdk`, `packages/cdk` in SSSB's repository). The construct builds the Next standalone server in one
|
|
5
|
+
Lambda via the AWS Lambda Web Adapter, its Function URL behind CloudFront, static assets from S3, the
|
|
6
|
+
framework's migrator bundled with this app's own migrations, Aurora PostgreSQL Serverless v2 (min-capacity 0
|
|
7
|
+
outside production), alarms and a budget. `app.ts` instantiates it with `..` as the app's directory and the
|
|
8
|
+
app's own `config/params.ts`; `lib/tags.ts` is your organisation's tagging, applied to the whole stack.
|
|
9
|
+
|
|
10
|
+
This is a **draft you are meant to take over**, not a finished deployment. It exists so the hosting
|
|
11
|
+
decision is written down in runnable form rather than as prose, and so `pnpm synth` here proves the shape
|
|
12
|
+
compiles offline before anyone has an AWS account. The stack in `app.ts` is yours: add your own constructs
|
|
13
|
+
beside `SssbApp`. The construct reads only the app's directory and params, so this directory can also move
|
|
14
|
+
into an infrastructure repository or a root `infra/` that composes several apps; give each `SssbApp` an id of
|
|
15
|
+
its own there.
|
|
16
|
+
|
|
17
|
+
## Status: authored — cutover
|
|
18
|
+
|
|
19
|
+
- `pnpm synth` in this directory is the verification bar: green, offline, zero credentials
|
|
20
|
+
(environment-agnostic stack, no lookups). CI runs it for every app.
|
|
21
|
+
- **Nothing here deploys until** (see `docs/cutover-checklist.md`): `cloud-accounts` fills
|
|
22
|
+
`../config/params.ts` · `recurring-cost` — Aurora, the NAT gateway (on the `pg` shape), and CloudFront need
|
|
23
|
+
explicit approval. Not a checklist row, but do it first: if your organisation ships its own CDK construct
|
|
24
|
+
library, replace `lib/tags.ts` with it.
|
|
25
|
+
|
|
26
|
+
## Two network shapes — decide before the first deploy
|
|
27
|
+
|
|
28
|
+
`params.database.transport` in the app's `config/params.ts` picks one (ADR-0001 and ADR-0002, addenda
|
|
29
|
+
2026-11-16). On an existing stack a switch does not replace anything: it fails on overlapping subnet
|
|
30
|
+
CIDRs and rolls back. Changing shape later means a new stack and a snapshot restore.
|
|
31
|
+
|
|
32
|
+
- **`pg` (default):** both Lambdas inside the VPC, reaching Aurora over a socket. One NAT gateway carries
|
|
33
|
+
their egress.
|
|
34
|
+
- **`data-api` (opt-in):**
|
|
35
|
+
- only the cluster lives in the VPC, in isolated subnets with no NAT gateway;
|
|
36
|
+
- both Lambdas run outside it and reach Aurora through the RDS Data API, authorised by IAM alone;
|
|
37
|
+
- the function configuration holds no database credential.
|
|
38
|
+
|
|
39
|
+
Cutover rows `data-api` (the transport, proven live by SSSB's `docs/runbooks/data-api.md` runbook) and
|
|
40
|
+
`data-api-access` (this shape, deployed) close it.
|
|
41
|
+
|
|
42
|
+
## What synth asserts
|
|
43
|
+
|
|
44
|
+
`cdk synth` fails unless each of these holds, for the shape the params choose (the construct's header,
|
|
45
|
+
`packages/cdk/src/sssb-app.js` in SSSB's repository, is the full list):
|
|
46
|
+
|
|
47
|
+
- the `@sssb/kit` this app resolves is the construct's own version (SSSB's packages are released in
|
|
48
|
+
lockstep), installed under the project root (the lock file's directory), which also installs esbuild: the
|
|
49
|
+
migrator is bundled locally, never in CDK's Docker fallback;
|
|
50
|
+
- the slug is the `APP_SLUG` in `../config/app.ts`, and a linked `@sssb/app-config` is this app's own
|
|
51
|
+
`src/app-config`;
|
|
52
|
+
- the server's final environment, escape-hatch overrides included, sets `APP_MODE=real` and has neither
|
|
53
|
+
`DEMO_MODE` nor `E2E_BUILD`, so fake adapters cannot serve a deployment; the migrator carries neither either;
|
|
54
|
+
- the migrator deploys the bundle esbuild staged during this synth, and that bundle carries every migration the
|
|
55
|
+
app's registry names under a literal key, names the framework's and the app's migration registries in
|
|
56
|
+
esbuild's path comments (so a minified bundle fails instead of passing unread), and holds no code from a test
|
|
57
|
+
fixture. The construct resolves the migrator from this app's `@sssb/kit` and passes the seam to esbuild
|
|
58
|
+
explicitly (`--alias:@sssb/app-config=<app>/src/app-config`): in SSSB's own repository the nearest tsconfig
|
|
59
|
+
points that alias at SSSB's test fixture, and a migrator bundled with it would ship the fixture's migrations
|
|
60
|
+
instead of the app's.
|
|
61
|
+
|
|
62
|
+
SSSB's own repository also synthesizes both shapes for every app and checks the way in (`packages/cdk`'s
|
|
63
|
+
test): on both, each statement that can grant a Secrets Manager action names the cluster's own secret alone, no
|
|
64
|
+
role attaches an AWS-managed policy beyond the two Lambda execution policies, and every database cluster is
|
|
65
|
+
encrypted at rest; on `data-api`, each statement that can grant an `rds-data` action names the cluster alone and
|
|
66
|
+
the database's security group admits nothing.
|
|
67
|
+
|
|
68
|
+
## Deploys — checks in CI, deploys in your own pipeline
|
|
69
|
+
|
|
70
|
+
`.github/workflows/checks.yml` runs checks only; there is deliberately no GitHub Actions CD here,
|
|
71
|
+
because the deploy pipeline is the piece most tied to an organisation's accounts and approval gates.
|
|
72
|
+
The shape this stack assumes: a pipeline that uploads the standalone build zip the `Server` function
|
|
73
|
+
expects (the construct's placeholder asset is a `run.sh` that execs `node server.js`) and invokes the
|
|
74
|
+
`Migrator` before shifting traffic. Cutover row `deploy-pipeline` is where that gets built.
|
|
75
|
+
|
|
76
|
+
Nothing in this directory may depend on app source beyond `config/app.ts` and `config/params.ts`, which is
|
|
77
|
+
what makes moving it mechanical. `pnpm typecheck` covers it, through the app's own `typecheck` (`tsc --noEmit -p infra`,
|
|
78
|
+
with `infra/tsconfig.json`), and `synth` runs it.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { SssbApp } from '@sssb/cdk'
|
|
3
|
+
import * as cdk from 'aws-cdk-lib'
|
|
4
|
+
import { APP_SLUG } from '../config/app'
|
|
5
|
+
import { params } from '../config/params'
|
|
6
|
+
import { addTags, TAGS } from './lib/tags'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* This app's deployment (ADR-0014, D8): one stack holding SSSB's `SssbApp` construct, built from this app's
|
|
10
|
+
* own directory and `config/params.ts`. Environment-agnostic until cutover (`cloud-accounts`) fills
|
|
11
|
+
* config/params.ts — no account/region is bound, so `pnpm synth` runs offline with zero credentials.
|
|
12
|
+
*
|
|
13
|
+
* The stack is yours: add your own constructs beside `SssbApp`, or move it into a stack your organisation's
|
|
14
|
+
* infrastructure already has.
|
|
15
|
+
*/
|
|
16
|
+
const ENVIRONMENTS = ['Staging', 'Production'] as const
|
|
17
|
+
type Environment = (typeof ENVIRONMENTS)[number]
|
|
18
|
+
|
|
19
|
+
const app = new cdk.App()
|
|
20
|
+
|
|
21
|
+
const environment = app.node.tryGetContext('environment') as Environment | undefined
|
|
22
|
+
if (!environment || !ENVIRONMENTS.includes(environment)) {
|
|
23
|
+
throw new Error(`context "environment" must be one of ${ENVIRONMENTS.join(', ')}`)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Stack id derives from the app slug (capitalized) so two apps in one AWS account never collide.
|
|
27
|
+
const stackId = `${APP_SLUG.charAt(0).toUpperCase()}${APP_SLUG.slice(1)}AppStack`
|
|
28
|
+
|
|
29
|
+
const stack = new cdk.Stack(app, stackId, {
|
|
30
|
+
description: `${APP_SLUG} application stack (Next standalone on Lambda via Web Adapter, ADR-0001)`,
|
|
31
|
+
})
|
|
32
|
+
addTags(stack, { ...TAGS, Environment: environment })
|
|
33
|
+
|
|
34
|
+
// The id `Default` is left out of every logical id under it, so the resources keep the ids they had when
|
|
35
|
+
// they were this stack's own children (before ADR-0014's P9) and a deployed stack updates in place. A second
|
|
36
|
+
// SssbApp in the same stack needs an id of its own.
|
|
37
|
+
new SssbApp(stack, 'Default', {
|
|
38
|
+
appDir: path.join(__dirname, '..'),
|
|
39
|
+
slug: APP_SLUG,
|
|
40
|
+
params,
|
|
41
|
+
environment,
|
|
42
|
+
production: environment === 'Production',
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
app.synth()
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as cdk from 'aws-cdk-lib'
|
|
2
|
+
import type { Construct } from 'constructs'
|
|
3
|
+
import { APP_SLUG } from '../../config/app'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The mandatory-tag pattern: one map applied to EVERY construct in the stack (`addTags` below), so
|
|
7
|
+
* no resource can be created without answering the questions the organisation asks of it.
|
|
8
|
+
*
|
|
9
|
+
* The first three keys are near-universal — what this is (`Name`, `Application`) and who answers for
|
|
10
|
+
* it (`Owner`); `Environment` is the fourth, added per stack in `../app.ts` because only the stack
|
|
11
|
+
* knows which deployment it is. Keep those.
|
|
12
|
+
*
|
|
13
|
+
* The classification keys below are an EXAMPLE of the other half of the pattern — the governance
|
|
14
|
+
* taxonomy an organisation mandates so its estate can be queried by sensitivity, criticality and
|
|
15
|
+
* blast radius. Every organisation's is different: REPLACE them with your own policy's keys (or drop
|
|
16
|
+
* them if you have none), and if your organisation ships shared CDK constructs for tagging, import
|
|
17
|
+
* those instead of this file. `UPDATE-ME` is a deliberate tripwire — it synths and deploys,
|
|
18
|
+
* and stays obvious in the console until someone fills it in.
|
|
19
|
+
*/
|
|
20
|
+
export const TAGS = {
|
|
21
|
+
Name: APP_SLUG,
|
|
22
|
+
Application: APP_SLUG,
|
|
23
|
+
Owner: 'UPDATE-ME',
|
|
24
|
+
// Example governance taxonomy — replace these four keys with your own organisation's.
|
|
25
|
+
AssetClassification: 'UPDATE-ME',
|
|
26
|
+
DataClassification: 'UPDATE-ME',
|
|
27
|
+
MissionCriticality: 'UPDATE-ME',
|
|
28
|
+
AccessLevel: 'UPDATE-ME',
|
|
29
|
+
} as const
|
|
30
|
+
|
|
31
|
+
export function addTags(scope: Construct, tags: Record<string, string>): void {
|
|
32
|
+
for (const [key, value] of Object.entries(tags)) {
|
|
33
|
+
cdk.Tags.of(scope).add(key, value)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "starter-infra",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"description": "This app's deployment: SSSB's SssbApp construct in a stack of its own (ADR-0001, ADR-0014 D8). A draft you take over at cutover.",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"synth": "cdk synth --quiet",
|
|
9
|
+
"diff": "cdk diff"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@sssb/cdk": "workspace:*",
|
|
13
|
+
"@sssb/tools": "workspace:*",
|
|
14
|
+
"aws-cdk-lib": "^2.274.0",
|
|
15
|
+
"constructs": "^10.8.1"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"aws-cdk": "^2.1146.0"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
// The deployment's own TypeScript program: the app's options (the `extends`, so a compiler option the app sets
|
|
3
|
+
// holds here too), over infra/ only. Not part of the app's program, which `next build` typechecks: the CDK's
|
|
4
|
+
// declarations have no place in the app's build. The app's `typecheck` script runs this one after its own.
|
|
5
|
+
"extends": "../tsconfig.json",
|
|
6
|
+
"compilerOptions": {
|
|
7
|
+
"incremental": false,
|
|
8
|
+
// A CDK app runs in Node (cdk.json runs it with tsx).
|
|
9
|
+
"types": ["node"]
|
|
10
|
+
},
|
|
11
|
+
"include": ["**/*.ts"],
|
|
12
|
+
"exclude": ["node_modules", "cdk.out"]
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"welcome": {
|
|
3
|
+
"appName": "Starter",
|
|
4
|
+
"title": "Starter",
|
|
5
|
+
"subtitle": "A minimal app to grow from: one entity, one card, and everything else switched off.",
|
|
6
|
+
"dashboardLink": "Go to the dashboard"
|
|
7
|
+
},
|
|
8
|
+
"dashboard": {
|
|
9
|
+
"title": "Dashboard",
|
|
10
|
+
"signedInAs": "Signed in as {name} ({role})."
|
|
11
|
+
},
|
|
12
|
+
"items": {
|
|
13
|
+
"title": "Items",
|
|
14
|
+
"hint": "Items belong to the team you're working in — and never leave your tenant.",
|
|
15
|
+
"empty": "No items in this team yet.",
|
|
16
|
+
"addLabel": "New item",
|
|
17
|
+
"addButton": "Add item",
|
|
18
|
+
"readOnlyHint": "You have read-only access to items in this team."
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"welcome": {
|
|
3
|
+
"appName": "Starter",
|
|
4
|
+
"title": "Starter",
|
|
5
|
+
"subtitle": "Una aplicación mínima desde la que crecer: una entidad, una tarjeta y todo lo demás apagado.",
|
|
6
|
+
"dashboardLink": "Ir al panel"
|
|
7
|
+
},
|
|
8
|
+
"dashboard": {
|
|
9
|
+
"title": "Panel",
|
|
10
|
+
"signedInAs": "Sesión iniciada como {name} ({role})."
|
|
11
|
+
},
|
|
12
|
+
"items": {
|
|
13
|
+
"title": "Elementos",
|
|
14
|
+
"hint": "Los elementos pertenecen al equipo en el que trabajas y nunca salen de tu organización.",
|
|
15
|
+
"empty": "Aún no hay elementos en este equipo.",
|
|
16
|
+
"addLabel": "Nuevo elemento",
|
|
17
|
+
"addButton": "Añadir elemento",
|
|
18
|
+
"readOnlyHint": "Tienes acceso de solo lectura a los elementos de este equipo."
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { withSssb } from '@sssb/tools/next'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This app's Next config, deliberately shorter than SSSB's reference app's: no Sentry wrapper (that is a cutover row,
|
|
5
|
+
* and the adapter is inert without a DSN), no Panda/PostCSS pipeline (Mantine ships its own reset). What every SSSB
|
|
6
|
+
* app needs (the framework transpiled, next-intl pointed at the framework's request config, the standalone output,
|
|
7
|
+
* a hermetic `next dev`) comes from the preset, @sssb/tools/next.
|
|
8
|
+
*/
|
|
9
|
+
export default withSssb({ typedRoutes: true }, { appDir: __dirname })
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "starter",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"description": "The starter app: the minimum an adopter keeps — one entity, one card, and an otherwise empty seam (ADR-0007, ADR-0012).",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dev": "NEXT_TELEMETRY_DISABLED=1 APP_MODE=simulated sssb dev-tick starter -- next dev --port \"$(sssb port)\"",
|
|
9
|
+
"tick": "sssb tick starter",
|
|
10
|
+
"build": "NEXT_TELEMETRY_DISABLED=1 next build",
|
|
11
|
+
"start": "next start --port \"$(sssb port)\"",
|
|
12
|
+
"typecheck": "next typegen && tsc --noEmit && tsc --noEmit -p infra",
|
|
13
|
+
"sssb:doctor": "sssb doctor",
|
|
14
|
+
"check:e2e": "sssb check-e2e",
|
|
15
|
+
"test:e2e": "NEXT_TELEMETRY_DISABLED=1 playwright test",
|
|
16
|
+
"build:demo-static": "vite build --config vite.demo.config.ts",
|
|
17
|
+
"check:demo-size": "sssb check-demo-size 840000",
|
|
18
|
+
"e2e:demo-static": "playwright test --config playwright.demo.config.ts"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@mantine/core": "^9.7.3",
|
|
22
|
+
"@sssb/kit": "workspace:*",
|
|
23
|
+
"kysely": "^0.29.7",
|
|
24
|
+
"next": "^16.4.6",
|
|
25
|
+
"next-intl": "^4.14.9",
|
|
26
|
+
"react": "~19.3.1",
|
|
27
|
+
"react-dom": "~19.3.1"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@playwright/test": "^1.64.1",
|
|
31
|
+
"@sssb/tools": "workspace:*",
|
|
32
|
+
"@vitejs/plugin-react": "^6.1.2",
|
|
33
|
+
"embedded-postgres": "18.4.0-beta.17",
|
|
34
|
+
"vite": "^8.3.5",
|
|
35
|
+
"vite-plugin-singlefile": "^2.3.4"
|
|
36
|
+
},
|
|
37
|
+
"sssb": {
|
|
38
|
+
"port": "starter"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { defineConfig, devices } from '@playwright/test'
|
|
2
|
+
import { originFor } from '@sssb/tools/ports'
|
|
3
|
+
import { assertNoLiveDevTicker } from '@sssb/tools/ticker-marker'
|
|
4
|
+
|
|
5
|
+
// A dev server started with `DEV_TICK_SECONDS` set would be ADOPTED by `reuseExistingServer` below and tick under the
|
|
6
|
+
// suite; the ticker leaves a marker while it runs, and this refuses to load past it (@sssb/tools/ticker-marker).
|
|
7
|
+
assertNoLiveDevTicker()
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A port of this app's own: two apps in one workspace must be able to run (and be tested) side
|
|
11
|
+
* by side without one silently reusing the other's dev server (or a foreign server squatting :3000,
|
|
12
|
+
* which `reuseExistingServer` would otherwise adopt as this app's).
|
|
13
|
+
*
|
|
14
|
+
* Both numbers now come from @sssb/tools/ports rather than being written here, which extends that same
|
|
15
|
+
* guarantee ACROSS checkouts: a linked worktree gets its own pair, so two agent sessions running e2e
|
|
16
|
+
* at once no longer collide either. `pnpm dev` derives the identical number from the same function.
|
|
17
|
+
*/
|
|
18
|
+
const BASE_URL = originFor('starter')
|
|
19
|
+
|
|
20
|
+
export default defineConfig({
|
|
21
|
+
testDir: './tests/e2e',
|
|
22
|
+
fullyParallel: true,
|
|
23
|
+
// This app's whole suite is ONE spec, so it always starts against a cold dev server and pays a
|
|
24
|
+
// full Next compile on every route it touches — sign-in, dashboard, the items route. The default
|
|
25
|
+
// 30s is marginal for that (it timed out on the first run and passed on retry), and there is no
|
|
26
|
+
// warm-up pass to inherit, so the budget is raised rather than left to flake.
|
|
27
|
+
timeout: 60_000,
|
|
28
|
+
expect: { timeout: 15_000 },
|
|
29
|
+
forbidOnly: !!process.env['CI'],
|
|
30
|
+
retries: process.env['CI'] ? 2 : 1,
|
|
31
|
+
// One worker, on CI too — this app's whole suite is one spec, so parallelism buys nothing here,
|
|
32
|
+
// and more workers against one shared world (one `.data` behind one dev server) cost reliability rather than
|
|
33
|
+
// saving time.
|
|
34
|
+
workers: 1,
|
|
35
|
+
reporter: process.env['CI'] ? 'github' : 'list',
|
|
36
|
+
use: {
|
|
37
|
+
baseURL: BASE_URL,
|
|
38
|
+
trace: 'on-first-retry',
|
|
39
|
+
},
|
|
40
|
+
projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }],
|
|
41
|
+
webServer: {
|
|
42
|
+
command: 'pnpm dev',
|
|
43
|
+
url: BASE_URL,
|
|
44
|
+
// `pnpm dev` ticks the scheduler on a timer when DEV_TICK_SECONDS is set (`sssb dev-tick`). The e2e suite expects a
|
|
45
|
+
// scheduler that does nothing until a test asks, so whatever is in the caller's shell, the server it starts is not ticked.
|
|
46
|
+
env: { DEV_TICK_SECONDS: '' },
|
|
47
|
+
reuseExistingServer: !process.env['CI'],
|
|
48
|
+
timeout: 120_000,
|
|
49
|
+
},
|
|
50
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineConfig, devices } from '@playwright/test'
|
|
2
|
+
|
|
3
|
+
/** Drives the built static shell straight from file:// — no server involved. */
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
testDir: './tests/demo-static',
|
|
6
|
+
fullyParallel: true,
|
|
7
|
+
expect: { timeout: 10_000 },
|
|
8
|
+
reporter: process.env['CI'] ? 'github' : 'list',
|
|
9
|
+
projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }],
|
|
10
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState } from 'react'
|
|
4
|
+
import { DashboardScreen, type DashboardUser } from '@/components/dashboard-screen'
|
|
5
|
+
import { ItemsCard, type Item } from '@/components/items-card'
|
|
6
|
+
|
|
7
|
+
export function DashboardGlue({ user, canCreateItem }: { user: DashboardUser; canCreateItem: boolean }) {
|
|
8
|
+
const [items, setItems] = useState<Item[]>([])
|
|
9
|
+
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
// Sets state only once the response lands — the legitimate "sync with an external system"
|
|
12
|
+
// case, so the react-hooks set-state-in-effect rule does not fire here.
|
|
13
|
+
void fetch('/api/items')
|
|
14
|
+
.then((response) => (response.ok ? response.json() : { items: [] }))
|
|
15
|
+
.then((data: { items: Item[] }) => setItems(data.items))
|
|
16
|
+
}, [])
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<DashboardScreen user={user}>
|
|
20
|
+
<ItemsCard
|
|
21
|
+
items={items}
|
|
22
|
+
canCreate={canCreateItem}
|
|
23
|
+
onAdd={async (title) => {
|
|
24
|
+
const response = await fetch('/api/items', {
|
|
25
|
+
method: 'POST',
|
|
26
|
+
headers: { 'content-type': 'application/json' },
|
|
27
|
+
body: JSON.stringify({ title }),
|
|
28
|
+
})
|
|
29
|
+
if (response.ok) {
|
|
30
|
+
const { item } = (await response.json()) as { item: Item }
|
|
31
|
+
setItems((prev) => [item, ...prev])
|
|
32
|
+
}
|
|
33
|
+
}}
|
|
34
|
+
/>
|
|
35
|
+
</DashboardScreen>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { setRequestLocale } from 'next-intl/server'
|
|
2
|
+
import { redirect } from 'next/navigation'
|
|
3
|
+
import { auth } from '@sssb/kit/adapters/index'
|
|
4
|
+
import { canInActiveOrg } from '@sssb/kit/authz/authorize'
|
|
5
|
+
import { DashboardGlue } from './dashboard-glue'
|
|
6
|
+
|
|
7
|
+
export default async function DashboardPage({ params }: { params: Promise<{ locale: string }> }) {
|
|
8
|
+
const { locale } = await params
|
|
9
|
+
setRequestLocale(locale)
|
|
10
|
+
const user = await auth.getCurrentUser()
|
|
11
|
+
if (!user) redirect(`/${locale}${auth.signInPath()}`)
|
|
12
|
+
|
|
13
|
+
// Reflect the server-side authorization in the UI: restricted members get a read-only card. The
|
|
14
|
+
// POST route re-checks with authorize(), so this is presentation, never enforcement.
|
|
15
|
+
return (
|
|
16
|
+
<DashboardGlue
|
|
17
|
+
user={{ name: user.name, role: user.role }}
|
|
18
|
+
canCreateItem={canInActiveOrg(user, 'create', 'Item')}
|
|
19
|
+
/>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useTranslations } from 'next-intl'
|
|
4
|
+
import { AppHeader } from '@sssb/kit/components/app-header'
|
|
5
|
+
import { OrgSwitcher, type SwitcherOrg } from '@sssb/kit/components/auth/org-switcher'
|
|
6
|
+
import { UserMenu, type MenuUser } from '@sssb/kit/components/auth/user-menu'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The framework header, wired to this app. Deliberately barer than SSSB's reference app's: no notification
|
|
10
|
+
* bell (nothing here produces notifications) and no nav (there is one screen). `appName` is passed
|
|
11
|
+
* because the prop is required: one shared framework catalog cannot name two products, so SSSB's
|
|
12
|
+
* catalog carries no product name and every app supplies its own (see AppHeader).
|
|
13
|
+
*/
|
|
14
|
+
export function HeaderGlue({
|
|
15
|
+
user,
|
|
16
|
+
orgs,
|
|
17
|
+
activeSlug,
|
|
18
|
+
tenantName,
|
|
19
|
+
locale,
|
|
20
|
+
}: {
|
|
21
|
+
user: MenuUser
|
|
22
|
+
orgs: SwitcherOrg[]
|
|
23
|
+
activeSlug: string
|
|
24
|
+
tenantName: string
|
|
25
|
+
locale: string
|
|
26
|
+
}) {
|
|
27
|
+
const t = useTranslations('welcome')
|
|
28
|
+
return (
|
|
29
|
+
<AppHeader
|
|
30
|
+
appName={t('appName')}
|
|
31
|
+
tenantName={tenantName}
|
|
32
|
+
controls={
|
|
33
|
+
<>
|
|
34
|
+
<OrgSwitcher
|
|
35
|
+
orgs={orgs}
|
|
36
|
+
activeSlug={activeSlug}
|
|
37
|
+
onSwitch={(orgSlug) => {
|
|
38
|
+
void fetch('/api/auth/org', {
|
|
39
|
+
method: 'POST',
|
|
40
|
+
headers: { 'content-type': 'application/json' },
|
|
41
|
+
body: JSON.stringify({ orgSlug }),
|
|
42
|
+
}).then((response) => {
|
|
43
|
+
if (response.ok) window.location.reload()
|
|
44
|
+
})
|
|
45
|
+
}}
|
|
46
|
+
/>
|
|
47
|
+
<UserMenu
|
|
48
|
+
user={user}
|
|
49
|
+
onSignOut={() => {
|
|
50
|
+
void fetch('/api/auth/signout', { method: 'POST' }).then((response) => {
|
|
51
|
+
if (response.ok) window.location.assign(`/${locale}`)
|
|
52
|
+
})
|
|
53
|
+
}}
|
|
54
|
+
/>
|
|
55
|
+
</>
|
|
56
|
+
}
|
|
57
|
+
/>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { setRequestLocale } from 'next-intl/server'
|
|
2
|
+
import { redirect } from 'next/navigation'
|
|
3
|
+
import type { ReactNode } from 'react'
|
|
4
|
+
import { auth } from '@sssb/kit/adapters/index'
|
|
5
|
+
import { findTenant } from '@/seed'
|
|
6
|
+
import { HeaderGlue } from './header-glue'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Everything in this group requires a signed-in user; signed-out visitors go to /signin.
|
|
10
|
+
*
|
|
11
|
+
* Deliberately shorter than SSSB's reference app's: no access-gate evaluation, because this app seeds no
|
|
12
|
+
* agreements and registers no gates. The capability is not removed — it is simply unused, and an
|
|
13
|
+
* unused capability needs no scaffolding (ADR-0012).
|
|
14
|
+
*/
|
|
15
|
+
export default async function ProtectedLayout({
|
|
16
|
+
children,
|
|
17
|
+
params,
|
|
18
|
+
}: {
|
|
19
|
+
children: ReactNode
|
|
20
|
+
params: Promise<{ locale: string }>
|
|
21
|
+
}) {
|
|
22
|
+
const { locale } = await params
|
|
23
|
+
setRequestLocale(locale)
|
|
24
|
+
|
|
25
|
+
const user = await auth.getCurrentUser()
|
|
26
|
+
if (!user) redirect(`/${locale}${auth.signInPath()}`)
|
|
27
|
+
|
|
28
|
+
const orgs = await auth.listMyOrgs()
|
|
29
|
+
const tenantName = findTenant(user.tenantSlug)?.name ?? user.tenantSlug
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<>
|
|
33
|
+
<HeaderGlue
|
|
34
|
+
user={{ name: user.name, email: user.email }}
|
|
35
|
+
orgs={orgs}
|
|
36
|
+
activeSlug={user.orgSlug}
|
|
37
|
+
tenantName={tenantName}
|
|
38
|
+
locale={locale}
|
|
39
|
+
/>
|
|
40
|
+
{children}
|
|
41
|
+
</>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import '@mantine/core/styles.css'
|
|
2
|
+
import '@/styles/index.css'
|
|
3
|
+
|
|
4
|
+
import { ColorSchemeScript, MantineProvider, mantineHtmlProps } from '@mantine/core'
|
|
5
|
+
import { hasLocale, NextIntlClientProvider } from 'next-intl'
|
|
6
|
+
import { setRequestLocale } from 'next-intl/server'
|
|
7
|
+
import { notFound } from 'next/navigation'
|
|
8
|
+
import type { ReactNode } from 'react'
|
|
9
|
+
import { auth, isDemoMode } from '@sssb/kit/adapters/index'
|
|
10
|
+
import { DemoBadge } from '@sssb/kit/components/demo-badge'
|
|
11
|
+
import { routing } from '@sssb/kit/i18n/routing'
|
|
12
|
+
import { getTenantTheme } from '@sssb/kit/theme'
|
|
13
|
+
import { tenants } from '@/seed'
|
|
14
|
+
|
|
15
|
+
export const metadata = {
|
|
16
|
+
title: 'Starter',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function generateStaticParams() {
|
|
20
|
+
return routing.locales.map((locale) => ({ locale }))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default async function LocaleLayout({
|
|
24
|
+
children,
|
|
25
|
+
params,
|
|
26
|
+
}: {
|
|
27
|
+
children: ReactNode
|
|
28
|
+
params: Promise<{ locale: string }>
|
|
29
|
+
}) {
|
|
30
|
+
const { locale } = await params
|
|
31
|
+
if (!hasLocale(routing.locales, locale)) notFound()
|
|
32
|
+
setRequestLocale(locale)
|
|
33
|
+
|
|
34
|
+
// The theming seam (ADR-0005): the ACTIVE tenant drives the theme. Signed-out pages fall back to
|
|
35
|
+
// this app's FIRST seeded tenant rather than SSSB's DEFAULT_TENANT_SLUG, which names the
|
|
36
|
+
// world of SSSB's reference app — see the seam notes in SSSB's adoption guide.
|
|
37
|
+
const user = await auth.getCurrentUser()
|
|
38
|
+
const theme = getTenantTheme(user?.tenantSlug ?? tenants[0]!.slug)
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<html lang={locale} {...mantineHtmlProps}>
|
|
42
|
+
<head>
|
|
43
|
+
<ColorSchemeScript />
|
|
44
|
+
</head>
|
|
45
|
+
<body>
|
|
46
|
+
<NextIntlClientProvider>
|
|
47
|
+
<MantineProvider theme={theme}>
|
|
48
|
+
{children}
|
|
49
|
+
{isDemoMode ? <DemoBadge /> : null}
|
|
50
|
+
</MantineProvider>
|
|
51
|
+
</NextIntlClientProvider>
|
|
52
|
+
</body>
|
|
53
|
+
</html>
|
|
54
|
+
)
|
|
55
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { setRequestLocale } from 'next-intl/server'
|
|
2
|
+
import { WelcomeScreen } from '@/components/welcome-screen'
|
|
3
|
+
|
|
4
|
+
// Route files are thin wrappers around router-agnostic screens (ADR-0006).
|
|
5
|
+
export default async function HomePage({ params }: { params: Promise<{ locale: string }> }) {
|
|
6
|
+
const { locale } = await params
|
|
7
|
+
setRequestLocale(locale)
|
|
8
|
+
return <WelcomeScreen dashboardHref={`/${locale}/dashboard`} />
|
|
9
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Route } from 'next'
|
|
2
|
+
import { getTranslations, setRequestLocale } from 'next-intl/server'
|
|
3
|
+
import { redirect } from 'next/navigation'
|
|
4
|
+
import { auth, isSimulated } from '@sssb/kit/adapters/index'
|
|
5
|
+
import { listAllPeople } from '@sssb/kit/adapters/fake/auth'
|
|
6
|
+
import { SignInScreen } from '@sssb/kit/components/auth/sign-in-screen'
|
|
7
|
+
import { findTenant } from '@/seed'
|
|
8
|
+
import { PickerGlue } from './picker-glue'
|
|
9
|
+
|
|
10
|
+
export default async function SignInPage({
|
|
11
|
+
params,
|
|
12
|
+
searchParams,
|
|
13
|
+
}: {
|
|
14
|
+
params: Promise<{ locale: string }>
|
|
15
|
+
searchParams: Promise<{ returnTo?: string }>
|
|
16
|
+
}) {
|
|
17
|
+
const { locale } = await params
|
|
18
|
+
setRequestLocale(locale)
|
|
19
|
+
const { returnTo } = await searchParams
|
|
20
|
+
// Only same-origin, path-shaped targets; anything else falls back to the dashboard.
|
|
21
|
+
const safe = returnTo && returnTo.startsWith('/') && !returnTo.startsWith('//')
|
|
22
|
+
const target = (safe ? returnTo : `/${locale}/dashboard`) as Route
|
|
23
|
+
|
|
24
|
+
if (await auth.getCurrentUser()) redirect(target)
|
|
25
|
+
|
|
26
|
+
if (!isSimulated) {
|
|
27
|
+
const [{ RealSignInForm }, t] = await Promise.all([
|
|
28
|
+
import('@sssb/kit/adapters/real/sign-in-form'),
|
|
29
|
+
getTranslations('auth'),
|
|
30
|
+
])
|
|
31
|
+
const labels = {
|
|
32
|
+
email: t('emailLabel'),
|
|
33
|
+
password: t('passwordLabel'),
|
|
34
|
+
submit: t('signInButton'),
|
|
35
|
+
genericError: t('signInError'),
|
|
36
|
+
mfaNotImplemented: t('mfaNotImplemented'),
|
|
37
|
+
}
|
|
38
|
+
return <SignInScreen body={<RealSignInForm returnTo={target} labels={labels} />} />
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// A person with no membership has no role to sign in as, so the picker leaves them out.
|
|
42
|
+
const people = listAllPeople().flatMap((p) => {
|
|
43
|
+
const membership = p.memberships[0]
|
|
44
|
+
if (!membership) return []
|
|
45
|
+
return [
|
|
46
|
+
{
|
|
47
|
+
id: p.id,
|
|
48
|
+
name: p.name,
|
|
49
|
+
role: membership.role,
|
|
50
|
+
tenantName: findTenant(p.tenantSlug)?.name ?? p.tenantSlug,
|
|
51
|
+
},
|
|
52
|
+
]
|
|
53
|
+
})
|
|
54
|
+
return <SignInScreen body={<PickerGlue people={people} returnTo={target} />} />
|
|
55
|
+
}
|