@sssb/kit 0.0.0 → 0.3.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.
Files changed (227) hide show
  1. package/LICENSE +21 -0
  2. package/dist/core/webhook-hmac.d.ts +69 -0
  3. package/dist/release.json +1 -0
  4. package/dist/testing/e2e.d.ts +15 -0
  5. package/dist/testing/e2e.js +195 -0
  6. package/package.json +212 -5
  7. package/src/adapters/README.md +6 -0
  8. package/src/adapters/dev-server.ts +21 -0
  9. package/src/adapters/fake/agreements.ts +81 -0
  10. package/src/adapters/fake/analytics.ts +93 -0
  11. package/src/adapters/fake/atomic-write.ts +161 -0
  12. package/src/adapters/fake/audit.ts +58 -0
  13. package/src/adapters/fake/auth.ts +313 -0
  14. package/src/adapters/fake/clock.ts +54 -0
  15. package/src/adapters/fake/data-dir.ts +27 -0
  16. package/src/adapters/fake/db.ts +88 -0
  17. package/src/adapters/fake/email.ts +46 -0
  18. package/src/adapters/fake/jobs.ts +248 -0
  19. package/src/adapters/fake/llm.ts +230 -0
  20. package/src/adapters/fake/pglite-dialect.ts +124 -0
  21. package/src/adapters/fake/service-auth.ts +145 -0
  22. package/src/adapters/fake/simulator-admin.ts +203 -0
  23. package/src/adapters/fake/simulator.ts +93 -0
  24. package/src/adapters/fake/sms.ts +43 -0
  25. package/src/adapters/fake/storage.ts +288 -0
  26. package/src/adapters/fake/webhooks.ts +98 -0
  27. package/src/adapters/index.ts +142 -0
  28. package/src/adapters/lazy-jobs.ts +25 -0
  29. package/src/adapters/proxy.ts +34 -0
  30. package/src/adapters/real/absent.ts +41 -0
  31. package/src/adapters/real/accept-invite-form.tsx +77 -0
  32. package/src/adapters/real/analytics.ts +28 -0
  33. package/src/adapters/real/auth.ts +216 -0
  34. package/src/adapters/real/clerk-proxy.ts +111 -0
  35. package/src/adapters/real/contract-data-api.ts +104 -0
  36. package/src/adapters/real/contract-postgres.ts +167 -0
  37. package/src/adapters/real/database-transport.ts +34 -0
  38. package/src/adapters/real/db-data-api.ts +61 -0
  39. package/src/adapters/real/db-port.ts +26 -0
  40. package/src/adapters/real/db.ts +69 -0
  41. package/src/adapters/real/email.ts +22 -0
  42. package/src/adapters/real/index.ts +139 -0
  43. package/src/adapters/real/jobs-in-process.ts +118 -0
  44. package/src/adapters/real/jobs.ts +33 -0
  45. package/src/adapters/real/llm.ts +108 -0
  46. package/src/adapters/real/migrate-handler.ts +66 -0
  47. package/src/adapters/real/optional-ports.ts +78 -0
  48. package/src/adapters/real/providers.tsx +12 -0
  49. package/src/adapters/real/rds-data-codec.ts +508 -0
  50. package/src/adapters/real/rds-data-dialect.ts +470 -0
  51. package/src/adapters/real/rds-data-emulator.ts +351 -0
  52. package/src/adapters/real/s3-storage.ts +233 -0
  53. package/src/adapters/real/sign-in-form.tsx +59 -0
  54. package/src/adapters/real/storage.ts +10 -0
  55. package/src/adapters/run-mode.ts +11 -0
  56. package/src/adapters/sentry/baseline.ts +90 -0
  57. package/src/adapters/sentry/client.ts +17 -0
  58. package/src/adapters/sentry/init.ts +17 -0
  59. package/src/authz/app-exemptions.ts +226 -0
  60. package/src/authz/authorize.ts +214 -0
  61. package/src/authz/route-policy.ts +153 -0
  62. package/src/authz/route-scan.ts +1516 -0
  63. package/src/components/agreements/acceptances-section.tsx +55 -0
  64. package/src/components/agreements/agreement-advisory-banner.tsx +33 -0
  65. package/src/components/agreements/agreement-body.tsx +34 -0
  66. package/src/components/agreements/agreement-gate.tsx +45 -0
  67. package/src/components/app-header.tsx +45 -0
  68. package/src/components/auth/accept-invite-screen.tsx +126 -0
  69. package/src/components/auth/auth-icons.tsx +68 -0
  70. package/src/components/auth/org-switcher.tsx +76 -0
  71. package/src/components/auth/people-picker.tsx +50 -0
  72. package/src/components/auth/preview-row.tsx +64 -0
  73. package/src/components/auth/sign-in-screen.tsx +24 -0
  74. package/src/components/auth/user-menu.tsx +64 -0
  75. package/src/components/demo-badge.tsx +20 -0
  76. package/src/components/demo-banner.tsx +14 -0
  77. package/src/components/gates/gate-interstitial.tsx +23 -0
  78. package/src/components/job-timeline.tsx +64 -0
  79. package/src/components/notifications/notification-bell.tsx +120 -0
  80. package/src/components/notifications/notification-prefs-section.tsx +112 -0
  81. package/src/components/org-screen.tsx +197 -0
  82. package/src/components/profile-screen.tsx +100 -0
  83. package/src/components/simulator/actor-runtime.ts +180 -0
  84. package/src/components/simulator/actor-shell.tsx +275 -0
  85. package/src/components/simulator/actors-app.tsx +119 -0
  86. package/src/components/simulator/errors-app.tsx +84 -0
  87. package/src/components/simulator/events-app.tsx +210 -0
  88. package/src/components/simulator/format-when.ts +20 -0
  89. package/src/components/simulator/hooks-app.tsx +319 -0
  90. package/src/components/simulator/inbound-app.tsx +210 -0
  91. package/src/components/simulator/jobs-app.tsx +471 -0
  92. package/src/components/simulator/mail-app.tsx +290 -0
  93. package/src/components/simulator/messages-app.tsx +64 -0
  94. package/src/components/simulator/people-app.tsx +140 -0
  95. package/src/components/simulator/people-dimensions.ts +16 -0
  96. package/src/components/simulator/simulator-host.tsx +335 -0
  97. package/src/components/simulator/simulator-panel.tsx +704 -0
  98. package/src/components/simulator/snapshots-app.tsx +398 -0
  99. package/src/components/simulator/tab-mount.ts +25 -0
  100. package/src/components/simulator/tours-app.tsx +105 -0
  101. package/src/components/webhook-endpoints-card.tsx +172 -0
  102. package/src/core/abilities.ts +464 -0
  103. package/src/core/agreements.ts +139 -0
  104. package/src/core/gates.ts +157 -0
  105. package/src/core/greeting.ts +11 -0
  106. package/src/core/inbound-email.ts +129 -0
  107. package/src/core/jobs.ts +51 -0
  108. package/src/core/keyset.ts +227 -0
  109. package/src/core/llm-models.ts +10 -0
  110. package/src/core/locale.ts +3 -0
  111. package/src/core/notifications.ts +182 -0
  112. package/src/core/presets.ts +456 -0
  113. package/src/core/roles.ts +47 -0
  114. package/src/core/same-origin-path.ts +20 -0
  115. package/src/core/schedules.ts +147 -0
  116. package/src/core/standard-schema.ts +56 -0
  117. package/src/core/state-machine.ts +43 -0
  118. package/src/core/webhook-events.ts +86 -0
  119. package/src/core/webhook-hmac.ts +248 -0
  120. package/src/core/webhook-signing.ts +27 -0
  121. package/src/cutover/rows.json +101 -0
  122. package/src/db/agreements.ts +176 -0
  123. package/src/db/app-roles.ts +197 -0
  124. package/src/db/audit.ts +356 -0
  125. package/src/db/inbound-email.ts +145 -0
  126. package/src/db/jobs.ts +300 -0
  127. package/src/db/jsonb.ts +18 -0
  128. package/src/db/keyset.ts +179 -0
  129. package/src/db/migrate.ts +73 -0
  130. package/src/db/migrations/0001_tenants.ts +25 -0
  131. package/src/db/migrations/0003_organizations.ts +27 -0
  132. package/src/db/migrations/0004_jobs.ts +64 -0
  133. package/src/db/migrations/0005_service_keys.ts +33 -0
  134. package/src/db/migrations/0008_audit_events.ts +51 -0
  135. package/src/db/migrations/0009_job_schedules.ts +52 -0
  136. package/src/db/migrations/0010_webhooks.ts +100 -0
  137. package/src/db/migrations/0011_notifications.ts +98 -0
  138. package/src/db/migrations/0012_inbound_email.ts +74 -0
  139. package/src/db/migrations/0013_agreements.ts +98 -0
  140. package/src/db/migrations/0014_audit_credential.ts +29 -0
  141. package/src/db/migrations/0015_app_user_grant.ts +67 -0
  142. package/src/db/migrations/0016_audit_detail.ts +26 -0
  143. package/src/db/migrations/index.ts +49 -0
  144. package/src/db/notifications.ts +185 -0
  145. package/src/db/org-lookup.ts +104 -0
  146. package/src/db/owner-pass.ts +252 -0
  147. package/src/db/rls-coverage.ts +259 -0
  148. package/src/db/rls-proof-runner.ts +94 -0
  149. package/src/db/rls-proofs.ts +1176 -0
  150. package/src/db/schedules.ts +187 -0
  151. package/src/db/schema.ts +235 -0
  152. package/src/db/seed.ts +176 -0
  153. package/src/db/service-keys.ts +50 -0
  154. package/src/db/tenant-lookup.ts +13 -0
  155. package/src/db/webhooks.ts +483 -0
  156. package/src/db/with-tenant.ts +26 -0
  157. package/src/demo-static/actor-drivers.ts +161 -0
  158. package/src/demo-static/assistant-replay.ts +61 -0
  159. package/src/demo-static/contracts.ts +282 -0
  160. package/src/demo-static/email-html.ts +58 -0
  161. package/src/demo-static/hash-route.ts +24 -0
  162. package/src/demo-static/rows.ts +105 -0
  163. package/src/demo-static/shell.tsx +440 -0
  164. package/src/demo-static/tour/contracts.ts +97 -0
  165. package/src/demo-static/tour/driver.ts +320 -0
  166. package/src/demo-static/tour/tour-overlay.tsx +226 -0
  167. package/src/demo-static/tour/use-tours.tsx +394 -0
  168. package/src/demo-static/world.ts +1480 -0
  169. package/src/email/send.ts +12 -0
  170. package/src/email/templates/digest-email.tsx +61 -0
  171. package/src/email/templates/invite-email.tsx +57 -0
  172. package/src/email/templates/notification-email.tsx +39 -0
  173. package/src/guide.md +132 -0
  174. package/src/i18n/messages/en.json +373 -0
  175. package/src/i18n/messages/es.json +373 -0
  176. package/src/i18n/messages.ts +34 -0
  177. package/src/i18n/namespaces.ts +32 -0
  178. package/src/i18n/request.ts +34 -0
  179. package/src/i18n/routing.ts +7 -0
  180. package/src/inbound-email/handlers.ts +67 -0
  181. package/src/inbound-email/intake.ts +180 -0
  182. package/src/jobs/digest-email.ts +112 -0
  183. package/src/jobs/run-in-process.ts +82 -0
  184. package/src/observability/scrub.ts +44 -0
  185. package/src/ports/README.md +8 -0
  186. package/src/ports/analytics.ts +8 -0
  187. package/src/ports/auth.ts +87 -0
  188. package/src/ports/db.ts +27 -0
  189. package/src/ports/email.ts +14 -0
  190. package/src/ports/errors.ts +46 -0
  191. package/src/ports/jobs.ts +69 -0
  192. package/src/ports/llm.ts +85 -0
  193. package/src/ports/storage.ts +132 -0
  194. package/src/seed/contracts.ts +129 -0
  195. package/src/server-lib/assistant.ts +45 -0
  196. package/src/server-lib/defer.ts +57 -0
  197. package/src/server-lib/demo-presets.ts +85 -0
  198. package/src/server-lib/invite.ts +92 -0
  199. package/src/server-lib/notify-deps.ts +15 -0
  200. package/src/server-lib/notify.ts +252 -0
  201. package/src/server-lib/preset-operations.ts +121 -0
  202. package/src/server-lib/scheduled-tick.ts +48 -0
  203. package/src/server-lib/simulator-api.ts +311 -0
  204. package/src/server-lib/sms.ts +43 -0
  205. package/src/server-lib/webhook-dispatch.ts +75 -0
  206. package/src/service-auth/credential.ts +20 -0
  207. package/src/service-auth/mailgun.ts +70 -0
  208. package/src/service-auth/verify.ts +80 -0
  209. package/src/service-auth/webhook.ts +69 -0
  210. package/src/testing/checks.json +103 -0
  211. package/src/testing/conformance/authz.ts +46 -0
  212. package/src/testing/conformance/db.ts +258 -0
  213. package/src/testing/conformance/demo-presets.ts +295 -0
  214. package/src/testing/conformance/i18n.ts +80 -0
  215. package/src/testing/conformance/register.ts +200 -0
  216. package/src/testing/conformance/seam-map.ts +205 -0
  217. package/src/testing/conformance/suite.ts +59 -0
  218. package/src/testing/conformance/types.ts +18 -0
  219. package/src/testing/contract.ts +200 -0
  220. package/src/testing/e2e.ts +15 -0
  221. package/src/testing/index.ts +6 -0
  222. package/src/testing/seam-specifiers.json +22 -0
  223. package/src/testing/tmp-dir-marker.d.mts +4 -0
  224. package/src/testing/tmp-dir-marker.mjs +5 -0
  225. package/src/testing/tmp-dir.ts +182 -0
  226. package/src/theme.ts +28 -0
  227. package/README.md +0 -3
@@ -0,0 +1,33 @@
1
+ import { CodeBuildClient, StartBuildCommand } from '@aws-sdk/client-codebuild'
2
+ import type { JobsPort } from '../../ports/jobs'
3
+
4
+ /**
5
+ * AUTHORED — CUTOVER (`job-runner`): typechecked against @aws-sdk/client-codebuild, never run
6
+ * against a real project. Starting the build is ALL this seam does — the job stays 'queued' until
7
+ * the build's FINAL step POSTs /api/webhooks/jobs with `x-sssb-webhook-secret: $WEBHOOK_SECRET` (never `Authorization`, which
8
+ * the deployment's CloudFront replaces with its own signature) and
9
+ * `{ jobId, tenantId, status: 'completed' | 'failed', resultKey?, error? }`, which records the
10
+ * terminal transition via packages/kit/src/db/jobs.recordWebhookCompletion (idempotent under redelivery). The
11
+ * build receives its context through environment overrides, mirroring the fake handler's args —
12
+ * including JOB_TENANT_ID, which the webhook echoes back as `tenantId` so the completion is scoped
13
+ * to the right tenant without the build having to look it up.
14
+ */
15
+ export function createRealJobs(project: string, region: string): JobsPort {
16
+ const client = new CodeBuildClient({ region })
17
+
18
+ return {
19
+ async start(job) {
20
+ await client.send(
21
+ new StartBuildCommand({
22
+ projectName: project,
23
+ environmentVariablesOverride: [
24
+ { name: 'JOB_ID', value: job.id, type: 'PLAINTEXT' },
25
+ { name: 'JOB_KIND', value: job.kind, type: 'PLAINTEXT' },
26
+ { name: 'JOB_TENANT_ID', value: job.tenantId, type: 'PLAINTEXT' },
27
+ { name: 'JOB_PAYLOAD', value: JSON.stringify(job.payload ?? {}), type: 'PLAINTEXT' },
28
+ ],
29
+ }),
30
+ )
31
+ },
32
+ }
33
+ }
@@ -0,0 +1,108 @@
1
+ import Anthropic from '@anthropic-ai/sdk'
2
+ import { LLM_MODELS } from '../../core/llm-models'
3
+ import type { LlmContentBlock, LlmPort, LlmRequest, LlmTurn } from '../../ports/llm'
4
+
5
+ /**
6
+ * AUTHORED — CUTOVER (`llm-key`): typechecked, never run against the real API. Also used by each
7
+ * app's own `scripts/llm-record.ts` to (re)record fixtures. The `llm-key` cutover row's deferred
8
+ * verification covers BOTH: re-recording the conversation fixtures AND running one live tool loop
9
+ * (`runToolLoop` below — tool_use/tool_result blocks, loop until end_turn or maxTurns).
10
+ */
11
+ export function createRealLlm(apiKey: string): LlmPort {
12
+ const client = new Anthropic({ apiKey })
13
+
14
+ const toParams = (request: LlmRequest) => ({
15
+ model: request.model ?? LLM_MODELS.default,
16
+ ...(request.system === undefined ? {} : { system: request.system }),
17
+ messages: request.messages,
18
+ max_tokens: request.maxTokens ?? 1024,
19
+ })
20
+
21
+ return {
22
+ async complete(request) {
23
+ const message = await client.messages.create(toParams(request))
24
+ const text = message.content
25
+ .filter((block): block is Anthropic.TextBlock => block.type === 'text')
26
+ .map((block) => block.text)
27
+ .join('')
28
+ return { text }
29
+ },
30
+
31
+ async *stream(request) {
32
+ const stream = client.messages.stream(toParams(request))
33
+ for await (const chunk of stream) {
34
+ if (chunk.type === 'content_block_delta' && chunk.delta.type === 'text_delta') {
35
+ yield chunk.delta.text
36
+ }
37
+ }
38
+ },
39
+
40
+ async runToolLoop(request) {
41
+ const tools: Anthropic.Tool[] = request.tools.map((t) => ({
42
+ name: t.name,
43
+ description: t.description,
44
+ input_schema: t.inputSchema,
45
+ }))
46
+ // Running SDK message history (assistant + tool_result turns), fed back each round.
47
+ const messages: Anthropic.MessageParam[] = request.messages.map((m) => ({
48
+ role: m.role,
49
+ content: m.content,
50
+ }))
51
+ // Port-shaped view of the same conversation (serializes to the fixture format).
52
+ const turns: LlmTurn[] = []
53
+ const maxTurns = request.maxTurns ?? 6
54
+
55
+ for (let round = 0; round < maxTurns; round++) {
56
+ const message = await client.messages.create({
57
+ model: request.model ?? LLM_MODELS.default,
58
+ ...(request.system === undefined ? {} : { system: request.system }),
59
+ messages,
60
+ tools,
61
+ max_tokens: request.maxTokens ?? 1024,
62
+ })
63
+
64
+ const assistantBlocks: LlmContentBlock[] = []
65
+ for (const block of message.content) {
66
+ if (block.type === 'text') assistantBlocks.push({ type: 'text', text: block.text })
67
+ else if (block.type === 'tool_use')
68
+ assistantBlocks.push({ type: 'tool_use', id: block.id, name: block.name, input: block.input })
69
+ // Other block types (thinking, server tools) aren't used by this surface.
70
+ }
71
+ turns.push({ role: 'assistant', content: assistantBlocks })
72
+ messages.push({ role: 'assistant', content: message.content })
73
+
74
+ if (message.stop_reason !== 'tool_use') {
75
+ return { text: textOf(assistantBlocks), turns }
76
+ }
77
+
78
+ // Relay each tool_use to the app's executor LIVE, then feed all results back at once.
79
+ const toolResults: Anthropic.ToolResultBlockParam[] = []
80
+ const resultBlocks: LlmContentBlock[] = []
81
+ for (const block of message.content) {
82
+ if (block.type !== 'tool_use') continue
83
+ // Defense-in-depth mirror of the fake adapter: never execute a tool_use whose
84
+ // name the app didn't supply — the model is untrusted (see the port trust model).
85
+ const known = request.tools.some((t) => t.name === block.name)
86
+ const result = known
87
+ ? await request.execute({ name: block.name, input: block.input })
88
+ : `unknown tool: ${block.name}`
89
+ toolResults.push({ type: 'tool_result', tool_use_id: block.id, content: result })
90
+ resultBlocks.push({ type: 'tool_result', toolUseId: block.id, content: result })
91
+ }
92
+ messages.push({ role: 'user', content: toolResults })
93
+ turns.push({ role: 'user', content: resultBlocks })
94
+ }
95
+
96
+ // Hit maxTurns without an end_turn: return the last assistant text.
97
+ const lastAssistant = [...turns].reverse().find((t) => t.role === 'assistant')
98
+ return { text: lastAssistant ? textOf(lastAssistant.content) : '', turns }
99
+ },
100
+ }
101
+ }
102
+
103
+ function textOf(blocks: LlmContentBlock[]): string {
104
+ return blocks
105
+ .filter((b): b is Extract<LlmContentBlock, { type: 'text' }> => b.type === 'text')
106
+ .map((b) => b.text)
107
+ .join('')
108
+ }
@@ -0,0 +1,66 @@
1
+ import { GetSecretValueCommand, SecretsManagerClient } from '@aws-sdk/client-secrets-manager'
2
+ import { databaseTransport } from './database-transport'
3
+ import { createRealDb } from './db'
4
+
5
+ /**
6
+ * Migrator Lambda handler (ADR-0001): runs the same migration registry the app, unit tests, and
7
+ * contract tests use. Invoked by the CD pipeline before each release shifts traffic.
8
+ * AUTHORED — CUTOVER (`cloud-accounts`; `data-api` for the Data API path).
9
+ *
10
+ * ROLES. The credentials here are the migrator's, and migration 0015 grants that role the switch to
11
+ * `app_user`. If the application connects as a DIFFERENT role, that role needs the switch too. It cannot
12
+ * grant itself that; this role, which created `app_user` and so holds ADMIN on it, or any other role with
13
+ * ADMIN on `app_user`, runs: GRANT app_user TO <app role> WITH SET TRUE, INHERIT TRUE;
14
+ * A SECOND database's owner on the same cluster (staging beside production) has no ADMIN on the
15
+ * `app_user` the first one created: its run stops at 0015 and prints the GRANT to run; see the same row.
16
+ * (the `db-role-not-superuser` row in docs/cutover-checklist.md; ADR-0004, 2026-11-16 addendum).
17
+ *
18
+ * The transport follows the app's switch (`DATABASE_TRANSPORT`, ./index.ts), and the Data API one is a
19
+ * dynamic import here too. On the Data API, Kysely's Migrator runs every pending migration in ONE Data
20
+ * API transaction, as it does on `pg` (Postgres DDL is transactional). Two limits follow, and both fail
21
+ * loudly rather than half-apply: the transaction dies after an hour (AWS's BeginTransaction API
22
+ * reference) or three idle minutes, and any single statement still running at 45 seconds is cancelled. A
23
+ * migration that cannot fit — a long backfill, an index on a large table — needs the `pg` transport, from
24
+ * inside the VPC: a deployment on the `data-api` network shape has no other way in to run it.
25
+ *
26
+ * @public
27
+ */
28
+ export async function handler(): Promise<{ ok: true }> {
29
+ if (databaseTransport() === 'data-api') {
30
+ const { DATABASE_CLUSTER_ARN, DATABASE_SECRET_ARN, DATABASE_NAME } = process.env
31
+ if (!DATABASE_CLUSTER_ARN || !DATABASE_SECRET_ARN || !DATABASE_NAME) {
32
+ throw new Error('DATABASE_CLUSTER_ARN, DATABASE_SECRET_ARN and DATABASE_NAME must be set for the Data API')
33
+ }
34
+ const { createRealDataApiDb } = await import('./db-data-api')
35
+ const db = createRealDataApiDb({
36
+ resourceArn: DATABASE_CLUSTER_ARN,
37
+ secretArn: DATABASE_SECRET_ARN,
38
+ database: DATABASE_NAME,
39
+ })
40
+ await db.migrateToLatest()
41
+ return { ok: true }
42
+ }
43
+
44
+ const secretArn = process.env['DB_SECRET_ARN']
45
+ if (!secretArn) throw new Error('DB_SECRET_ARN is not set')
46
+
47
+ const client = new SecretsManagerClient({})
48
+ const secret = await client.send(new GetSecretValueCommand({ SecretId: secretArn }))
49
+ const { host, port, username, password, dbname } = JSON.parse(secret.SecretString ?? '{}') as {
50
+ host: string
51
+ port: number
52
+ username: string
53
+ password: string
54
+ dbname?: string
55
+ }
56
+
57
+ // The deployment names the database (SSSB's construct sets DATABASE_NAME); the secret's `dbname` is the fallback
58
+ // for infra that does not, and is there only if the cluster's secret attachment added it.
59
+ const database = process.env['DATABASE_NAME'] ?? dbname
60
+ if (!database) throw new Error('neither DATABASE_NAME nor the secret names the database to migrate')
61
+ const db = createRealDb(
62
+ `postgres://${encodeURIComponent(username)}:${encodeURIComponent(password)}@${host}:${port}/${database}`,
63
+ )
64
+ await db.migrateToLatest()
65
+ return { ok: true }
66
+ }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * SSSB's optional ports in a real deployment: the ones an app may not use at all. Each has a switch, a deployment
3
+ * parameter each app records under `params.ports` in its `config/params.ts` (@sssb/cdk's `SssbApp` sets the variables
4
+ * from it, as it sets DATABASE_TRANSPORT from `params.database.transport`):
5
+ *
6
+ * - `LLM_PROVIDER`: `anthropic` (the default) or `none`. The `llm` port.
7
+ * - `EMAIL_PROVIDER`: `mailgun` (the default) or `none`. The `email` port, which the framework's invitations and
8
+ * notifications send through too.
9
+ * - `INBOUND_EMAIL_PROVIDER`: `mailgun` (the default) or `none`. The signing key the inbound email route verifies
10
+ * with (`@sssb/kit/service-auth/mailgun`). Without it that route refuses every request, as it always has.
11
+ * - `JOBS_RUNNER`: `codebuild` (the default), `in-process` or `none`. The `jobs` port: a CodeBuild build per job, the
12
+ * job's handler run in the server itself (./jobs-in-process.ts), or no jobs at all.
13
+ *
14
+ * An unset switch is its default, which is what real mode required before the switches existed, so a deployment that
15
+ * sets none of them boots as it did. `none` makes the port ABSENT (./absent.ts): its settings are not required, its
16
+ * SDK is never loaded, and a call through it throws an error that names the switch. Never fill an unused port's
17
+ * settings with placeholder values instead: a placeholder reaches the vendor and fails there, far from the cause.
18
+ *
19
+ * An explicit switch, never inferred from which settings happen to be set (the DATABASE_TRANSPORT rule): a
20
+ * deployment that half-configures a port must fail at boot, not quietly lose it.
21
+ */
22
+ export const OPTIONAL_PORTS = {
23
+ llm: {
24
+ variable: 'LLM_PROVIDER',
25
+ default: 'anthropic',
26
+ env: { anthropic: { ANTHROPIC_API_KEY: 'llm-key' }, none: {} },
27
+ },
28
+ email: {
29
+ variable: 'EMAIL_PROVIDER',
30
+ default: 'mailgun',
31
+ env: {
32
+ mailgun: {
33
+ MAILGUN_DOMAIN: 'email-outbound',
34
+ MAILGUN_API_KEY: 'email-outbound',
35
+ EMAIL_FROM: 'email-outbound',
36
+ },
37
+ none: {},
38
+ },
39
+ },
40
+ inboundEmail: {
41
+ variable: 'INBOUND_EMAIL_PROVIDER',
42
+ default: 'mailgun',
43
+ // The key Mailgun signs inbound-route webhooks with, verified by the inbound email route at request time.
44
+ env: { mailgun: { MAILGUN_WEBHOOK_SIGNING_KEY: 'email-inbound' }, none: {} },
45
+ },
46
+ jobs: {
47
+ variable: 'JOBS_RUNNER',
48
+ default: 'codebuild',
49
+ env: { codebuild: { JOBS_CODEBUILD_PROJECT: 'job-runner' }, 'in-process': {}, none: {} },
50
+ },
51
+ } as const satisfies Record<
52
+ string,
53
+ { variable: string; default: string; env: Record<string, Readonly<Record<string, string>>> }
54
+ >
55
+
56
+ export type OptionalPort = keyof typeof OPTIONAL_PORTS
57
+ export type PortChoice<P extends OptionalPort> = keyof (typeof OPTIONAL_PORTS)[P]['env'] & string
58
+
59
+ /** The deployment's choice for one optional port: its switch, or the default when unset. Fails on an unknown value. */
60
+ export function portChoice<P extends OptionalPort>(port: P): PortChoice<P> {
61
+ const { variable, default: fallback, env } = OPTIONAL_PORTS[port]
62
+ const choices = Object.keys(env)
63
+ const value = process.env[variable] || fallback
64
+ if (!choices.includes(value)) {
65
+ throw new Error(`${variable} must be one of ${choices.join(', ')} (got "${value}")`)
66
+ }
67
+ return value as PortChoice<P>
68
+ }
69
+
70
+ /** The variables the deployment's optional-port choices require, each mapped to its cutover row. */
71
+ export function optionalPortsEnv(): Record<string, string> {
72
+ const required: Record<string, string> = {}
73
+ for (const port of Object.keys(OPTIONAL_PORTS) as OptionalPort[]) {
74
+ const env: Record<string, Readonly<Record<string, string>>> = OPTIONAL_PORTS[port].env
75
+ Object.assign(required, env[portChoice(port)])
76
+ }
77
+ return required
78
+ }
@@ -0,0 +1,12 @@
1
+ 'use client'
2
+
3
+ import { ClerkProvider } from '@clerk/nextjs'
4
+ import type { ReactNode } from 'react'
5
+
6
+ /**
7
+ * Real-mode client providers. Only mounted when APP_MODE=real, so simulated mode ships zero Clerk
8
+ * code. AUTHORED — CUTOVER (`auth-dev`).
9
+ */
10
+ export function RealAuthProviders({ children }: { children: ReactNode }) {
11
+ return <ClerkProvider>{children}</ClerkProvider>
12
+ }