@crombolo/server 0.25.0 → 0.27.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/src/ports.ts CHANGED
@@ -17,7 +17,6 @@ import type {
17
17
  import { AuthStore, expireCookie, serializeCookie } from '@crombolo/auth'
18
18
  import {
19
19
  APP_PREVIEW_MANIFEST_ID,
20
- ASSISTANT_MANIFEST_ID,
21
20
  type BackOfficePaths,
22
21
  collectManifests,
23
22
  type ExtensionRegistry,
@@ -27,6 +26,7 @@ import {
27
26
  type ApprovalsGate,
28
27
  type ContentPrincipal,
29
28
  createDocumentOperations,
29
+ createMediaOperations,
30
30
  type DocumentOperations,
31
31
  type EventSink,
32
32
  SILENT,
@@ -85,6 +85,7 @@ import { createWebhookPort } from './adapters/webhooks.ts'
85
85
  import { type Approvals, createApprovals } from './approvals.ts'
86
86
  import { COMPONENT_SNIPPETS } from './component-snippets.ts'
87
87
  import { type CromboloConfig, type UserLinkSender, VERSION } from './config.ts'
88
+ import { createMediaEventSink } from './content-events.ts'
88
89
  import type { ContentNotifier } from './content-notifications.ts'
89
90
  import { writeDomainsFor } from './domains.ts'
90
91
  import { type EmailPort, resolveEmailPort } from './email.ts'
@@ -474,12 +475,12 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
474
475
  const deps: ManagementApiDeps = {
475
476
  server: createServerPort(options.config, Boolean(sendUserLink)),
476
477
  preview: createPreviewPort(options.config, options.previewInApp),
477
- // An unconfigured assistant contributes no extension, so the backoffice has
478
- // no drawer, no button and nothing to load; Preview in app likewise.
479
- manifests: createManifestPort(options.paths, options.extensions, [
480
- ...(options.config.assistant ? [] : [ASSISTANT_MANIFEST_ID]),
481
- ...(options.previewInApp ? [] : [APP_PREVIEW_MANIFEST_ID]),
482
- ]),
478
+ // Without an app to preview in, Preview in app contributes no extension.
479
+ manifests: createManifestPort(
480
+ options.paths,
481
+ options.extensions,
482
+ options.previewInApp ? [] : [APP_PREVIEW_MANIFEST_ID],
483
+ ),
483
484
  localization: createLocalizationPort(
484
485
  options.db,
485
486
  options.db ? createSchemaFileWriter(options.db, schemaFiles(options.config)) : undefined,
@@ -575,13 +576,24 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
575
576
  }
576
577
  deps.userGroups = userPorts.groups
577
578
  deps.userData = userPorts.userData
578
- deps.media = createMediaPort(options.db, mediaFiles, {
579
+ deps.media = createMediaPort(options.db, {
579
580
  nodeState: options.schema?.nodeState,
580
581
  nodeId: options.schema?.nodeId,
581
582
  valueIntake,
583
+ })
584
+ // Every media write, whoever starts it (story 165).
585
+ deps.mediaOperations = createMediaOperations({
586
+ db: options.db,
587
+ repository: {
588
+ nodeState: options.schema?.nodeState,
589
+ nodeId: options.schema?.nodeId,
590
+ valueIntake,
591
+ },
592
+ events: createMediaEventSink({ webhooks: options.webhooks, nudge: options.nudgeEvents }),
593
+ files: mediaFiles,
582
594
  onChange: () => options.cache?.invalidate(),
583
- webhooks: options.webhooks,
584
- nudge: options.nudgeEvents,
595
+ refusalReason: (error) =>
596
+ error instanceof TemporaryFileMissingError ? error.message : undefined,
585
597
  })
586
598
  deps.blueprints = createBlueprintPort(options.db, {
587
599
  nodeState: options.schema?.nodeState,
package/src/remote.ts CHANGED
@@ -15,12 +15,12 @@ import { createWriteStream } from 'node:fs'
15
15
  import { mkdir, rm } from 'node:fs/promises'
16
16
  import { tmpdir } from 'node:os'
17
17
  import { join, sep } from 'node:path'
18
- import type { Principal } from '@crombolo/api-management'
18
+ import { hasSection, type Principal } from '@crombolo/api-management'
19
19
  import { DEVICE_CODE_GRANT, REMOTE_CLIENT_ID } from '@crombolo/auth'
20
- import { MANAGEMENT_API_PATH, RemotePermissions, type RemoteVerb } from '@crombolo/core'
21
- import { type Db, type RemoteJob, RemoteJobRepository } from '@crombolo/data'
20
+ import { managementApiPath, RemotePermissions, type RemoteVerb } from '@crombolo/core'
21
+ import { AuditLog, auditRecord, type Db, type RemoteJob, RemoteJobRepository } from '@crombolo/data'
22
22
  import type { ContentSet } from '@crombolo/transfer'
23
- import { recordAudit } from './adapters/audit.ts'
23
+ import { readAuditPageQuery, recordAudit } from './adapters/audit.ts'
24
24
  import { installBundleContent } from './bundle-install.ts'
25
25
  import type { CromboloConfig } from './config.ts'
26
26
  import { mediaStoreFor } from './media-files.ts'
@@ -78,6 +78,9 @@ const problem = (status: number, body: Problem) =>
78
78
  const may = (principal: Principal, verb: RemoteVerb) =>
79
79
  principal.isAdmin || principal.permissions.includes(verb)
80
80
 
81
+ /** Who may read the audit log: whoever has its dashboard, in Settings. */
82
+ const mayReadAudit = (principal: Principal) => hasSection(principal, 'settings')
83
+
81
84
  /** A cookie-authenticated write must come from this site; a bearer token is a client's own. */
82
85
  const fromThisSiteOrBearer = (request: Request) => {
83
86
  if (request.headers.get('authorization')?.toLowerCase().startsWith('bearer ')) return true
@@ -117,18 +120,26 @@ export function createRemote(options: RemoteOptions): Remote {
117
120
  protected: settings.protected,
118
121
  })
119
122
 
123
+ // Under the back office, as the editor's own API calls are; a command line
124
+ // follows these addresses rather than building its own.
125
+ const managementApi = managementApiPath(config.backOfficePath.replace(/\/+$/, ''))
120
126
  const discovery = (origin: string) => ({
121
127
  protocol: 'crombolo-remote',
122
128
  versions: [REMOTE_PROTOCOL_VERSION],
123
129
  name: config.siteName,
124
130
  api: `${origin}${REMOTE_API_PATH}`,
125
131
  auth: {
126
- deviceAuthorization: `${origin}${MANAGEMENT_API_PATH}/security/back-office/device`,
127
- token: `${origin}${MANAGEMENT_API_PATH}/security/back-office/token`,
132
+ deviceAuthorization: `${origin}${managementApi}/security/back-office/device`,
133
+ token: `${origin}${managementApi}/security/back-office/token`,
128
134
  clientId: REMOTE_CLIENT_ID,
129
135
  grantType: DEVICE_CODE_GRANT,
130
136
  },
131
- capabilities: ['media-fetch', 'push-check', ...(settings.approvals ? ['approvals'] : [])],
137
+ capabilities: [
138
+ 'media-fetch',
139
+ 'push-check',
140
+ 'audit',
141
+ ...(settings.approvals ? ['approvals'] : []),
142
+ ],
132
143
  environments: [environment()],
133
144
  })
134
145
 
@@ -339,6 +350,22 @@ export function createRemote(options: RemoteOptions): Remote {
339
350
  })
340
351
  : undefined
341
352
 
353
+ /**
354
+ * A page of the audit log (story 156), for whoever may read it in the back
355
+ * office: the Settings section, as the dashboard asks. Reading is not audited.
356
+ */
357
+ async function readAudit(url: URL, principal: Principal): Promise<Response> {
358
+ if (!mayReadAudit(principal))
359
+ return problem(403, { code: 'forbidden', title: 'You may not read the audit log' })
360
+ const query = readAuditPageQuery(url.searchParams)
361
+ if (typeof query === 'string') return problem(400, { code: 'bad-query', title: query })
362
+ const page = await new AuditLog(db).page(query.filter, query.cursor)
363
+ return Response.json(
364
+ { items: page.items.map(auditRecord), next: page.next, truncated: page.truncated },
365
+ { headers: { 'cache-control': 'no-store' } },
366
+ )
367
+ }
368
+
342
369
  async function startPull(request: Request, url: URL, principal: Principal): Promise<Response> {
343
370
  if (!may(principal, RemotePermissions.Pull))
344
371
  return problem(403, { code: 'forbidden', title: 'You may not pull from this environment' })
@@ -715,6 +742,7 @@ export function createRemote(options: RemoteOptions): Remote {
715
742
  push:
716
743
  may(principal, RemotePermissions.Push) &&
717
744
  (!settings.protected || may(principal, RemotePermissions.PushProtected)),
745
+ audit: mayReadAudit(principal),
718
746
  },
719
747
  },
720
748
  ])
@@ -747,6 +775,7 @@ export function createRemote(options: RemoteOptions): Remote {
747
775
  title: `There is no environment "${envId}"`,
748
776
  })
749
777
 
778
+ if (what === 'audit' && request.method === 'GET') return readAudit(url, principal)
750
779
  if (what === 'pulls' && request.method === 'POST') return startPull(request, url, principal)
751
780
  if (what === 'pushes' && request.method === 'PUT') return startPush(request, url, principal)
752
781
  if (what === 'pushes/check' && request.method === 'POST') {
package/src/schema.ts CHANGED
@@ -448,7 +448,7 @@ export interface SchemaImportResult {
448
448
  * by the backoffice arrives here and is imported the same way, through one path.
449
449
  *
450
450
  * Deliberately never automatic. It runs when someone asks, or when an operation
451
- * needs it — committing an assistant changeset, publishing type changes — because
451
+ * needs it — publishing type changes, say — because
452
452
  * importing a half-finished schema underneath an editor mid-save is worse than
453
453
  * importing a minute later.
454
454
  *
package/src/server.ts CHANGED
@@ -62,12 +62,14 @@ import { servedContract } from '@crombolo/contracts'
62
62
  import {
63
63
  CHOICE_SOURCE_KINDS,
64
64
  type ChoiceSourceKind,
65
+ contractPathFor,
65
66
  DEFAULT_UPLOAD_SETTINGS,
66
67
  DELIVERY_API_PREFIX,
67
68
  FormPermissions,
68
69
  hasAccessToSensitiveData,
69
70
  localReturnUrl,
70
71
  MANAGEMENT_API_PREFIX,
72
+ managementApiPrefix,
71
73
  ObjectTypes,
72
74
  PREVIEW_HUB_PATH,
73
75
  SERVER_EVENT_HUB_PATH,
@@ -117,7 +119,6 @@ import { createNodeLookup, loadAccess } from './access.ts'
117
119
  import { createAuditHost, createAuditSink, pluginAuditPlan, recordAudit } from './adapters/audit.ts'
118
120
  import { readCreatedBundlePackage, writeCreatedBundlePackage } from './adapters/bundles.ts'
119
121
  import { createPublishedContentSource, loadDraftNode } from './adapters/documents.ts'
120
- import { createSchemaProposals } from './adapters/schema-proposals.ts'
121
122
  import type { Approvals } from './approvals.ts'
122
123
  import { handleApprovalsApi } from './approvals-api.ts'
123
124
  import { CommandError, installBundleContent } from './bundle-install.ts'
@@ -164,6 +165,7 @@ import {
164
165
  parseEntryState,
165
166
  redactSensitive,
166
167
  } from './forms.ts'
168
+ import { HOST_TOKEN_SECONDS, issueHostToken } from './host-token.ts'
167
169
  import { ImageProcessor, parseImagingQuery } from './imaging.ts'
168
170
  import { type BackgroundJobs, createBackgroundJobs } from './jobs.ts'
169
171
  import { configureLogging, logger } from './logging.ts'
@@ -183,6 +185,7 @@ import {
183
185
  import { createRedirectTracker } from './redirects.ts'
184
186
  import { createRemote } from './remote.ts'
185
187
  import { withRemoteMedia } from './remote-media.ts'
188
+ import { unknownHostProvided } from './site-file.ts'
186
189
  import { handleTransferAction, pendingTransfers } from './transfer-dashboard.ts'
187
190
  import {
188
191
  changeUrlOptions,
@@ -216,7 +219,7 @@ import {
216
219
  type HubSocketData,
217
220
  type ServerEventHub,
218
221
  } from './server-events.ts'
219
- import { createSetupRoutes } from './setup.ts'
222
+ import { AttemptLimiter, createSetupRoutes } from './setup.ts'
220
223
  import { siteSearchFor } from './site-search.ts'
221
224
  import { TwoFactorService, USER_TWO_FACTOR_PROVIDER } from './two-factor.ts'
222
225
  import { summariseUpgrades } from './upgrade-summary.ts'
@@ -379,7 +382,7 @@ export async function createServer(config: CromboloConfig = loadConfig()): Promi
379
382
  const cookies = { siteName: config.siteName, securePrefix: config.secureCookies }
380
383
  const names = cookieNames(cookies)
381
384
  // The socket's peer for each request in flight, which only `Bun.serve` knows;
382
- // a request that came some other way (a test, the assistant) has none.
385
+ // a request that came some other way (a test) has none.
383
386
  const peers = new WeakMap<Request, string>()
384
387
  const clientAddress = (request: Request): ClientAddress => ({
385
388
  ipAddress: peers.get(request) ?? null,
@@ -701,6 +704,11 @@ export async function createServer(config: CromboloConfig = loadConfig()): Promi
701
704
  prefix: bundle.prefix,
702
705
  section: bundle.section,
703
706
  })
707
+ for (const name of unknownHostProvided(config))
708
+ log.warning(
709
+ '{name} is listed as host-provided but is not installed here; exports leave it out regardless',
710
+ { name },
711
+ )
704
712
 
705
713
  const poller = new CacheInstructionPoller({
706
714
  db,
@@ -1143,48 +1151,12 @@ export async function createServer(config: CromboloConfig = loadConfig()): Promi
1143
1151
  const hubPath = SERVER_EVENT_HUB_PATH
1144
1152
  const previewHubPath = PREVIEW_HUB_PATH
1145
1153
 
1146
- // Imported only when the feature is configured, so an unconfigured site never
1147
- // loads the assistant, its provider or its tool definitions.
1148
- const assistantPath = `${paths.pluginPath}/api/assistant`
1149
- const assistant =
1150
- config.assistant && servesBackOffice
1151
- ? await import('./assistant.ts').then((module) =>
1152
- module.createAssistantHost({
1153
- config: config.assistant as NonNullable<typeof config.assistant>,
1154
- db,
1155
- schema: createSchemaProposals({ db, config, boot: schema, afterSync }),
1156
- siteName: config.siteName,
1157
- version: VERSION,
1158
- dispatch: (inner) => api.dispatch(inner),
1159
- }),
1160
- )
1161
- : undefined
1162
- if (assistant) {
1163
- log.info('Assistant enabled with {provider}{mcp}', {
1164
- provider: config.assistant?.provider.name,
1165
- mcp: config.assistant?.mcp === true ? ', MCP endpoint served' : '',
1166
- })
1167
- // Checked once at boot so an expired SSO session is reported here rather than
1168
- // as a failed message later. Never awaited into the boot path: the assistant
1169
- // is optional and the site must come up either way.
1170
- void assistant.status(true).then((status) => {
1171
- if (status.ok) {
1172
- log.info('Assistant credentials resolved: {detail}{expires}', {
1173
- detail: status.detail,
1174
- expires: status.expires ? `, expiring ${status.expires}` : '',
1175
- })
1176
- } else {
1177
- log.warning('Assistant cannot reach its model: {detail} {remedy}', {
1178
- detail: status.detail,
1179
- remedy: status.remedy ?? '',
1180
- })
1181
- }
1182
- })
1183
- }
1184
-
1185
- // Imported only when configured, like the assistant: an unconfigured site has no
1186
- // git route and no credentials anywhere near it.
1154
+ // Imported only when configured: an unconfigured site has no git route and no
1155
+ // credentials anywhere near it.
1187
1156
  const auditPath = `${paths.pluginPath}/api/audit`
1157
+ const hostTokenPath = `${paths.pluginPath}/api/host-token`
1158
+ /** Per node: ten a minute for each person, three hundred in all. */
1159
+ const hostTokens = new AttemptLimiter({ max: 10, maxAll: 300, windowMs: 60_000 })
1188
1160
  const auditHost = createAuditHost(db, config.auditRetentionDays)
1189
1161
 
1190
1162
  const gitPath = `${paths.pluginPath}/api/git`
@@ -1205,7 +1177,37 @@ export async function createServer(config: CromboloConfig = loadConfig()): Promi
1205
1177
  })
1206
1178
  }
1207
1179
 
1180
+ /**
1181
+ * Answers on the back office's API paths as on Umbraco's (`contractPathFor`):
1182
+ * a request on the new paths is routed as the contract names it, and an
1183
+ * address it is answered with points back at the new paths.
1184
+ */
1208
1185
  async function fetch(request: Request): Promise<Response> {
1186
+ const url = new URL(request.url)
1187
+ const contract = contractPathFor(paths.backOfficePath, url.pathname)
1188
+ if (!contract) return route(request)
1189
+ url.pathname = contract
1190
+ const moved = new Request(url, request)
1191
+ const peer = peers.get(request)
1192
+ if (peer) peers.set(moved, peer)
1193
+ const response = await route(moved)
1194
+ const location = response.headers.get('location')
1195
+ if (location?.includes(MANAGEMENT_API_PREFIX)) {
1196
+ const headers = new Headers(response.headers)
1197
+ headers.set(
1198
+ 'location',
1199
+ location.replace(MANAGEMENT_API_PREFIX, managementApiPrefix(paths.backOfficePath)),
1200
+ )
1201
+ return new Response(response.body, {
1202
+ status: response.status,
1203
+ statusText: response.statusText,
1204
+ headers,
1205
+ })
1206
+ }
1207
+ return response
1208
+ }
1209
+
1210
+ async function route(request: Request): Promise<Response> {
1209
1211
  const url = new URL(request.url)
1210
1212
  const { pathname } = url
1211
1213
 
@@ -1278,13 +1280,14 @@ export async function createServer(config: CromboloConfig = loadConfig()): Promi
1278
1280
 
1279
1281
  /**
1280
1282
  * The audit entry for a successful write to one of Crombolo's own endpoints,
1281
- * which the contract router does not see. The assistant's are left out: what it
1282
- * changes goes through the router, and is recorded there. docs/audit-log.md.
1283
+ * which the contract router does not see. docs/audit-log.md.
1283
1284
  */
1284
1285
  async function auditPluginWrite(request: Request, pathname: string): Promise<void> {
1285
1286
  const prefix = `${paths.pluginPath}/api/`
1286
1287
  if (request.method === 'GET' || request.method === 'HEAD') return
1287
- if (!pathname.startsWith(prefix) || pathname.startsWith(`${assistantPath}/`)) return
1288
+ if (!pathname.startsWith(prefix)) return
1289
+ // A host token changes nothing here: each one is a log line, not an entry.
1290
+ if (pathname === hostTokenPath) return
1288
1291
  const principal = await authenticate(request)
1289
1292
  if (!principal) return
1290
1293
  const plan = pluginAuditPlan(request.method, pathname.slice(prefix.length))
@@ -1318,20 +1321,6 @@ export async function createServer(config: CromboloConfig = loadConfig()): Promi
1318
1321
  )
1319
1322
  return new Response(null, { status: 303, headers: { location: setup.path } })
1320
1323
 
1321
- // Non-contract, signed-in: the assistant's chat, review and MCP endpoints.
1322
- // Absent configuration there is no `assistant`, so these paths 404 like any
1323
- // other unknown route.
1324
- if (assistant && pathname.startsWith(`${assistantPath}/`)) {
1325
- const principal = await authenticate(request)
1326
- if (!principal) return new Response('Unauthorized', { status: 401 })
1327
- const response = await assistant.handle(
1328
- request,
1329
- pathname.slice(assistantPath.length),
1330
- principal,
1331
- )
1332
- if (response) return response
1333
- }
1334
-
1335
1324
  // Non-contract, Settings: what the repository has against what this site has.
1336
1325
  // Settings and not merely signed in, because the diff is the schema's full
1337
1326
  // text and a commit pushes it under this site's credentials — the same
@@ -1359,8 +1348,7 @@ export async function createServer(config: CromboloConfig = loadConfig()): Promi
1359
1348
  const principal = await authenticate(request)
1360
1349
  if (!principal) return new Response('Unauthorized', { status: 401 })
1361
1350
  // Settings: this applies type changes to the database, which is what every
1362
- // `document-type` write requires, and what the assistant asks of a schema
1363
- // proposal before it writes one.
1351
+ // `document-type` write requires.
1364
1352
  if (!hasSection(principal, 'settings')) return new Response('Forbidden', { status: 403 })
1365
1353
  if (request.method !== 'GET' && request.method !== 'POST') {
1366
1354
  return new Response('Method Not Allowed', { status: 405 })
@@ -1392,8 +1380,7 @@ export async function createServer(config: CromboloConfig = loadConfig()): Promi
1392
1380
  //
1393
1381
  // Signed in and not Settings, although only Settings can open a template:
1394
1382
  // this is the same vocabulary of type and property aliases that the content
1395
- // editor in front of every backoffice user already shows them, and the
1396
- // assistant's review pane loads a template for anyone who may use it.
1383
+ // editor in front of every backoffice user already shows them.
1397
1384
  if (pathname === `${paths.pluginPath}/api/editor-types`) {
1398
1385
  const principal = await authenticate(request)
1399
1386
  if (!principal) return new Response('Unauthorized', { status: 401 })
@@ -1513,6 +1500,39 @@ export async function createServer(config: CromboloConfig = loadConfig()): Promi
1513
1500
  * wherever someone finds the option missing. The provider's `description`
1514
1501
  * is deliberately left out: for a custom adapter it is an internal URL.
1515
1502
  */
1503
+ // Story 178: the back office vouches for its user to the host's own service.
1504
+ if (pathname === hostTokenPath) {
1505
+ if (!config.host) return new Response('Not Found', { status: 404 })
1506
+ if (request.method !== 'POST') return new Response('Method Not Allowed', { status: 405 })
1507
+ if (!isSameOrigin(request, config.applicationUrl || undefined))
1508
+ return new Response('Forbidden', { status: 403 })
1509
+ // The person as they stand now: an ended session, a lock-out or a
1510
+ // disabled account resolves to nobody.
1511
+ const principal = await authenticate(request)
1512
+ if (!principal) return new Response('Unauthorized', { status: 401 })
1513
+ if (hostTokens.blocked(principal.id))
1514
+ return new Response('Too Many Requests', { status: 429, headers: { 'retry-after': '60' } })
1515
+ hostTokens.fail(principal.id)
1516
+ const token = await issueHostToken(config.host, {
1517
+ user: { key: principal.id, name: principal.name },
1518
+ groups: principal.groups.map((group) => group.alias),
1519
+ sections: principal.allowedSections,
1520
+ site: {
1521
+ name: config.siteName,
1522
+ nodeId: schema.nodeId,
1523
+ url: config.applicationUrl || undefined,
1524
+ },
1525
+ })
1526
+ log.info('Issued a host token to {user} for {host}', {
1527
+ user: principal.email,
1528
+ host: config.host.origin,
1529
+ })
1530
+ return Response.json(
1531
+ { token, expiresIn: HOST_TOKEN_SECONDS },
1532
+ { headers: { 'cache-control': 'no-store' } },
1533
+ )
1534
+ }
1535
+
1516
1536
  if (pathname === `${paths.pluginPath}/api/email` && request.method === 'GET') {
1517
1537
  if (!(await authenticate(request))) return new Response('Unauthorized', { status: 401 })
1518
1538
  return Response.json({
@@ -1974,7 +1994,7 @@ export async function createServer(config: CromboloConfig = loadConfig()): Promi
1974
1994
  if (pathname.startsWith(apiPrefix)) {
1975
1995
  if (pathname === `${apiPrefix}openapi.json`) {
1976
1996
  // Umbraco's contract with crombolo's deliberate differences (contracts/src/overrides.ts).
1977
- return new Response(servedContract(), {
1997
+ return new Response(servedContract(managementApiPrefix(paths.backOfficePath)), {
1978
1998
  headers: { 'content-type': 'application/json' },
1979
1999
  })
1980
2000
  }
@@ -2492,9 +2512,10 @@ export async function createServer(config: CromboloConfig = loadConfig()): Promi
2492
2512
  if (!request.headers.has('content-length') && request.headers.has('transfer-encoding'))
2493
2513
  return new Response('Length Required', { status: 411 })
2494
2514
  }
2495
- if (pathname === hubPath || pathname === previewHubPath) {
2515
+ const hubAt = contractPathFor(paths.backOfficePath, pathname) ?? pathname
2516
+ if (hubAt === hubPath || hubAt === previewHubPath) {
2496
2517
  const principal = await authenticate(request)
2497
- const hub = pathname === hubPath ? events : previewHub
2518
+ const hub = hubAt === hubPath ? events : previewHub
2498
2519
  return hub.upgrade(request, bunServer, principal?.id)
2499
2520
  }
2500
2521
  return fetch(request)
@@ -2504,6 +2525,8 @@ export async function createServer(config: CromboloConfig = loadConfig()): Promi
2504
2525
  async close() {
2505
2526
  diagnostics.stop()
2506
2527
  jobs.stop()
2528
+ // A dispatch a commit started finishes before the connection goes.
2529
+ await dispatcher.settled().catch(() => {})
2507
2530
  events.stop()
2508
2531
  previewHub.stop()
2509
2532
  watcher?.close()
package/src/settings.ts CHANGED
@@ -893,19 +893,13 @@ const DECLARED = [
893
893
  env: 'AWS_REGION',
894
894
  kind: 'string',
895
895
  section: 'AWS credentials',
896
- description: 'The AWS region, for SES e-mail and the Bedrock assistant when they set none.',
897
- },
898
- {
899
- env: 'AWS_PROFILE',
900
- kind: 'string',
901
- section: 'AWS credentials',
902
- description: 'The AWS profile the Bedrock assistant signs in with.',
896
+ description: 'The AWS region, for SES e-mail when it sets none.',
903
897
  },
904
898
  {
905
899
  env: 'AWS_ACCESS_KEY_ID',
906
900
  kind: 'string',
907
901
  section: 'AWS credentials',
908
- description: 'A static AWS access key, for SES e-mail and the Bedrock assistant.',
902
+ description: 'A static AWS access key, for SES e-mail.',
909
903
  },
910
904
  {
911
905
  env: 'AWS_SECRET_ACCESS_KEY',
package/src/site-file.ts CHANGED
@@ -98,12 +98,28 @@ async function topLevelNodes(db: Db): Promise<NodeRow[]> {
98
98
  }
99
99
 
100
100
  /** The server bundles the site wires, by package name and version. */
101
+ /**
102
+ * The names in `hostProvided` this installation has not got: neither a wired
103
+ * bundle's package nor an extension discovered in the site. Said once at start
104
+ * rather than refused, so a host can list a bundle it is still rolling out.
105
+ */
106
+ export function unknownHostProvided(
107
+ config: Pick<CromboloConfig, 'hostProvided' | 'siteDir'>,
108
+ ): string[] {
109
+ if (config.hostProvided.length === 0) return []
110
+ const installed = new Set(discoverBundles(config.siteDir).bundles.map((b) => b.packageName))
111
+ return config.hostProvided.filter((name) => !installed.has(name))
112
+ }
113
+
101
114
  function requiredPackages(config: CromboloConfig): Record<string, string> {
102
115
  if (config.bundles.length === 0) return {}
103
116
  const wired = new Set(config.bundles.map((bundle) => bundle.id))
117
+ // The installation's own packages are not the site's to need (story 177).
118
+ const hosts = new Set(config.hostProvided)
104
119
  const required: Record<string, string> = {}
105
120
  for (const found of discoverBundles(config.siteDir).bundles)
106
- if (wired.has(found.id)) required[found.packageName] = found.version
121
+ if (wired.has(found.id) && !hosts.has(found.packageName))
122
+ required[found.packageName] = found.version
107
123
  return required
108
124
  }
109
125