@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,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The APP's Simulator registrations (the seam side of the panel's tab strip + the Snapshots flag list,
|
|
3
|
+
* ADR-0012). The framework panel owns its subsystem tabs and its own feature flags.
|
|
4
|
+
*
|
|
5
|
+
* EMPTY REGISTRATION on every count: no extra tabs, no app feature flags. The panel still ships every
|
|
6
|
+
* framework tab; `flags` is composed into KNOWN_FLAGS (@sssb/kit/adapters/fake/analytics.ts) and an empty
|
|
7
|
+
* list simply adds nothing. `tabs` is not exported at all — nothing would read it, and an export with
|
|
8
|
+
* no consumer is dead code the gate would (rightly) flag.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** One app-registered Snapshots feature flag. `labelKey` resolves in the `simulator` i18n namespace. */
|
|
12
|
+
interface AppSimulatorFlag {
|
|
13
|
+
id: string
|
|
14
|
+
labelKey: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const flags: AppSimulatorFlag[] = []
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TourDefinition } from '@sssb/kit/demo-static/tour/contracts'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The APP's registered TOURS — scripted walkthroughs the Simulator Tours tab lists and runs
|
|
5
|
+
* (@sssb/kit/demo-static/tour/contracts, ADR-0012).
|
|
6
|
+
*
|
|
7
|
+
* EMPTY REGISTRATION, and it is a real off-switch rather than an empty list: with no tours registered
|
|
8
|
+
* the panel does not render the Tours tab at all and the engine never mounts a ghost cursor. It is not
|
|
9
|
+
* free in BYTES — the shell imports the engine either way, which is ~11KB of this app's single-file
|
|
10
|
+
* demo — because the alternative is making every app wire the engine itself, and the framework's whole
|
|
11
|
+
* bargain here is that an app inherits the simulated world without assembling it. An adopter who wants
|
|
12
|
+
* a walkthrough writes one here (`/sssb:new-tour`); SSSB's reference app's is the worked example.
|
|
13
|
+
*/
|
|
14
|
+
export const tours: TourDefinition[] = []
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The APP's outbound-webhook event kinds (the seam side of @sssb/kit/core/webhook-events.ts, ADR-0012). The
|
|
3
|
+
* framework owns the backoff policy, the signed envelope, and its own kind (job.status_changed).
|
|
4
|
+
*
|
|
5
|
+
* EMPTY REGISTRATION: no app events. Endpoints can still be registered and still receive the
|
|
6
|
+
* framework's own event; the subscribe list simply offers one kind instead of three.
|
|
7
|
+
*/
|
|
8
|
+
export const appWebhookEventKinds = [] as const
|
|
9
|
+
export type AppWebhookEventKind = (typeof appWebhookEventKinds)[number]
|
|
10
|
+
|
|
11
|
+
/** Per-kind payload shapes for the app kinds. There are none, so this contributes nothing to the
|
|
12
|
+
* intersection the framework builds (`Framework & App`). */
|
|
13
|
+
export type AppWebhookEventPayloadMap = Record<never, never>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { Container, Stack, Text, Title } from '@mantine/core'
|
|
4
|
+
import { useTranslations } from 'next-intl'
|
|
5
|
+
import type { ReactNode } from 'react'
|
|
6
|
+
|
|
7
|
+
export interface DashboardUser {
|
|
8
|
+
name: string
|
|
9
|
+
role: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Signed-in landing screen. Router-agnostic (ADR-0006); the cards are slotted in as children. */
|
|
13
|
+
export function DashboardScreen({ user, children }: { user: DashboardUser; children: ReactNode }) {
|
|
14
|
+
const t = useTranslations('dashboard')
|
|
15
|
+
return (
|
|
16
|
+
<Container component="main" size="sm" py="xl">
|
|
17
|
+
<Stack gap="lg">
|
|
18
|
+
<Title order={1}>{t('title')}</Title>
|
|
19
|
+
<Text c="gray.7" data-testid="signed-in-as">
|
|
20
|
+
{t('signedInAs', { name: user.name, role: user.role })}
|
|
21
|
+
</Text>
|
|
22
|
+
{children}
|
|
23
|
+
</Stack>
|
|
24
|
+
</Container>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { Button, Card, Group, Stack, Text, TextInput, Title } from '@mantine/core'
|
|
4
|
+
import { useTranslations } from 'next-intl'
|
|
5
|
+
import { useState } from 'react'
|
|
6
|
+
|
|
7
|
+
export interface Item {
|
|
8
|
+
id: string
|
|
9
|
+
title: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The app's ONE screen component: a list of the active team's items with an add box. Router-agnostic
|
|
14
|
+
* (ADR-0006) so the Next route and the `file://` static twin render the same component; `canCreate`
|
|
15
|
+
* comes from the same pure ability model on both sides.
|
|
16
|
+
*/
|
|
17
|
+
export function ItemsCard({
|
|
18
|
+
items,
|
|
19
|
+
onAdd,
|
|
20
|
+
canCreate = true,
|
|
21
|
+
}: {
|
|
22
|
+
items: Item[]
|
|
23
|
+
onAdd: (title: string) => Promise<void>
|
|
24
|
+
/** When false (restricted members), the add affordance is disabled and a read-only hint shows. */
|
|
25
|
+
canCreate?: boolean
|
|
26
|
+
}) {
|
|
27
|
+
const t = useTranslations('items')
|
|
28
|
+
const [draft, setDraft] = useState('')
|
|
29
|
+
const [busy, setBusy] = useState(false)
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<Card withBorder padding="lg" radius="md" data-testid="items-card">
|
|
33
|
+
<Stack gap="sm">
|
|
34
|
+
<Title order={2} size="h3">
|
|
35
|
+
{t('title')}
|
|
36
|
+
</Title>
|
|
37
|
+
<Text size="sm" c="gray.7">
|
|
38
|
+
{t('hint')}
|
|
39
|
+
</Text>
|
|
40
|
+
{items.length === 0 ? (
|
|
41
|
+
<Text c="gray.7" data-testid="items-empty">
|
|
42
|
+
{t('empty')}
|
|
43
|
+
</Text>
|
|
44
|
+
) : (
|
|
45
|
+
<Stack gap={4} data-testid="items-list">
|
|
46
|
+
{items.map((item) => (
|
|
47
|
+
<Text key={item.id} data-testid="item-row">
|
|
48
|
+
{item.title}
|
|
49
|
+
</Text>
|
|
50
|
+
))}
|
|
51
|
+
</Stack>
|
|
52
|
+
)}
|
|
53
|
+
<Group align="end" gap="sm">
|
|
54
|
+
<TextInput
|
|
55
|
+
label={t('addLabel')}
|
|
56
|
+
flex={1}
|
|
57
|
+
value={draft}
|
|
58
|
+
disabled={!canCreate}
|
|
59
|
+
data-testid="item-input"
|
|
60
|
+
onChange={(event) => setDraft(event.currentTarget.value)}
|
|
61
|
+
/>
|
|
62
|
+
<Button
|
|
63
|
+
loading={busy}
|
|
64
|
+
disabled={!canCreate || !draft.trim()}
|
|
65
|
+
data-testid="item-add"
|
|
66
|
+
onClick={() => {
|
|
67
|
+
setBusy(true)
|
|
68
|
+
onAdd(draft.trim())
|
|
69
|
+
.then(() => setDraft(''))
|
|
70
|
+
.finally(() => setBusy(false))
|
|
71
|
+
}}
|
|
72
|
+
>
|
|
73
|
+
{t('addButton')}
|
|
74
|
+
</Button>
|
|
75
|
+
</Group>
|
|
76
|
+
{!canCreate ? (
|
|
77
|
+
<Text size="sm" c="gray.7" data-testid="items-readonly-hint">
|
|
78
|
+
{t('readOnlyHint')}
|
|
79
|
+
</Text>
|
|
80
|
+
) : null}
|
|
81
|
+
</Stack>
|
|
82
|
+
</Card>
|
|
83
|
+
)
|
|
84
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { Anchor, Container, Stack, Text, Title } from '@mantine/core'
|
|
4
|
+
import { useTranslations } from 'next-intl'
|
|
5
|
+
|
|
6
|
+
/** Router-agnostic landing screen: no Next imports, so the app route and the static twin share it. */
|
|
7
|
+
export function WelcomeScreen({ dashboardHref }: { dashboardHref: string }) {
|
|
8
|
+
const t = useTranslations('welcome')
|
|
9
|
+
return (
|
|
10
|
+
<Container component="main" size="sm" py="xl">
|
|
11
|
+
<Stack gap="lg">
|
|
12
|
+
<Title order={1}>{t('title')}</Title>
|
|
13
|
+
<Text c="gray.7">{t('subtitle')}</Text>
|
|
14
|
+
<Anchor href={dashboardHref} data-testid="dashboard-link">
|
|
15
|
+
{t('dashboardLink')}
|
|
16
|
+
</Anchor>
|
|
17
|
+
</Stack>
|
|
18
|
+
</Container>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import { useTranslations } from 'next-intl'
|
|
3
|
+
import { defineAbilitiesFor } from '@sssb/kit/core/abilities'
|
|
4
|
+
import { isRestricted } from '@sssb/kit/core/roles'
|
|
5
|
+
import type { Locale } from '@sssb/kit/core/locale'
|
|
6
|
+
import { DemoShell } from '@sssb/kit/demo-static/shell'
|
|
7
|
+
import { useDemoWorld } from '@sssb/kit/demo-static/world'
|
|
8
|
+
import type { SeedPerson } from '@/seed'
|
|
9
|
+
import { staffOrgSlug } from '@/app-config/abilities'
|
|
10
|
+
import { DashboardScreen } from '@/components/dashboard-screen'
|
|
11
|
+
import { ItemsCard, type Item } from '@/components/items-card'
|
|
12
|
+
import { WelcomeScreen } from '@/components/welcome-screen'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The static demo's COMPOSITION ROOT — the `file://` twin of the server-side glue, and the same job:
|
|
16
|
+
* take the framework's simulated world (@sssb/kit/demo-static/world), add THIS app's own rows, hand the
|
|
17
|
+
* shell its screens, and get out of the way (ADR-0006, ADR-0012).
|
|
18
|
+
*
|
|
19
|
+
* This is what the twin costs an app that owns ONE table: a row type, a piece of state, an ability
|
|
20
|
+
* check and a card. Everything else on screen — routing, sign-in, the people, mail, jobs, schedules,
|
|
21
|
+
* webhooks, notifications, agreements, audit and the whole Simulator panel — is the package's.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/** In-memory twin of an `items` row — tenant + org scoped, so the static dashboard shows only the
|
|
25
|
+
* active team's items and gates create by the same pure ability model the real server runs. */
|
|
26
|
+
interface DemoItem extends Item {
|
|
27
|
+
tenantSlug: string
|
|
28
|
+
orgSlug: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function StaticDemoApp({ locale, onLocaleChange }: { locale: Locale; onLocaleChange: (l: Locale) => void }) {
|
|
32
|
+
const t = useTranslations('welcome')
|
|
33
|
+
const [items, setItems] = useState<DemoItem[]>([])
|
|
34
|
+
const world = useDemoWorld({ onReset: () => setItems([]) })
|
|
35
|
+
|
|
36
|
+
function renderDashboard(person: SeedPerson) {
|
|
37
|
+
const { tenant, activeOrgSlug } = world
|
|
38
|
+
// Same pure ability the real server runs — a restricted person gets a read-only card here too.
|
|
39
|
+
const ability = defineAbilitiesFor({
|
|
40
|
+
// The static shell's signed-in person IS a session, and only a stated session wields manage-all.
|
|
41
|
+
credential: { kind: 'session', id: null },
|
|
42
|
+
userId: person.id,
|
|
43
|
+
role: world.roleInOrg(person, activeOrgSlug),
|
|
44
|
+
restricted: isRestricted(person.restricted, world.roleInOrg(person, activeOrgSlug)),
|
|
45
|
+
activeOrgId: activeOrgSlug,
|
|
46
|
+
// Acting AS the operator org activates manage-all, exactly like abilityActorFromUser does
|
|
47
|
+
// server-side — genuine parity, no degrade.
|
|
48
|
+
manageAll: activeOrgSlug === staffOrgSlug,
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<DashboardScreen user={{ name: world.name, role: world.roleInOrg(person, activeOrgSlug) }}>
|
|
53
|
+
<ItemsCard
|
|
54
|
+
items={items.filter((i) => i.tenantSlug === tenant.slug && i.orgSlug === activeOrgSlug)}
|
|
55
|
+
canCreate={ability.can('create', { type: 'Item', orgId: activeOrgSlug })}
|
|
56
|
+
onAdd={async (title) => {
|
|
57
|
+
const id = crypto.randomUUID()
|
|
58
|
+
setItems((prev) => [{ id, title, tenantSlug: tenant.slug, orgSlug: activeOrgSlug }, ...prev])
|
|
59
|
+
}}
|
|
60
|
+
/>
|
|
61
|
+
</DashboardScreen>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<DemoShell
|
|
67
|
+
world={world}
|
|
68
|
+
locale={locale}
|
|
69
|
+
onLocaleChange={onLocaleChange}
|
|
70
|
+
appName={t('appName')}
|
|
71
|
+
welcome={<WelcomeScreen dashboardHref="#/dashboard" />}
|
|
72
|
+
nav={null}
|
|
73
|
+
dashboard={renderDashboard}
|
|
74
|
+
extraTabs={[]}
|
|
75
|
+
/>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>Starter — static demo</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="root"></div>
|
|
10
|
+
<script type="module" src="./main.tsx"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import '@mantine/core/styles.css'
|
|
2
|
+
import '../styles/index.css'
|
|
3
|
+
|
|
4
|
+
import { MantineProvider } from '@mantine/core'
|
|
5
|
+
import { NextIntlClientProvider } from 'next-intl'
|
|
6
|
+
import { StrictMode, useState } from 'react'
|
|
7
|
+
import { createRoot } from 'react-dom/client'
|
|
8
|
+
import type { Locale } from '@sssb/kit/core/locale'
|
|
9
|
+
import { mergeMessages, type MessageTree } from '@sssb/kit/i18n/messages'
|
|
10
|
+
import enFramework from '@sssb/kit/i18n/messages/en.json'
|
|
11
|
+
import esFramework from '@sssb/kit/i18n/messages/es.json'
|
|
12
|
+
import { getTenantTheme } from '@sssb/kit/theme'
|
|
13
|
+
import enApp from '../../messages/en.json'
|
|
14
|
+
import esApp from '../../messages/es.json'
|
|
15
|
+
import { tenants } from '../seed'
|
|
16
|
+
import { StaticDemoApp } from './app'
|
|
17
|
+
|
|
18
|
+
// The catalogs are physically split (ADR-0012), so the static shell composes both halves exactly like
|
|
19
|
+
// the server's request config does — statically imported, since a file:// bundle inlines everything.
|
|
20
|
+
const MESSAGES: Record<Locale, MessageTree> = {
|
|
21
|
+
en: mergeMessages(enFramework, enApp),
|
|
22
|
+
es: mergeMessages(esFramework, esApp),
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function Root() {
|
|
26
|
+
const [locale, setLocale] = useState<Locale>('en')
|
|
27
|
+
return (
|
|
28
|
+
<NextIntlClientProvider locale={locale} messages={MESSAGES[locale]}>
|
|
29
|
+
<MantineProvider theme={getTenantTheme(tenants[0]!.slug)}>
|
|
30
|
+
<StaticDemoApp locale={locale} onLocaleChange={setLocale} />
|
|
31
|
+
</MantineProvider>
|
|
32
|
+
</NextIntlClientProvider>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
createRoot(document.getElementById('root')!).render(
|
|
37
|
+
<StrictMode>
|
|
38
|
+
<Root />
|
|
39
|
+
</StrictMode>,
|
|
40
|
+
)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import createMiddleware from 'next-intl/middleware'
|
|
2
|
+
import { routing } from '@sssb/kit/i18n/routing'
|
|
3
|
+
|
|
4
|
+
// Next 16 renamed middleware.ts -> proxy.ts; next-intl's locale negotiation runs here.
|
|
5
|
+
export default createMiddleware(routing)
|
|
6
|
+
|
|
7
|
+
export const config = {
|
|
8
|
+
matcher: '/((?!api|_next|_vercel|.*\\..*).*)',
|
|
9
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { SeedAgreement, SeedJobSchedule, SeedOrg, SeedPerson, SeedTenant } from '@sssb/kit/seed/contracts'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This app's seed world — two tenants, two teams, three people.
|
|
5
|
+
*
|
|
6
|
+
* WHY IT LIVES INSIDE THE APP (and not in a `packages/*-seed` workspace like SSSB's reference
|
|
7
|
+
* app's `@app/seed`): the seed IS app content. The framework never imports it directly — it reads
|
|
8
|
+
* `@sssb/app-config/seed`, which re-exports this file — so its location is entirely the app's choice, and
|
|
9
|
+
* an app-local module is one fewer workspace package to keep. It also
|
|
10
|
+
* proves `@sssb/kit/seed/contracts` is a real published surface rather than a private arrangement with one
|
|
11
|
+
* package: this world fills the same contracts with no `@app/seed` anywhere in sight.
|
|
12
|
+
*
|
|
13
|
+
* Deliberately smaller than SSSB's reference app's: two tenants (the minimum that makes tenant isolation
|
|
14
|
+
* observable), one team each, and the roles the framework's own screens need to stay interesting —
|
|
15
|
+
* an admin who can invite, a plain member, and a restricted member whose authoring surface is
|
|
16
|
+
* reduced. `preAcceptedByAllInTenant` is unused because this app seeds no agreements.
|
|
17
|
+
*
|
|
18
|
+
* This content came with the generated app, and every sign-in picker lists all of it. Replace it with
|
|
19
|
+
* your own world rather than adding yours beside it (SSSB's adoption guide says what else the generated
|
|
20
|
+
* app still shows).
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export type {
|
|
24
|
+
PersonRole,
|
|
25
|
+
SeedAgreement,
|
|
26
|
+
SeedAgreementGating,
|
|
27
|
+
SeedAgreementKind,
|
|
28
|
+
SeedJobSchedule,
|
|
29
|
+
SeedMembership,
|
|
30
|
+
SeedOrg,
|
|
31
|
+
SeedPerson,
|
|
32
|
+
SeedScheduleSpec,
|
|
33
|
+
SeedTenant,
|
|
34
|
+
} from '@sssb/kit/seed/contracts'
|
|
35
|
+
|
|
36
|
+
export const tenants: SeedTenant[] = [
|
|
37
|
+
{ slug: 'northwind', name: 'Northwind', themePrimaryColor: 'teal', themeRadius: 'sm' },
|
|
38
|
+
{ slug: 'westgate', name: 'Westgate', themePrimaryColor: 'grape', themeRadius: 'xl' },
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* One team per tenant. `ops` doubles as the operator org (see `staffOrgSlug` in
|
|
43
|
+
* ../app-config/abilities.ts): the two slugs must agree, and this is the whole of that agreement.
|
|
44
|
+
*/
|
|
45
|
+
export const organizations: SeedOrg[] = [
|
|
46
|
+
{ slug: 'ops', name: 'Operations', tenantSlug: 'northwind' },
|
|
47
|
+
{ slug: 'field', name: 'Field Team', tenantSlug: 'westgate' },
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
export const people: SeedPerson[] = [
|
|
51
|
+
{
|
|
52
|
+
id: 'person-owner',
|
|
53
|
+
name: 'Nadia Owner',
|
|
54
|
+
email: 'nadia.owner@example.test',
|
|
55
|
+
locale: 'en',
|
|
56
|
+
tenantSlug: 'northwind',
|
|
57
|
+
memberships: [{ orgSlug: 'ops', role: 'admin' }],
|
|
58
|
+
restricted: false,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: 'person-teammate',
|
|
62
|
+
name: 'Tomás Compañero',
|
|
63
|
+
email: 'tomas.companero@example.test',
|
|
64
|
+
locale: 'es',
|
|
65
|
+
tenantSlug: 'northwind',
|
|
66
|
+
memberships: [{ orgSlug: 'ops', role: 'member' }],
|
|
67
|
+
restricted: false,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
// The other tenant, and the star of the tenancy e2e: whatever Nadia writes, Wes cannot see.
|
|
71
|
+
id: 'person-other-tenant',
|
|
72
|
+
name: 'Wes Westgate',
|
|
73
|
+
email: 'wes.westgate@example.test',
|
|
74
|
+
locale: 'en',
|
|
75
|
+
tenantSlug: 'westgate',
|
|
76
|
+
memberships: [{ orgSlug: 'field', role: 'admin' }],
|
|
77
|
+
restricted: false,
|
|
78
|
+
},
|
|
79
|
+
]
|
|
80
|
+
|
|
81
|
+
/** No agreements: the access-gate capability is registered-but-empty, like most of this app's seam. */
|
|
82
|
+
export const agreements: SeedAgreement[] = []
|
|
83
|
+
|
|
84
|
+
/** No recurring work: this app registers no job kinds, so nothing is scheduled. */
|
|
85
|
+
export const jobSchedules: SeedJobSchedule[] = []
|
|
86
|
+
|
|
87
|
+
export function findTenant(slug: string): SeedTenant | undefined {
|
|
88
|
+
return tenants.find((t) => t.slug === slug)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function findOrg(slug: string): SeedOrg | undefined {
|
|
92
|
+
return organizations.find((o) => o.slug === slug)
|
|
93
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { conformanceSuite } from '@sssb/kit/testing'
|
|
3
|
+
|
|
4
|
+
// SSSB's conformance suite, run against THIS app's seam and route tree (ADR-0014 part 3). Keep this file in the app's
|
|
5
|
+
// own tree: that is what makes the checks run by default. Leaving a check out takes a named opt-out with a reason,
|
|
6
|
+
// `optOut: { '<check id>': '<why>' }`; the ids are in @sssb/kit/testing/checks.json.
|
|
7
|
+
conformanceSuite({ appDir: path.resolve(import.meta.dirname, '..'), optOut: {} })
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@layer reset, base, tokens, recipes, utilities;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This app's own message catalog, read from disk at test time.
|
|
6
|
+
*
|
|
7
|
+
* Specs assert against THIS rather than against the product name as a literal, because the product name
|
|
8
|
+
* is the one thing an adopter is guaranteed to change (`pnpm create @sssb` names it). A spec that hard-codes it
|
|
9
|
+
* turns the rename into a broken gate.
|
|
10
|
+
*/
|
|
11
|
+
export function welcome(locale: string): { readonly title: string; readonly [key: string]: string } {
|
|
12
|
+
const file = path.resolve(__dirname, `../messages/${locale}.json`)
|
|
13
|
+
const catalog = JSON.parse(readFileSync(file, 'utf8')) as { welcome: { title: string; [key: string]: string } }
|
|
14
|
+
return catalog.welcome
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { contractSuite } from '@sssb/kit/testing/contract'
|
|
2
|
+
import { portFor } from '@sssb/tools/ports'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The "fakes can't drift" job for this app: the SAME migrations + RLS proof suite that runs on pglite in unit
|
|
6
|
+
* tests, executed against REAL Postgres, in a database of this app's own (`<slug>_contract`), by a non-superuser
|
|
7
|
+
* owner, by a superuser, and over the RDS Data API transport through its emulator. Everything is the contract
|
|
8
|
+
* runner's (`@sssb/kit/testing/contract`), which reads the app through its seam; this file only says where the
|
|
9
|
+
* embedded Postgres listens and which checks, if any, the app leaves out (`optOut: { '<check id>': '<why>' }`).
|
|
10
|
+
*
|
|
11
|
+
* Run via `pnpm test:contract` — deliberately not part of the fast unit suite. Locally that's embedded-postgres
|
|
12
|
+
* binaries (no docker on the dev VM); in CI, CONTRACT_DATABASE_URL names a postgres service container.
|
|
13
|
+
*/
|
|
14
|
+
contractSuite({ port: portFor('contractPg'), optOut: {} })
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { expect, test } from '@playwright/test'
|
|
3
|
+
import { welcome } from '../catalog'
|
|
4
|
+
|
|
5
|
+
const indexUrl = `file://${path.resolve(__dirname, '../../dist-demo/index.html')}`
|
|
6
|
+
|
|
7
|
+
test('the static shell signs in and lists an item, with the framework panel intact', async ({ page }) => {
|
|
8
|
+
await page.goto(indexUrl)
|
|
9
|
+
// Asserted against the catalog, not the product name — `pnpm create @sssb` renames the app, and this
|
|
10
|
+
// spec is the first thing that would have broken if it hard-coded the title.
|
|
11
|
+
await expect(page.getByRole('heading', { level: 1 })).toContainText(welcome('en').title)
|
|
12
|
+
|
|
13
|
+
await page.getByTestId('dashboard-link').click()
|
|
14
|
+
await page.getByTestId('person-person-owner').click()
|
|
15
|
+
await expect(page.getByTestId('signed-in-as')).toContainText('Nadia Owner')
|
|
16
|
+
|
|
17
|
+
await page.getByTestId('item-input').fill('write the first item')
|
|
18
|
+
await page.getByTestId('item-add').click()
|
|
19
|
+
await expect(page.getByTestId('items-list')).toContainText('write the first item')
|
|
20
|
+
|
|
21
|
+
// The whole Simulator panel comes from the package: an app that registers no tabs still gets the
|
|
22
|
+
// framework's, and switching people still works.
|
|
23
|
+
await page.getByTestId('simulator-pill').click()
|
|
24
|
+
await expect(page.getByTestId('simulator-panel')).toBeVisible()
|
|
25
|
+
await page.getByTestId('people-person-teammate').click()
|
|
26
|
+
await expect(page.getByTestId('signed-in-as')).toContainText('Tomás Compañero')
|
|
27
|
+
|
|
28
|
+
// The tours off-switch: this app registers `tours: []` (src/app-config/tours.ts), so the Tours tab
|
|
29
|
+
// does not exist at all — an adopter who wants no scripted walkthrough pays nothing for the one
|
|
30
|
+
// SSSB's reference app ships.
|
|
31
|
+
await expect(page.getByTestId('simulator-tab-tours')).toHaveCount(0)
|
|
32
|
+
})
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { expect, test, type Page } from '@playwright/test'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This app's whole e2e budget, spent on the one claim this app exists to prove: an item written
|
|
5
|
+
* in one tenant is invisible from the other, through the entire stack (UI → route → withTenant → RLS
|
|
6
|
+
* on pglite).
|
|
7
|
+
*
|
|
8
|
+
* This app has no Simulator panel, so crossing tenants is done the way a real user would — sign out,
|
|
9
|
+
* sign in as somebody whose home tenant differs.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
async function signInAs(page: Page, personId: string) {
|
|
13
|
+
await page.goto('/en/signin')
|
|
14
|
+
await page.getByTestId(`person-${personId}`).click()
|
|
15
|
+
await page.waitForURL('**/dashboard')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function signOut(page: Page) {
|
|
19
|
+
await page.getByTestId('user-menu').click()
|
|
20
|
+
await page.getByTestId('menu-signout').click()
|
|
21
|
+
await page.waitForURL(/\/en\/?$/)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Hydration-safe entry: right after a navigation, filling the controlled input can beat React
|
|
25
|
+
* hydration, so the DOM has the text but state does not and the button stays disabled. */
|
|
26
|
+
async function addItem(page: Page, title: string) {
|
|
27
|
+
await expect(async () => {
|
|
28
|
+
await page.getByTestId('item-input').fill(title)
|
|
29
|
+
await expect(page.getByTestId('item-add')).toBeEnabled({ timeout: 1_000 })
|
|
30
|
+
}).toPass()
|
|
31
|
+
await page.getByTestId('item-add').click()
|
|
32
|
+
await expect(page.getByTestId('items-list')).toContainText(title)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
test('an item created in one tenant is invisible from the other', async ({ page }) => {
|
|
36
|
+
const secret = `northwind-item-${Date.now()}`
|
|
37
|
+
|
|
38
|
+
// Nadia's home tenant is northwind.
|
|
39
|
+
await signInAs(page, 'person-owner')
|
|
40
|
+
await expect(page.getByTestId('active-tenant')).toHaveText('Northwind')
|
|
41
|
+
await addItem(page, secret)
|
|
42
|
+
|
|
43
|
+
// Reload proves the row survived a round trip through Postgres rather than living in React state.
|
|
44
|
+
await page.reload()
|
|
45
|
+
await expect(page.getByTestId('items-list')).toContainText(secret)
|
|
46
|
+
|
|
47
|
+
// Cross to the other tenant: Wes must not see it, and his own view starts empty.
|
|
48
|
+
await signOut(page)
|
|
49
|
+
await signInAs(page, 'person-other-tenant')
|
|
50
|
+
await expect(page.getByTestId('active-tenant')).toHaveText('Westgate')
|
|
51
|
+
await expect(page.getByTestId('items-card')).toBeVisible()
|
|
52
|
+
await expect(page.getByTestId('items-card')).not.toContainText(secret)
|
|
53
|
+
|
|
54
|
+
// ...and back again: Nadia's item is still there.
|
|
55
|
+
await signOut(page)
|
|
56
|
+
await signInAs(page, 'person-owner')
|
|
57
|
+
await expect(page.getByTestId('items-list')).toContainText(secret)
|
|
58
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@sssb/tools/tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"incremental": true,
|
|
5
|
+
"paths": {
|
|
6
|
+
"@/*": ["./src/*"],
|
|
7
|
+
"@sssb/app-config/*": ["./src/app-config/*"],
|
|
8
|
+
"@sssb/kit/*": ["../../packages/kit/src/*"]
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"include": [
|
|
12
|
+
"next-env.d.ts",
|
|
13
|
+
"src/**/*.ts",
|
|
14
|
+
"src/**/*.tsx",
|
|
15
|
+
"tests/**/*.ts",
|
|
16
|
+
".next/types/**/*.ts",
|
|
17
|
+
"*.ts",
|
|
18
|
+
"config/**/*.ts",
|
|
19
|
+
".next/dev/types/**/*.ts",
|
|
20
|
+
"../../packages/kit/src/**/*.ts",
|
|
21
|
+
"../../packages/kit/src/**/*.tsx"
|
|
22
|
+
],
|
|
23
|
+
"exclude": [
|
|
24
|
+
"node_modules",
|
|
25
|
+
"../../packages/kit/src/**/*.test.ts",
|
|
26
|
+
"../../packages/kit/src/**/*.test.tsx",
|
|
27
|
+
"../../packages/kit/src/**/*.stories.tsx"
|
|
28
|
+
]
|
|
29
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { staticDemoConfig } from '@sssb/tools/vite'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Builds the hash-routed static demo shell (src/demo-static) that runs from file://, as one file. The preset
|
|
5
|
+
* (@sssb/tools/vite) passes this app's own seam explicitly, which is what makes the framework bundle resolve against
|
|
6
|
+
* this app's registrations rather than any other app's.
|
|
7
|
+
*/
|
|
8
|
+
export default staticDemoConfig({ appDir: __dirname })
|