@crombolo/server 0.25.0 → 0.26.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/package.json +14 -14
- package/src/config.ts +24 -9
- package/src/host-token.ts +69 -0
- package/src/index.ts +1 -0
- package/src/ports.ts +6 -7
- package/src/remote.ts +6 -3
- package/src/schema.ts +1 -1
- package/src/server.ts +91 -68
- package/src/settings.ts +2 -8
- package/src/site-file.ts +17 -1
- package/src/adapters/assistant.ts +0 -229
- package/src/adapters/schema-proposals.ts +0 -195
- package/src/assistant.ts +0 -492
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "The crombolo HTTP server: routing, configuration, media stores and background jobs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -30,18 +30,18 @@
|
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@crombolo/api-delivery": "0.
|
|
34
|
-
"@crombolo/api-management": "0.
|
|
35
|
-
"@crombolo/
|
|
36
|
-
"@crombolo/
|
|
37
|
-
"@crombolo/
|
|
38
|
-
"@crombolo/
|
|
39
|
-
"@crombolo/
|
|
40
|
-
"@crombolo/
|
|
41
|
-
"@crombolo/
|
|
42
|
-
"@crombolo/
|
|
43
|
-
"@crombolo/
|
|
44
|
-
"@
|
|
45
|
-
"
|
|
33
|
+
"@crombolo/api-delivery": "0.26.0",
|
|
34
|
+
"@crombolo/api-management": "0.26.0",
|
|
35
|
+
"@crombolo/auth": "0.26.0",
|
|
36
|
+
"@crombolo/backoffice-host": "0.26.0",
|
|
37
|
+
"@crombolo/content": "0.26.0",
|
|
38
|
+
"@crombolo/contracts": "0.26.0",
|
|
39
|
+
"@crombolo/core": "0.26.0",
|
|
40
|
+
"@crombolo/data": "0.26.0",
|
|
41
|
+
"@crombolo/render": "0.26.0",
|
|
42
|
+
"@crombolo/schema": "0.26.0",
|
|
43
|
+
"@crombolo/transfer": "0.26.0",
|
|
44
|
+
"@logtape/logtape": "^2.3.8",
|
|
45
|
+
"jose": "^6.2.12"
|
|
46
46
|
}
|
|
47
47
|
}
|
package/src/config.ts
CHANGED
|
@@ -12,10 +12,10 @@ import {
|
|
|
12
12
|
type RedirectRule,
|
|
13
13
|
type SnapshotLimits,
|
|
14
14
|
} from '@crombolo/render'
|
|
15
|
-
import type { AssistantConfig } from './assistant.ts'
|
|
16
15
|
import type { ServerBundle } from './bundles.ts'
|
|
17
16
|
import type { EmailPort } from './email.ts'
|
|
18
17
|
import type { GitConfig } from './git-routes.ts'
|
|
18
|
+
import { checkHost, type HostConfig } from './host-token.ts'
|
|
19
19
|
import { checkIdentityProviders, type IdentityProvider } from './identity-providers.ts'
|
|
20
20
|
import type { MediaStore } from './media-store.ts'
|
|
21
21
|
import type { SchemaStore } from './schema-store.ts'
|
|
@@ -380,6 +380,13 @@ export interface CromboloConfig {
|
|
|
380
380
|
* (`bundles.ts`, `docs/bundles.md`).
|
|
381
381
|
*/
|
|
382
382
|
bundles: ServerBundle[]
|
|
383
|
+
/**
|
|
384
|
+
* Package names this installation provides to every site it runs, rather
|
|
385
|
+
* than the site choosing them (story 177): a whole-site file leaves them out
|
|
386
|
+
* of what it requires, so the site starts anywhere without them. Set by
|
|
387
|
+
* whoever runs the installation, in code only, as `bundles` is.
|
|
388
|
+
*/
|
|
389
|
+
hostProvided: readonly string[]
|
|
383
390
|
/**
|
|
384
391
|
* Whether installing a bundle from the Marketplace also applies the content it
|
|
385
392
|
* carries — its schema, components and content — straight after `bun add`. On
|
|
@@ -414,12 +421,11 @@ export interface CromboloConfig {
|
|
|
414
421
|
*/
|
|
415
422
|
git: GitConfig | undefined
|
|
416
423
|
/**
|
|
417
|
-
* The
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
* approves each one — it cannot write, and it cannot publish.
|
|
424
|
+
* The host this installation's back office vouches for its user to (story
|
|
425
|
+
* 178): its origin, the key that signs host tokens, and that key's id. From
|
|
426
|
+
* `crombolo.config.ts` only; without it no token is issued.
|
|
421
427
|
*/
|
|
422
|
-
|
|
428
|
+
host: HostConfig | undefined
|
|
423
429
|
}
|
|
424
430
|
|
|
425
431
|
export type SiteConfig = CromboloConfig
|
|
@@ -688,11 +694,13 @@ export function loadConfig(
|
|
|
688
694
|
}),
|
|
689
695
|
// No environment variable: a bundle is an import, which is code.
|
|
690
696
|
bundles: [],
|
|
697
|
+
// Nor here: it is the installation's decision about that code.
|
|
698
|
+
hostProvided: [],
|
|
691
699
|
marketplaceUrl: setting('CROMBOLO_MARKETPLACE_URL') ?? DEFAULTS.marketplaceUrl,
|
|
692
700
|
packageKeyword: setting('CROMBOLO_PACKAGE_KEYWORD') ?? DEFAULTS.packageKeyword,
|
|
693
701
|
npmRegistry: setting('CROMBOLO_NPM_REGISTRY') ?? DEFAULTS.npmRegistry,
|
|
694
|
-
//
|
|
695
|
-
|
|
702
|
+
// Nor here: a host reads its own variables inside `defineConfig`, if it wants them.
|
|
703
|
+
host: undefined,
|
|
696
704
|
}
|
|
697
705
|
const merged: CromboloConfig = { ...fromEnv, ...stripUndefined(overrides) }
|
|
698
706
|
checkIdentityProviders(merged.memberIdentityProviders, 'member')
|
|
@@ -701,6 +709,13 @@ export function loadConfig(
|
|
|
701
709
|
merged.seo = { ...fromEnv.seo, ...stripUndefined(overrides.seo ?? {}) }
|
|
702
710
|
merged.remote = { ...fromEnv.remote, ...stripUndefined(overrides.remote ?? {}) }
|
|
703
711
|
checkApiClient(merged.apiClient)
|
|
712
|
+
checkHost(merged.host)
|
|
713
|
+
// The key itself is refused, so a config left over from before says so rather
|
|
714
|
+
// than starting without the feature it asked for.
|
|
715
|
+
if ('assistant' in overrides)
|
|
716
|
+
throw new Error(
|
|
717
|
+
"The AI assistant was removed from crombolo in 0.26 (story 179), so 'assistant' is no longer a setting. See the 0.26 release notes, and 'Tools a host provides' in docs/bundles.md for how a host offers such a tool now.",
|
|
718
|
+
)
|
|
704
719
|
if (!/^[a-z][a-z0-9-]{0,62}$/.test(merged.remote.environment))
|
|
705
720
|
throw new Error(
|
|
706
721
|
`remote.environment "${merged.remote.environment}" must be lower case letters, digits and dashes.`,
|
|
@@ -798,7 +813,7 @@ export function describeDatabase(
|
|
|
798
813
|
}
|
|
799
814
|
}
|
|
800
815
|
|
|
801
|
-
export const VERSION = '0.
|
|
816
|
+
export const VERSION = '0.26.0'
|
|
802
817
|
|
|
803
818
|
/** A whole number of seconds from the environment; undefined when unset or not one. */
|
|
804
819
|
function numberSetting(name: Parameters<typeof setting>[0]): number | undefined {
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A host token (story 178): the back office's signed statement, for a service
|
|
3
|
+
* the host runs elsewhere, of who is signed in. Short-lived, addressed to the
|
|
4
|
+
* one host origin configured, and signed with a key the host holds.
|
|
5
|
+
* docs/bundles.md, "Tools a host provides".
|
|
6
|
+
*/
|
|
7
|
+
import { SignJWT } from 'jose'
|
|
8
|
+
|
|
9
|
+
/** The installation's host, from `crombolo.config.ts` only. */
|
|
10
|
+
export interface HostConfig {
|
|
11
|
+
/** The host service's origin, which every token is addressed to. */
|
|
12
|
+
origin: string
|
|
13
|
+
/** The HS256 key, at least 32 bytes; it both signs and verifies. */
|
|
14
|
+
signingKey: string
|
|
15
|
+
/** Names the key in each token's header, for a host running many installations. */
|
|
16
|
+
keyId: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** How long a token lasts, in seconds. */
|
|
20
|
+
export const HOST_TOKEN_SECONDS = 300
|
|
21
|
+
|
|
22
|
+
/** Refuses a `host` that could not be used, naming the field. */
|
|
23
|
+
export function checkHost(host: HostConfig | undefined): void {
|
|
24
|
+
if (!host) return
|
|
25
|
+
let url: URL | undefined
|
|
26
|
+
try {
|
|
27
|
+
url = new URL(host.origin)
|
|
28
|
+
} catch {
|
|
29
|
+
url = undefined
|
|
30
|
+
}
|
|
31
|
+
const local = url?.protocol === 'http:' && ['localhost', '127.0.0.1'].includes(url.hostname)
|
|
32
|
+
if (!url || (url.protocol !== 'https:' && !local) || url.origin !== host.origin)
|
|
33
|
+
throw new Error(
|
|
34
|
+
`host.origin "${host.origin}" must be an https origin with no path, such as https://tools.example.com.`,
|
|
35
|
+
)
|
|
36
|
+
if (new TextEncoder().encode(host.signingKey ?? '').length < 32)
|
|
37
|
+
throw new Error('host.signingKey must be at least 32 bytes.')
|
|
38
|
+
if (typeof host.keyId !== 'string' || host.keyId.trim() === '')
|
|
39
|
+
throw new Error('host.keyId must name the key.')
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Who the token is about, and which site says so. */
|
|
43
|
+
export interface HostTokenSubject {
|
|
44
|
+
user: { key: string; name: string }
|
|
45
|
+
groups: readonly string[]
|
|
46
|
+
sections: readonly string[]
|
|
47
|
+
site: { name: string; nodeId: string; url?: string }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function issueHostToken(
|
|
51
|
+
host: HostConfig,
|
|
52
|
+
subject: HostTokenSubject,
|
|
53
|
+
now = new Date(),
|
|
54
|
+
): Promise<string> {
|
|
55
|
+
const issuedAt = Math.floor(now.getTime() / 1000)
|
|
56
|
+
const token = new SignJWT({
|
|
57
|
+
name: subject.user.name,
|
|
58
|
+
groups: [...subject.groups],
|
|
59
|
+
sections: [...subject.sections],
|
|
60
|
+
site: { name: subject.site.name, nodeId: subject.site.nodeId },
|
|
61
|
+
})
|
|
62
|
+
.setProtectedHeader({ alg: 'HS256', kid: host.keyId, typ: 'JWT' })
|
|
63
|
+
.setSubject(subject.user.key)
|
|
64
|
+
.setAudience(host.origin)
|
|
65
|
+
.setIssuedAt(issuedAt)
|
|
66
|
+
.setExpirationTime(issuedAt + HOST_TOKEN_SECONDS)
|
|
67
|
+
if (subject.site.url) token.setIssuer(subject.site.url)
|
|
68
|
+
return token.sign(new TextEncoder().encode(host.signingKey))
|
|
69
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -53,6 +53,7 @@ export * from './forms.ts'
|
|
|
53
53
|
export * from './git.ts'
|
|
54
54
|
export * from './git-github.ts'
|
|
55
55
|
export * from './git-routes.ts'
|
|
56
|
+
export * from './host-token.ts'
|
|
56
57
|
export * from './identity-provider-overrides.ts'
|
|
57
58
|
export * from './identity-providers.ts'
|
|
58
59
|
export * from './imaging.ts'
|
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,
|
|
@@ -474,12 +473,12 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
|
|
|
474
473
|
const deps: ManagementApiDeps = {
|
|
475
474
|
server: createServerPort(options.config, Boolean(sendUserLink)),
|
|
476
475
|
preview: createPreviewPort(options.config, options.previewInApp),
|
|
477
|
-
//
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
476
|
+
// Without an app to preview in, Preview in app contributes no extension.
|
|
477
|
+
manifests: createManifestPort(
|
|
478
|
+
options.paths,
|
|
479
|
+
options.extensions,
|
|
480
|
+
options.previewInApp ? [] : [APP_PREVIEW_MANIFEST_ID],
|
|
481
|
+
),
|
|
483
482
|
localization: createLocalizationPort(
|
|
484
483
|
options.db,
|
|
485
484
|
options.db ? createSchemaFileWriter(options.db, schemaFiles(options.config)) : undefined,
|
package/src/remote.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { tmpdir } from 'node:os'
|
|
|
17
17
|
import { join, sep } from 'node:path'
|
|
18
18
|
import type { Principal } from '@crombolo/api-management'
|
|
19
19
|
import { DEVICE_CODE_GRANT, REMOTE_CLIENT_ID } from '@crombolo/auth'
|
|
20
|
-
import {
|
|
20
|
+
import { managementApiPath, RemotePermissions, type RemoteVerb } from '@crombolo/core'
|
|
21
21
|
import { type Db, type RemoteJob, RemoteJobRepository } from '@crombolo/data'
|
|
22
22
|
import type { ContentSet } from '@crombolo/transfer'
|
|
23
23
|
import { recordAudit } from './adapters/audit.ts'
|
|
@@ -117,14 +117,17 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
117
117
|
protected: settings.protected,
|
|
118
118
|
})
|
|
119
119
|
|
|
120
|
+
// Under the back office, as the editor's own API calls are; a command line
|
|
121
|
+
// follows these addresses rather than building its own.
|
|
122
|
+
const managementApi = managementApiPath(config.backOfficePath.replace(/\/+$/, ''))
|
|
120
123
|
const discovery = (origin: string) => ({
|
|
121
124
|
protocol: 'crombolo-remote',
|
|
122
125
|
versions: [REMOTE_PROTOCOL_VERSION],
|
|
123
126
|
name: config.siteName,
|
|
124
127
|
api: `${origin}${REMOTE_API_PATH}`,
|
|
125
128
|
auth: {
|
|
126
|
-
deviceAuthorization: `${origin}${
|
|
127
|
-
token: `${origin}${
|
|
129
|
+
deviceAuthorization: `${origin}${managementApi}/security/back-office/device`,
|
|
130
|
+
token: `${origin}${managementApi}/security/back-office/token`,
|
|
128
131
|
clientId: REMOTE_CLIENT_ID,
|
|
129
132
|
grantType: DEVICE_CODE_GRANT,
|
|
130
133
|
},
|
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 —
|
|
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
|
|
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
|
|
1147
|
-
//
|
|
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.
|
|
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)
|
|
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
|
|
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
|
|
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
|
-
|
|
2515
|
+
const hubAt = contractPathFor(paths.backOfficePath, pathname) ?? pathname
|
|
2516
|
+
if (hubAt === hubPath || hubAt === previewHubPath) {
|
|
2496
2517
|
const principal = await authenticate(request)
|
|
2497
|
-
const hub =
|
|
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
|
|
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
|
|
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)
|
|
121
|
+
if (wired.has(found.id) && !hosts.has(found.packageName))
|
|
122
|
+
required[found.packageName] = found.version
|
|
107
123
|
return required
|
|
108
124
|
}
|
|
109
125
|
|