@sssb/kit 0.0.0 → 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/dist/core/webhook-hmac.d.ts +69 -0
- package/dist/release.json +1 -0
- package/dist/testing/e2e.d.ts +15 -0
- package/dist/testing/e2e.js +195 -0
- package/package.json +209 -5
- package/src/adapters/README.md +6 -0
- package/src/adapters/dev-server.ts +21 -0
- package/src/adapters/fake/agreements.ts +81 -0
- package/src/adapters/fake/analytics.ts +93 -0
- package/src/adapters/fake/atomic-write.ts +161 -0
- package/src/adapters/fake/audit.ts +58 -0
- package/src/adapters/fake/auth.ts +312 -0
- package/src/adapters/fake/clock.ts +54 -0
- package/src/adapters/fake/data-dir.ts +27 -0
- package/src/adapters/fake/db.ts +88 -0
- package/src/adapters/fake/email.ts +46 -0
- package/src/adapters/fake/jobs.ts +270 -0
- package/src/adapters/fake/llm.ts +230 -0
- package/src/adapters/fake/pglite-dialect.ts +124 -0
- package/src/adapters/fake/service-auth.ts +145 -0
- package/src/adapters/fake/simulator-admin.ts +203 -0
- package/src/adapters/fake/simulator.ts +94 -0
- package/src/adapters/fake/sms.ts +43 -0
- package/src/adapters/fake/storage.ts +288 -0
- package/src/adapters/fake/webhooks.ts +98 -0
- package/src/adapters/index.ts +115 -0
- package/src/adapters/real/accept-invite-form.tsx +77 -0
- package/src/adapters/real/analytics.ts +28 -0
- package/src/adapters/real/auth.ts +216 -0
- package/src/adapters/real/contract-data-api.ts +104 -0
- package/src/adapters/real/contract-postgres.ts +167 -0
- package/src/adapters/real/database-transport.ts +34 -0
- package/src/adapters/real/db-data-api.ts +61 -0
- package/src/adapters/real/db.ts +88 -0
- package/src/adapters/real/email.ts +22 -0
- package/src/adapters/real/index.ts +89 -0
- package/src/adapters/real/jobs.ts +32 -0
- package/src/adapters/real/llm.ts +108 -0
- package/src/adapters/real/migrate-handler.ts +66 -0
- package/src/adapters/real/providers.tsx +12 -0
- package/src/adapters/real/rds-data-codec.ts +508 -0
- package/src/adapters/real/rds-data-dialect.ts +470 -0
- package/src/adapters/real/rds-data-emulator.ts +351 -0
- package/src/adapters/real/s3-storage.ts +233 -0
- package/src/adapters/real/sign-in-form.tsx +59 -0
- package/src/adapters/real/storage.ts +10 -0
- package/src/adapters/sentry/baseline.ts +90 -0
- package/src/adapters/sentry/client.ts +17 -0
- package/src/adapters/sentry/init.ts +17 -0
- package/src/authz/app-exemptions.ts +226 -0
- package/src/authz/authorize.ts +214 -0
- package/src/authz/route-policy.ts +153 -0
- package/src/authz/route-scan.ts +1516 -0
- package/src/components/agreements/acceptances-section.tsx +55 -0
- package/src/components/agreements/agreement-advisory-banner.tsx +33 -0
- package/src/components/agreements/agreement-body.tsx +34 -0
- package/src/components/agreements/agreement-gate.tsx +45 -0
- package/src/components/app-header.tsx +45 -0
- package/src/components/auth/accept-invite-screen.tsx +126 -0
- package/src/components/auth/auth-icons.tsx +68 -0
- package/src/components/auth/org-switcher.tsx +76 -0
- package/src/components/auth/people-picker.tsx +50 -0
- package/src/components/auth/preview-row.tsx +64 -0
- package/src/components/auth/sign-in-screen.tsx +24 -0
- package/src/components/auth/user-menu.tsx +64 -0
- package/src/components/demo-badge.tsx +20 -0
- package/src/components/demo-banner.tsx +14 -0
- package/src/components/gates/gate-interstitial.tsx +23 -0
- package/src/components/job-timeline.tsx +64 -0
- package/src/components/notifications/notification-bell.tsx +120 -0
- package/src/components/notifications/notification-prefs-section.tsx +112 -0
- package/src/components/org-screen.tsx +197 -0
- package/src/components/profile-screen.tsx +100 -0
- package/src/components/simulator/actor-runtime.ts +180 -0
- package/src/components/simulator/actor-shell.tsx +275 -0
- package/src/components/simulator/actors-app.tsx +119 -0
- package/src/components/simulator/errors-app.tsx +84 -0
- package/src/components/simulator/events-app.tsx +210 -0
- package/src/components/simulator/format-when.ts +20 -0
- package/src/components/simulator/hooks-app.tsx +319 -0
- package/src/components/simulator/inbound-app.tsx +210 -0
- package/src/components/simulator/jobs-app.tsx +471 -0
- package/src/components/simulator/mail-app.tsx +290 -0
- package/src/components/simulator/messages-app.tsx +64 -0
- package/src/components/simulator/people-app.tsx +140 -0
- package/src/components/simulator/people-dimensions.ts +16 -0
- package/src/components/simulator/simulator-panel.tsx +716 -0
- package/src/components/simulator/snapshots-app.tsx +398 -0
- package/src/components/simulator/tab-mount.ts +25 -0
- package/src/components/simulator/tours-app.tsx +105 -0
- package/src/components/webhook-endpoints-card.tsx +172 -0
- package/src/core/abilities.ts +459 -0
- package/src/core/agreements.ts +139 -0
- package/src/core/gates.ts +157 -0
- package/src/core/greeting.ts +11 -0
- package/src/core/inbound-email.ts +129 -0
- package/src/core/jobs.ts +51 -0
- package/src/core/keyset.ts +227 -0
- package/src/core/llm-models.ts +10 -0
- package/src/core/locale.ts +3 -0
- package/src/core/notifications.ts +182 -0
- package/src/core/presets.ts +456 -0
- package/src/core/roles.ts +47 -0
- package/src/core/schedules.ts +147 -0
- package/src/core/standard-schema.ts +56 -0
- package/src/core/state-machine.ts +43 -0
- package/src/core/webhook-events.ts +86 -0
- package/src/core/webhook-hmac.ts +248 -0
- package/src/core/webhook-signing.ts +27 -0
- package/src/cutover/rows.json +101 -0
- package/src/db/agreements.ts +176 -0
- package/src/db/app-roles.ts +197 -0
- package/src/db/audit.ts +356 -0
- package/src/db/inbound-email.ts +145 -0
- package/src/db/jobs.ts +300 -0
- package/src/db/jsonb.ts +18 -0
- package/src/db/keyset.ts +179 -0
- package/src/db/migrate.ts +73 -0
- package/src/db/migrations/0001_tenants.ts +25 -0
- package/src/db/migrations/0003_organizations.ts +27 -0
- package/src/db/migrations/0004_jobs.ts +64 -0
- package/src/db/migrations/0005_service_keys.ts +33 -0
- package/src/db/migrations/0008_audit_events.ts +51 -0
- package/src/db/migrations/0009_job_schedules.ts +52 -0
- package/src/db/migrations/0010_webhooks.ts +100 -0
- package/src/db/migrations/0011_notifications.ts +98 -0
- package/src/db/migrations/0012_inbound_email.ts +74 -0
- package/src/db/migrations/0013_agreements.ts +98 -0
- package/src/db/migrations/0014_audit_credential.ts +29 -0
- package/src/db/migrations/0015_app_user_grant.ts +67 -0
- package/src/db/migrations/0016_audit_detail.ts +26 -0
- package/src/db/migrations/index.ts +49 -0
- package/src/db/notifications.ts +185 -0
- package/src/db/org-lookup.ts +104 -0
- package/src/db/owner-pass.ts +252 -0
- package/src/db/rls-coverage.ts +259 -0
- package/src/db/rls-proof-runner.ts +94 -0
- package/src/db/rls-proofs.ts +1176 -0
- package/src/db/schedules.ts +187 -0
- package/src/db/schema.ts +235 -0
- package/src/db/seed.ts +176 -0
- package/src/db/service-keys.ts +50 -0
- package/src/db/tenant-lookup.ts +13 -0
- package/src/db/webhooks.ts +483 -0
- package/src/db/with-tenant.ts +26 -0
- package/src/demo-static/actor-drivers.ts +161 -0
- package/src/demo-static/assistant-replay.ts +61 -0
- package/src/demo-static/contracts.ts +282 -0
- package/src/demo-static/email-html.ts +58 -0
- package/src/demo-static/hash-route.ts +24 -0
- package/src/demo-static/rows.ts +105 -0
- package/src/demo-static/shell.tsx +440 -0
- package/src/demo-static/tour/contracts.ts +97 -0
- package/src/demo-static/tour/driver.ts +320 -0
- package/src/demo-static/tour/tour-overlay.tsx +226 -0
- package/src/demo-static/tour/use-tours.tsx +394 -0
- package/src/demo-static/world.ts +1479 -0
- package/src/email/send.ts +12 -0
- package/src/email/templates/digest-email.tsx +61 -0
- package/src/email/templates/invite-email.tsx +57 -0
- package/src/email/templates/notification-email.tsx +39 -0
- package/src/guide.md +118 -0
- package/src/i18n/messages/en.json +373 -0
- package/src/i18n/messages/es.json +373 -0
- package/src/i18n/messages.ts +34 -0
- package/src/i18n/namespaces.ts +32 -0
- package/src/i18n/request.ts +34 -0
- package/src/i18n/routing.ts +7 -0
- package/src/inbound-email/handlers.ts +67 -0
- package/src/inbound-email/intake.ts +180 -0
- package/src/jobs/digest-email.ts +97 -0
- package/src/observability/scrub.ts +42 -0
- package/src/ports/README.md +8 -0
- package/src/ports/analytics.ts +8 -0
- package/src/ports/auth.ts +87 -0
- package/src/ports/db.ts +27 -0
- package/src/ports/email.ts +14 -0
- package/src/ports/errors.ts +46 -0
- package/src/ports/jobs.ts +48 -0
- package/src/ports/llm.ts +85 -0
- package/src/ports/storage.ts +132 -0
- package/src/seed/contracts.ts +129 -0
- package/src/server-lib/assistant.ts +45 -0
- package/src/server-lib/defer.ts +53 -0
- package/src/server-lib/demo-presets.ts +85 -0
- package/src/server-lib/invite.ts +92 -0
- package/src/server-lib/notify-deps.ts +15 -0
- package/src/server-lib/notify.ts +252 -0
- package/src/server-lib/preset-operations.ts +121 -0
- package/src/server-lib/scheduled-tick.ts +38 -0
- package/src/server-lib/sms.ts +43 -0
- package/src/server-lib/webhook-dispatch.ts +75 -0
- package/src/service-auth/mailgun.ts +70 -0
- package/src/service-auth/verify.ts +73 -0
- package/src/service-auth/webhook.ts +60 -0
- package/src/testing/checks.json +103 -0
- package/src/testing/conformance/authz.ts +46 -0
- package/src/testing/conformance/db.ts +258 -0
- package/src/testing/conformance/demo-presets.ts +295 -0
- package/src/testing/conformance/i18n.ts +80 -0
- package/src/testing/conformance/register.ts +200 -0
- package/src/testing/conformance/seam-map.ts +205 -0
- package/src/testing/conformance/suite.ts +59 -0
- package/src/testing/conformance/types.ts +18 -0
- package/src/testing/contract.ts +200 -0
- package/src/testing/e2e.ts +15 -0
- package/src/testing/index.ts +6 -0
- package/src/testing/seam-specifiers.json +22 -0
- package/src/testing/tmp-dir-marker.d.mts +4 -0
- package/src/testing/tmp-dir-marker.mjs +5 -0
- package/src/testing/tmp-dir.ts +182 -0
- package/src/theme.ts +28 -0
- package/README.md +0 -3
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { render } from '@react-email/render'
|
|
2
|
+
import type { ReactElement } from 'react'
|
|
3
|
+
import type { EmailPort } from '../ports/email'
|
|
4
|
+
|
|
5
|
+
/** Renders a react-email template to html+text and hands it to whichever email adapter is wired. */
|
|
6
|
+
export async function sendTemplate(
|
|
7
|
+
port: EmailPort,
|
|
8
|
+
options: { to: string; subject: string; template: ReactElement },
|
|
9
|
+
): Promise<void> {
|
|
10
|
+
const [html, text] = await Promise.all([render(options.template), render(options.template, { plainText: true })])
|
|
11
|
+
await port.send({ to: options.to, subject: options.subject, html, text })
|
|
12
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Body, Container, Head, Heading, Html, Preview, Section, Text } from '@react-email/components'
|
|
2
|
+
|
|
3
|
+
interface DigestEmailLabels {
|
|
4
|
+
preview: string
|
|
5
|
+
heading: string
|
|
6
|
+
intro: string
|
|
7
|
+
/** Already-localized "You have N items." (count interpolated by the caller — the app names them). */
|
|
8
|
+
countLine: string
|
|
9
|
+
recentHeading: string
|
|
10
|
+
/** Shown instead of the recent list when the team has nothing to digest. */
|
|
11
|
+
emptyLine: string
|
|
12
|
+
footer: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface DigestEmailProps {
|
|
16
|
+
/** All copy arrives pre-localized from the caller's next-intl lookup (`email` namespace) —
|
|
17
|
+
* templates render outside a request context, so they never call next-intl themselves. */
|
|
18
|
+
labels: DigestEmailLabels
|
|
19
|
+
/** Recent item snippets — user DATA, not UI copy, so they pass through verbatim. */
|
|
20
|
+
recentTitles: string[]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The scheduled org digest, previewed in Ladle, rendered by packages/kit/src/email/send.ts. Structurally
|
|
25
|
+
* a sibling of invite-email.tsx: a `labels` bag of pre-localized strings plus structured data (the
|
|
26
|
+
* recent-item snippets). The Simulator Mail tab renders it end-to-end when a schedule fires.
|
|
27
|
+
*/
|
|
28
|
+
export function DigestEmail({ labels, recentTitles }: DigestEmailProps) {
|
|
29
|
+
return (
|
|
30
|
+
<Html lang="en">
|
|
31
|
+
<Head />
|
|
32
|
+
<Preview>{labels.preview}</Preview>
|
|
33
|
+
<Body style={{ backgroundColor: '#f4f4f5', fontFamily: 'sans-serif' }}>
|
|
34
|
+
<Container style={{ backgroundColor: '#ffffff', borderRadius: 8, margin: '40px auto', padding: 24 }}>
|
|
35
|
+
<Heading as="h2">{labels.heading}</Heading>
|
|
36
|
+
<Section>
|
|
37
|
+
<Text>{labels.intro}</Text>
|
|
38
|
+
<Text style={{ fontWeight: 600 }}>{labels.countLine}</Text>
|
|
39
|
+
{recentTitles.length > 0 ? (
|
|
40
|
+
<Section>
|
|
41
|
+
<Text style={{ fontWeight: 600, marginBottom: 4 }}>{labels.recentHeading}</Text>
|
|
42
|
+
{recentTitles.map((title, index) => (
|
|
43
|
+
<Text
|
|
44
|
+
// Snippets can repeat, so index-suffix the key (order is stable).
|
|
45
|
+
key={`${index}-${title}`}
|
|
46
|
+
style={{ margin: '2px 0', color: '#333333' }}
|
|
47
|
+
>
|
|
48
|
+
{`• ${title}`}
|
|
49
|
+
</Text>
|
|
50
|
+
))}
|
|
51
|
+
</Section>
|
|
52
|
+
) : (
|
|
53
|
+
<Text style={{ color: '#666666' }}>{labels.emptyLine}</Text>
|
|
54
|
+
)}
|
|
55
|
+
<Text style={{ fontSize: 12, color: '#666666', marginTop: 16 }}>{labels.footer}</Text>
|
|
56
|
+
</Section>
|
|
57
|
+
</Container>
|
|
58
|
+
</Body>
|
|
59
|
+
</Html>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Body, Button, Container, Head, Heading, Html, Preview, Section, Text } from '@react-email/components'
|
|
2
|
+
|
|
3
|
+
interface InviteEmailLabels {
|
|
4
|
+
preview: string
|
|
5
|
+
heading: string
|
|
6
|
+
body: string
|
|
7
|
+
button: string
|
|
8
|
+
linkFallback: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface InviteEmailProps {
|
|
12
|
+
/** All copy arrives pre-localized from the caller's next-intl lookup (`email` namespace) —
|
|
13
|
+
* templates render outside a request context, so they never call next-intl themselves. */
|
|
14
|
+
labels: InviteEmailLabels
|
|
15
|
+
/** Built by the caller (src/app/api/org/invite/route.ts) from the invite id and request origin. */
|
|
16
|
+
acceptUrl: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Templates are react-email components (ADR-0011); previewed in Ladle, rendered by
|
|
21
|
+
* packages/kit/src/email/send.ts. `acceptUrl` is the real accept-invitation entrypoint (src/app/[locale]/accept-invite) —
|
|
22
|
+
* the Simulator Mail tab renders this end-to-end (clicks inside the reading pane bridge out to
|
|
23
|
+
* the app's navigation policy; the extracted link rows carry a copy button).
|
|
24
|
+
*/
|
|
25
|
+
export function InviteEmail({ labels, acceptUrl }: InviteEmailProps) {
|
|
26
|
+
return (
|
|
27
|
+
<Html lang="en">
|
|
28
|
+
<Head />
|
|
29
|
+
<Preview>{labels.preview}</Preview>
|
|
30
|
+
<Body style={{ backgroundColor: '#f4f4f5', fontFamily: 'sans-serif' }}>
|
|
31
|
+
<Container style={{ backgroundColor: '#ffffff', borderRadius: 8, margin: '40px auto', padding: 24 }}>
|
|
32
|
+
<Heading as="h2">{labels.heading}</Heading>
|
|
33
|
+
<Section>
|
|
34
|
+
<Text>{labels.body}</Text>
|
|
35
|
+
<Section style={{ textAlign: 'center', margin: '24px 0' }}>
|
|
36
|
+
<Button
|
|
37
|
+
href={acceptUrl}
|
|
38
|
+
style={{
|
|
39
|
+
backgroundColor: '#4c6ef5',
|
|
40
|
+
color: '#ffffff',
|
|
41
|
+
borderRadius: 6,
|
|
42
|
+
padding: '12px 24px',
|
|
43
|
+
}}
|
|
44
|
+
>
|
|
45
|
+
{labels.button}
|
|
46
|
+
</Button>
|
|
47
|
+
</Section>
|
|
48
|
+
<Text style={{ fontSize: 12, color: '#666666' }}>
|
|
49
|
+
{`${labels.linkFallback} `}
|
|
50
|
+
{acceptUrl}
|
|
51
|
+
</Text>
|
|
52
|
+
</Section>
|
|
53
|
+
</Container>
|
|
54
|
+
</Body>
|
|
55
|
+
</Html>
|
|
56
|
+
)
|
|
57
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Body, Container, Head, Heading, Html, Preview, Section, Text } from '@react-email/components'
|
|
2
|
+
|
|
3
|
+
interface NotificationEmailLabels {
|
|
4
|
+
preview: string
|
|
5
|
+
heading: string
|
|
6
|
+
body: string
|
|
7
|
+
footer: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface NotificationEmailProps {
|
|
11
|
+
/** All copy arrives pre-localized from the caller's next-intl lookup (`notifications` namespace) —
|
|
12
|
+
* templates render outside a request context, so they never call next-intl themselves. ONE generic
|
|
13
|
+
* template serves every NotificationKind; the kind decides only which labels the caller passes. */
|
|
14
|
+
labels: NotificationEmailLabels
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The generic notification email — the `email` fan-out channel. Deliberately ONE template
|
|
19
|
+
* with kind-based copy rather than a template per kind: the channel is the reusable thing, and a new
|
|
20
|
+
* NotificationKind ships copy in the i18n `notifications` namespace, not a new react-email file.
|
|
21
|
+
* Previewed in Ladle, rendered by packages/kit/src/email/send.ts, caught by the Simulator Mail tab.
|
|
22
|
+
*/
|
|
23
|
+
export function NotificationEmail({ labels }: NotificationEmailProps) {
|
|
24
|
+
return (
|
|
25
|
+
<Html lang="en">
|
|
26
|
+
<Head />
|
|
27
|
+
<Preview>{labels.preview}</Preview>
|
|
28
|
+
<Body style={{ backgroundColor: '#f4f4f5', fontFamily: 'sans-serif' }}>
|
|
29
|
+
<Container style={{ backgroundColor: '#ffffff', borderRadius: 8, margin: '40px auto', padding: 24 }}>
|
|
30
|
+
<Heading as="h2">{labels.heading}</Heading>
|
|
31
|
+
<Section>
|
|
32
|
+
<Text>{labels.body}</Text>
|
|
33
|
+
<Text style={{ fontSize: 12, color: '#666666' }}>{labels.footer}</Text>
|
|
34
|
+
</Section>
|
|
35
|
+
</Container>
|
|
36
|
+
</Body>
|
|
37
|
+
</Html>
|
|
38
|
+
)
|
|
39
|
+
}
|
package/src/guide.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# SSSB app guide
|
|
2
|
+
|
|
3
|
+
The rules for an app built on SSSB (`@sssb/kit`). Paths are relative to the app's own directory, the package that
|
|
4
|
+
depends on `@sssb/kit`. `pnpm exec sssb guide` copies this file into your repository under a hash stamp: edit nothing in
|
|
5
|
+
the copy, rerun the command after an upgrade, and review the diff. Most rules are enforced by the `@sssb/eslint-plugin`
|
|
6
|
+
preset, SSSB's conformance suite or `sssb doctor`; keep the rest by hand.
|
|
7
|
+
|
|
8
|
+
## The seam
|
|
9
|
+
|
|
10
|
+
- The app extends the framework only through the `@sssb/app-config/*` seam, the modules in `src/app-config/`.
|
|
11
|
+
Register new subjects, jobs, event kinds, tables and migrations there. Never edit or patch a framework base union or
|
|
12
|
+
registry.
|
|
13
|
+
- Import `@sssb/kit` only by a published subpath, a key of its `exports` map. Everything else in the package is
|
|
14
|
+
internal.
|
|
15
|
+
|
|
16
|
+
## Vendors, environment and parameters
|
|
17
|
+
|
|
18
|
+
- Vendor SDKs (`@clerk/*`, `@aws-sdk/*`, `@anthropic-ai/*`, `@sentry/*`, `posthog-*`, `mailgun.js`, `pg`) are
|
|
19
|
+
imported only in an app's real adapters, `adapters/real/` (and in what runs outside the request path: `next.config.*`
|
|
20
|
+
for the Sentry build plugin, the contract tests in `tests/contract/`, the deployment in `infra/`). Everything else
|
|
21
|
+
codes against a port: `@sssb/kit/ports/*`, or a port the app owns. SSSB's own real adapters
|
|
22
|
+
(`@sssb/kit/adapters/real/*`) load their SDK too, so every module of the app outside `adapters/real/` (which may
|
|
23
|
+
build on one) and the vendor carve-outs above, tests, stories and scripts included, reaches one only with `import()`
|
|
24
|
+
when `!isSimulated`, never by an import declaration (re-exports included; a type-only `import type` or
|
|
25
|
+
`export type`, which loads nothing, is allowed).
|
|
26
|
+
- A vendor SSSB has no port for gets a port the app owns, under `src`: the port module (`ports/<name>.ts`), a registry
|
|
27
|
+
(`adapters/index.ts`) that takes the run mode from SSSB's `isSimulated` (`@sssb/kit/adapters/index`) and loads the
|
|
28
|
+
real adapter only with `import()`, a fake, and the real adapter in `adapters/real/`, the one directory that imports
|
|
29
|
+
the SDK. Nothing imports `adapters/real/` statically, and a fake never imports it at all. Add the SDK to the ban in
|
|
30
|
+
the app's own `package.json`: `"sssb": { "vendors": ["stripe", "stripe/*"] }`.
|
|
31
|
+
- Read `process.env` only in `adapters/real/` (and never the run mode there), in Next's instrumentation hooks, in
|
|
32
|
+
tests and in the app-root tool configs (Playwright, Vite). Every other module imports the resolved value: deployment
|
|
33
|
+
parameters from `config/params.ts`, the run mode from `isSimulated`.
|
|
34
|
+
- Deployment and service parameters exist only in `config/params.ts`. Secret values never enter the repository.
|
|
35
|
+
- `pnpm dev` stays hermetic: no docker, no credentials, no network. Never add `next/font/google`, telemetry, or
|
|
36
|
+
anything that phones home.
|
|
37
|
+
- Anything that needs real credentials, accounts or money is a row in the workspace's cutover checklist, never a
|
|
38
|
+
blocker: the app boots, and is tested, without it.
|
|
39
|
+
|
|
40
|
+
## Data
|
|
41
|
+
|
|
42
|
+
- Tenant-scoped queries run only inside `db.withTenant()`. `getDb()` is banned in every module under `src`
|
|
43
|
+
(`sssb/no-raw-db-handle`); tests are exempt, except a route's or a screen's. A module that truly needs the raw
|
|
44
|
+
client is a named entry, with its reason, in the app's `lint-exceptions.mjs`: a path relative to the app, one
|
|
45
|
+
existing file per entry, never a glob or a directory.
|
|
46
|
+
- A list that can grow pages through `@sssb/kit/db/keyset`, never a hand-rolled `LIMIT`/`OFFSET`. Parse the cursor
|
|
47
|
+
with `parseDbKeysetCursor` and answer 400 when it is `invalid`; clamp the page size on the server; fix the
|
|
48
|
+
`orderBy` column per route, never from the client.
|
|
49
|
+
- App migrations live in `src/app-config/db/migrations/`, numbered 1001 and up (0001–0999 are the framework's), and
|
|
50
|
+
are listed in `src/app-config/db/migrations/index.ts`. A new tenant table copies the RLS pattern of
|
|
51
|
+
`src/app-config/db/migrations/1001_items.ts`, the generated app's first migration (once you have removed it, read it
|
|
52
|
+
in SSSB's repository at your release), and its isolation proofs go in `src/app-config/db/rls-proofs.ts`.
|
|
53
|
+
- A role is cluster-wide, so a migration that creates one of the app's own creates it only where it does not exist
|
|
54
|
+
yet: a `DO` block that runs `CREATE ROLE reviewer NOLOGIN` only when
|
|
55
|
+
`NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'reviewer')`. Keep it an ordinary role, before and after every
|
|
56
|
+
migration: NOLOGIN, never CREATEDB, CREATEROLE, SUPERUSER, BYPASSRLS or REPLICATION, granted no privilege on a server
|
|
57
|
+
parameter (`GRANT ... ON PARAMETER`), the owner of no database or tablespace, and a member of no role (at any depth)
|
|
58
|
+
but `app_user` and the app's other named roles (`GRANT reviewer TO app_user` is fine;
|
|
59
|
+
`GRANT pg_read_all_data TO reviewer` is not). Leave the framework's `app_user` ordinary too, since every later owner
|
|
60
|
+
gets ADMIN on it as well: never change its attributes, give it no parameter privilege, database or tablespace, and grant it only
|
|
61
|
+
the app's named roles, never a `pg_*` one. Name your role in `appRoles`, exported beside `appMigrations` from
|
|
62
|
+
`src/app-config/db/migrations/index.ts`: `export const appRoles = ['reviewer'] as const`. The contract tests' owner
|
|
63
|
+
pass grants a later database owner ADMIN on exactly those roles and `app_user`, as Aurora's master user holds on a
|
|
64
|
+
role it created, and refuses a role that is not ordinary; the conformance suite's `app-roles` check fails a role the
|
|
65
|
+
migrations create and `appRoles` does not name, a name they do not create, and a named role or `app_user` they leave
|
|
66
|
+
more than ordinary. Never name `app_user` or a `pg_*` or `rds_*` role.
|
|
67
|
+
- After any migration or database change, run the contract tests on real Postgres (`pnpm test:contract` from the
|
|
68
|
+
workspace root). After renumbering or renaming a migration, wipe
|
|
69
|
+
the local `.data` first.
|
|
70
|
+
|
|
71
|
+
## Authorization
|
|
72
|
+
|
|
73
|
+
- Every exported mutating route handler (POST, PUT, PATCH, DELETE) in a `route.ts` anywhere under `src/app`, not only
|
|
74
|
+
under `src/app/api`, calls `authorize(...)` from `@sssb/kit/authz/authorize` on its own path, as
|
|
75
|
+
`src/app/api/items/route.ts` does (the generated app's; once you have removed it, read it in SSSB's repository at your
|
|
76
|
+
release). The conformance suite's `authz-mutations` check reads each handler: a string, a
|
|
77
|
+
comment, a dead branch or a helper in another module does not count. Neither does a call whose denial cannot stop
|
|
78
|
+
the handler: in an `async` helper or a callback whose promise the handler neither awaits nor returns, in a callback
|
|
79
|
+
handed to a function the route file defines, or in a `try` whose `catch` does not rethrow. `await` the helper that
|
|
80
|
+
authorizes, and let `withPortErrors` answer the 403.
|
|
81
|
+
- An exemption is an entry in the app's `authz-exemptions.mjs` (`{ files, prefixes }`, keys relative to
|
|
82
|
+
`src/app/api`), with a reason and a `mustMatch` gate. A mutating route outside `src/app/api` can match no
|
|
83
|
+
exemption.
|
|
84
|
+
|
|
85
|
+
## UI
|
|
86
|
+
|
|
87
|
+
- No hard-coded UI strings: all copy goes through next-intl, accessible names, placeholders, titles and alt text
|
|
88
|
+
included (`sssb/no-jsx-literals`, `sssb/no-literal-a11y-copy`). The app's namespaces live in `messages/en.json` and
|
|
89
|
+
`messages/es.json`; the framework ships its own catalog, and the two are deep-merged wherever messages load. The
|
|
90
|
+
merged catalogs stay key- and placeholder-identical.
|
|
91
|
+
- Screens are router-agnostic: they live in `src/components`, and the files under `src/app` are thin wrappers with no
|
|
92
|
+
logic, so the `file://` static demo still builds.
|
|
93
|
+
|
|
94
|
+
## Tests
|
|
95
|
+
|
|
96
|
+
- Keep `src/sssb.conformance.test.ts` (SSSB's conformance suite) and `tests/contract/rls-contract.test.ts` (the
|
|
97
|
+
contract runner on real Postgres). Leave a check out only by a named opt-out with its reason,
|
|
98
|
+
`optOut: { '<check id>': '<why>' }`. `sssb doctor` fails when the Vitest config does not run them.
|
|
99
|
+
- A test that needs a scratch directory calls `makeTestTmpDir()` or `makeTestTmpDirAsync()` from
|
|
100
|
+
`@sssb/tools/testing/tmp-dir`, never `mkdtemp` directly. A script that runs Vitest as a gate goes through
|
|
101
|
+
`sssb check-tmpdir-leak`.
|
|
102
|
+
- E2E specs live in `tests/e2e/` and reach the framework only through `@sssb/kit/testing/e2e` (`sssb check-e2e`).
|
|
103
|
+
Playwright's `workers` stays 1: every worker shares one `.data` behind one dev server.
|
|
104
|
+
- Dead code fails `knip`. Never silence a finding with a broad ignore; add the narrowest entry, with its reason.
|
|
105
|
+
|
|
106
|
+
## The dev loop
|
|
107
|
+
|
|
108
|
+
- Scheduled work runs in dev only when something ticks it: the app's `pnpm tick` calls the running dev server's cron
|
|
109
|
+
route once, and `DEV_TICK_SECONDS=<n> pnpm dev` ticks it every n seconds. The ticker is off by default and stays off
|
|
110
|
+
under e2e. The cron route (`src/app/api/webhooks/cron/route.ts`) stays behind `withWebhookSecret`: never add a
|
|
111
|
+
bypass for the ticker.
|
|
112
|
+
- In a linked git worktree the app's ports are derived per checkout, so parallel sessions never adopt each other's dev
|
|
113
|
+
server; `pnpm exec sssb port`, run from the app, prints its port. An app declares its port slot in its package.json
|
|
114
|
+
(`"sssb": { "port": "starter" }`), and every app of a workspace needs a slot of its own: a second app declares
|
|
115
|
+
`"sssb": { "port": { "name": "ledger", "default": 3700 } }`, which `sssb doctor` checks, and reads its override from
|
|
116
|
+
`LEDGER_PORT`.
|
|
117
|
+
- Before finishing a change, run `pnpm verify` from the workspace root. Format with `pnpm lint:fix`, never by hand.
|
|
118
|
+
Commit messages are conventional commits; the commit-msg hook runs commitlint.
|