@crombolo/server 0.34.0 → 0.36.2
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 +12 -12
- package/src/adapters/audit.ts +1 -0
- package/src/adapters/bundles.ts +5 -4
- package/src/adapters/documents.ts +48 -22
- package/src/bundle-build.ts +7 -1
- package/src/bundle-code.ts +10 -71
- package/src/bundle-media.ts +613 -0
- package/src/bundles.ts +511 -57
- package/src/components.ts +58 -0
- package/src/config.ts +17 -1
- package/src/content-events.ts +11 -6
- package/src/delivery-media.ts +58 -0
- package/src/image-metadata.ts +355 -0
- package/src/imaging.ts +98 -0
- package/src/index.ts +3 -0
- package/src/media-access.ts +337 -0
- package/src/member-auth.ts +24 -3
- package/src/ports.ts +7 -2
- package/src/rate-limit.ts +54 -0
- package/src/schema.ts +78 -8
- package/src/seed/export.ts +16 -6
- package/src/seo.ts +5 -6
- package/src/server.ts +347 -73
- package/src/settings.ts +8 -0
- package/src/site-file.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.2",
|
|
4
4
|
"description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. The crombolo HTTP server: routing, configuration, media stores and background jobs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -30,17 +30,17 @@
|
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@crombolo/api-delivery": "0.
|
|
34
|
-
"@crombolo/api-management": "0.
|
|
35
|
-
"@crombolo/auth": "0.
|
|
36
|
-
"@crombolo/backoffice-host": "0.
|
|
37
|
-
"@crombolo/content": "0.
|
|
38
|
-
"@crombolo/contracts": "0.
|
|
39
|
-
"@crombolo/core": "0.
|
|
40
|
-
"@crombolo/data": "0.
|
|
41
|
-
"@crombolo/render": "0.
|
|
42
|
-
"@crombolo/schema": "0.
|
|
43
|
-
"@crombolo/transfer": "0.
|
|
33
|
+
"@crombolo/api-delivery": "0.36.2",
|
|
34
|
+
"@crombolo/api-management": "0.36.2",
|
|
35
|
+
"@crombolo/auth": "0.36.2",
|
|
36
|
+
"@crombolo/backoffice-host": "0.36.2",
|
|
37
|
+
"@crombolo/content": "0.36.2",
|
|
38
|
+
"@crombolo/contracts": "0.36.2",
|
|
39
|
+
"@crombolo/core": "0.36.2",
|
|
40
|
+
"@crombolo/data": "0.36.2",
|
|
41
|
+
"@crombolo/render": "0.36.2",
|
|
42
|
+
"@crombolo/schema": "0.36.2",
|
|
43
|
+
"@crombolo/transfer": "0.36.2",
|
|
44
44
|
"@logtape/logtape": "^2.3.8",
|
|
45
45
|
"jose": "^6.2.12"
|
|
46
46
|
}
|
package/src/adapters/audit.ts
CHANGED
|
@@ -186,6 +186,7 @@ const PLUGIN_AREAS: Record<string, { category: AuditCategory; entityType: string
|
|
|
186
186
|
seo: { category: 'settings', entityType: 'SeoSettings' },
|
|
187
187
|
bundles: { category: 'system', entityType: 'Bundle' },
|
|
188
188
|
forms: { category: 'content', entityType: 'Form' },
|
|
189
|
+
'media-access': { category: 'media', entityType: 'MediaAccess' },
|
|
189
190
|
}
|
|
190
191
|
|
|
191
192
|
const PLUGIN_ACTIONS: Record<string, string> = {
|
package/src/adapters/bundles.ts
CHANGED
|
@@ -180,6 +180,7 @@ export function createPackagePort(db: Db, options: PackagePortOptions): PackageP
|
|
|
180
180
|
*/
|
|
181
181
|
const contentEntries = async (
|
|
182
182
|
from: PackageDefinition,
|
|
183
|
+
withMedia: boolean,
|
|
183
184
|
): Promise<{ set: ContentSet | undefined; blobs: ReadonlyMap<string, Uint8Array> }> => {
|
|
184
185
|
const groups: Array<{ refs: string[]; descendants: boolean }> = [
|
|
185
186
|
{
|
|
@@ -208,7 +209,7 @@ export function createPackagePort(db: Db, options: PackagePortOptions): PackageP
|
|
|
208
209
|
descendants: group.descendants,
|
|
209
210
|
snapshot: 'published',
|
|
210
211
|
blueprints: false,
|
|
211
|
-
withBlobs:
|
|
212
|
+
withBlobs: withMedia,
|
|
212
213
|
siteName: options.siteName,
|
|
213
214
|
nodeId: options.nodeId,
|
|
214
215
|
})
|
|
@@ -220,7 +221,7 @@ export function createPackagePort(db: Db, options: PackagePortOptions): PackageP
|
|
|
220
221
|
if (!merged) return { set: undefined, blobs: new Map() }
|
|
221
222
|
|
|
222
223
|
const { bytes } =
|
|
223
|
-
blobKeys.size > 0
|
|
224
|
+
withMedia && blobKeys.size > 0
|
|
224
225
|
? await readBlobs(options.mediaStore, [...blobKeys])
|
|
225
226
|
: { bytes: new Map<string, Uint8Array>() }
|
|
226
227
|
return { set: merged, blobs: bytes }
|
|
@@ -272,7 +273,7 @@ export function createPackagePort(db: Db, options: PackagePortOptions): PackageP
|
|
|
272
273
|
* name, a version and the core it was written for, so the download is
|
|
273
274
|
* something `bun add ./file.tgz` and `bun publish` take as it is.
|
|
274
275
|
*/
|
|
275
|
-
async build(id): Promise<BuiltPackage | undefined> {
|
|
276
|
+
async build(id, buildOptions = {}): Promise<BuiltPackage | undefined> {
|
|
276
277
|
const row = await bundles.byId(id)
|
|
277
278
|
if (!row) return undefined
|
|
278
279
|
const from = definition(row)
|
|
@@ -298,7 +299,7 @@ export function createPackagePort(db: Db, options: PackagePortOptions): PackageP
|
|
|
298
299
|
},
|
|
299
300
|
)
|
|
300
301
|
|
|
301
|
-
const content = await contentEntries(from)
|
|
302
|
+
const content = await contentEntries(from, buildOptions.withMedia === true)
|
|
302
303
|
// A package with nothing picked is still a bundle: an empty selection
|
|
303
304
|
// produces an empty set rather than throwing, which is what gives a
|
|
304
305
|
// schema-only package a manifest of its own.
|
|
@@ -33,7 +33,13 @@ import {
|
|
|
33
33
|
readUrlOptions,
|
|
34
34
|
WriteRejectedError,
|
|
35
35
|
} from '@crombolo/data'
|
|
36
|
-
import type {
|
|
36
|
+
import type {
|
|
37
|
+
MediaSource,
|
|
38
|
+
PublishedCache,
|
|
39
|
+
PublishedContentSource,
|
|
40
|
+
PublishedMediaNode,
|
|
41
|
+
PublishedNode,
|
|
42
|
+
} from '@crombolo/render'
|
|
37
43
|
import {
|
|
38
44
|
DOMAINS_FILE,
|
|
39
45
|
nodeReferenceFor,
|
|
@@ -519,27 +525,6 @@ export function createPublishedContentSource(
|
|
|
519
525
|
})),
|
|
520
526
|
}))
|
|
521
527
|
},
|
|
522
|
-
async loadMedia() {
|
|
523
|
-
const media = new DocumentRepository(db, { ...options, kind: 'media' })
|
|
524
|
-
return (await media.loadCurrent()).map((item) => ({
|
|
525
|
-
key: item.key,
|
|
526
|
-
id: item.id,
|
|
527
|
-
name: item.name,
|
|
528
|
-
mediaTypeAlias: item.contentTypeAlias,
|
|
529
|
-
parentId: item.parentId,
|
|
530
|
-
sortOrder: item.sortOrder,
|
|
531
|
-
createDate: item.createDate,
|
|
532
|
-
updateDate: item.updateDate,
|
|
533
|
-
properties: item.values.map((value) => ({
|
|
534
|
-
alias: value.alias,
|
|
535
|
-
editorAlias: value.editorAlias ?? '',
|
|
536
|
-
culture: value.culture,
|
|
537
|
-
segment: value.segment,
|
|
538
|
-
value: toPublishedValue(value.editorAlias, value.value),
|
|
539
|
-
config: value.config,
|
|
540
|
-
})),
|
|
541
|
-
}))
|
|
542
|
-
},
|
|
543
528
|
async loadLanguages() {
|
|
544
529
|
return (await new LanguageRepository(db).all()).map((l) => ({
|
|
545
530
|
isoCode: l.isoCode,
|
|
@@ -621,6 +606,47 @@ export function createPublishedContentSource(
|
|
|
621
606
|
}
|
|
622
607
|
}
|
|
623
608
|
|
|
609
|
+
/**
|
|
610
|
+
* Where the media cache fills from (story 197): items by key, and by the file
|
|
611
|
+
* address `file_url` indexes, with the values an editor sees now — media has
|
|
612
|
+
* no publish — and its own access settings.
|
|
613
|
+
*/
|
|
614
|
+
export function createMediaSource(
|
|
615
|
+
db: Db,
|
|
616
|
+
options: Omit<DocumentRepositoryOptions, 'kind'> = {},
|
|
617
|
+
): MediaSource {
|
|
618
|
+
const media = new DocumentRepository(db, { ...options, kind: 'media' })
|
|
619
|
+
const shaped = (items: Awaited<ReturnType<DocumentRepository['loadCurrent']>>) =>
|
|
620
|
+
items.map(
|
|
621
|
+
(item): PublishedMediaNode => ({
|
|
622
|
+
key: item.key,
|
|
623
|
+
id: item.id,
|
|
624
|
+
name: item.name,
|
|
625
|
+
mediaTypeAlias: item.contentTypeAlias,
|
|
626
|
+
parentId: item.parentId,
|
|
627
|
+
path: item.path,
|
|
628
|
+
access: item.access,
|
|
629
|
+
sortOrder: item.sortOrder,
|
|
630
|
+
createDate: item.createDate,
|
|
631
|
+
updateDate: item.updateDate,
|
|
632
|
+
properties: item.values.map((value) => ({
|
|
633
|
+
alias: value.alias,
|
|
634
|
+
editorAlias: value.editorAlias ?? '',
|
|
635
|
+
culture: value.culture,
|
|
636
|
+
segment: value.segment,
|
|
637
|
+
value: toPublishedValue(value.editorAlias, value.value),
|
|
638
|
+
config: value.config,
|
|
639
|
+
})),
|
|
640
|
+
}),
|
|
641
|
+
)
|
|
642
|
+
return {
|
|
643
|
+
loadMediaByKeys: async (keys) =>
|
|
644
|
+
keys.length === 0 ? [] : shaped(await media.loadCurrent({ keys })),
|
|
645
|
+
loadMediaByUrls: async (urls) =>
|
|
646
|
+
urls.length === 0 ? [] : shaped(await media.loadCurrent({ urls })),
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
624
650
|
/** A document's current draft in the shape the renderer takes, for preview. */
|
|
625
651
|
export async function loadDraftNode(
|
|
626
652
|
db: Db,
|
package/src/bundle-build.ts
CHANGED
|
@@ -35,6 +35,12 @@ export interface BundleBuildOptions {
|
|
|
35
35
|
* `package.json` (story 192). Neither: the bundle carries no code.
|
|
36
36
|
*/
|
|
37
37
|
code?: readonly string[]
|
|
38
|
+
/**
|
|
39
|
+
* Carry the seed's media files (story 195). On unless turned off, so seeding
|
|
40
|
+
* a site still brings its media; `crombolo bundle build` turns it off unless
|
|
41
|
+
* `--with-media` is passed.
|
|
42
|
+
*/
|
|
43
|
+
media?: boolean
|
|
38
44
|
}
|
|
39
45
|
|
|
40
46
|
export interface BundleBuildResult {
|
|
@@ -140,7 +146,7 @@ export async function buildBundleFromDirectory(
|
|
|
140
146
|
},
|
|
141
147
|
}
|
|
142
148
|
const files = writeBundlePackage(
|
|
143
|
-
writeBundle(set, seed.blobs, [
|
|
149
|
+
writeBundle(set, options.media === false ? new Map() : seed.blobs, [
|
|
144
150
|
...sections,
|
|
145
151
|
...(code ? readCodeFiles(dir, code.paths) : []),
|
|
146
152
|
]),
|
package/src/bundle-code.ts
CHANGED
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
readFileSync,
|
|
14
14
|
rmSync,
|
|
15
15
|
symlinkSync,
|
|
16
|
-
writeFileSync,
|
|
17
16
|
} from 'node:fs'
|
|
18
17
|
import { tmpdir } from 'node:os'
|
|
19
18
|
import { dirname, join, relative } from 'node:path'
|
|
@@ -25,15 +24,11 @@ import {
|
|
|
25
24
|
resolvePackageDir,
|
|
26
25
|
} from '@crombolo/backoffice-host'
|
|
27
26
|
import { loadBundleCode } from '@crombolo/transfer'
|
|
28
|
-
import { type ServerBundle, validateServerBundles } from './bundles.ts'
|
|
29
27
|
import { VERSION } from './config.ts'
|
|
30
28
|
|
|
31
29
|
const SCOPE = '@crombolo/'
|
|
32
30
|
const CORE_PACKAGE = '@crombolo/crombolo'
|
|
33
31
|
|
|
34
|
-
/** How long reading a site's config may take before it is taken to have hung. */
|
|
35
|
-
const CONFIG_TIMEOUT_MS = 60_000
|
|
36
|
-
|
|
37
32
|
export interface BundleCodeOptions {
|
|
38
33
|
/** The CMS version the code is checked against; this one by default. */
|
|
39
34
|
coreVersion?: string
|
|
@@ -42,8 +37,8 @@ export interface BundleCodeOptions {
|
|
|
42
37
|
export interface BundleCodeCheck {
|
|
43
38
|
/** Every reason the code cannot run here; empty when it can. */
|
|
44
39
|
problems: string[]
|
|
45
|
-
/** The
|
|
46
|
-
|
|
40
|
+
/** The ids of the server bundles the code's packages carry. */
|
|
41
|
+
serverBundles: string[]
|
|
47
42
|
/** How many files the bundle's code is. */
|
|
48
43
|
files: number
|
|
49
44
|
}
|
|
@@ -128,63 +123,11 @@ function linkCms(json: PackageJson, dir: string): string[] {
|
|
|
128
123
|
return problems
|
|
129
124
|
}
|
|
130
125
|
|
|
131
|
-
const MARKER = '@@crombolo-bundles@@'
|
|
132
|
-
|
|
133
|
-
/** Run in a process of its own: the wired bundles, as data, after a marker line. */
|
|
134
|
-
const READ_CONFIG = `const config = (await import(process.argv[2])).default ?? {}
|
|
135
|
-
const bundles = (config.bundles ?? []).map((b) => ({
|
|
136
|
-
id: b.id,
|
|
137
|
-
section: b.section,
|
|
138
|
-
capabilities: b.capabilities ?? [],
|
|
139
|
-
routes: (b.routes ?? []).map((r) => ({ method: r.method, path: r.path })),
|
|
140
|
-
...(b.tables ? { tables: b.tables } : {}),
|
|
141
|
-
}))
|
|
142
|
-
process.stdout.write('\\n${MARKER}' + JSON.stringify(bundles) + '\\n')
|
|
143
|
-
`
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* The bundles `crombolo.config.ts` wires, read in a `bun` process given none
|
|
147
|
-
* of the caller's environment, so a config that reads a secret finds none and
|
|
148
|
-
* one that hangs is stopped.
|
|
149
|
-
*/
|
|
150
|
-
async function wiredBundles(dir: string): Promise<{ bundles: ServerBundle[]; problem?: string }> {
|
|
151
|
-
const config = join(dir, 'crombolo.config.ts')
|
|
152
|
-
if (!existsSync(config)) return { bundles: [] }
|
|
153
|
-
const scratch = mkdtempSync(join(tmpdir(), 'crombolo-read-config-'))
|
|
154
|
-
try {
|
|
155
|
-
const script = join(scratch, 'read-config.ts')
|
|
156
|
-
writeFileSync(script, READ_CONFIG)
|
|
157
|
-
const run = Bun.spawn([process.execPath, script, config], {
|
|
158
|
-
cwd: dir,
|
|
159
|
-
env: {},
|
|
160
|
-
stdout: 'pipe',
|
|
161
|
-
stderr: 'pipe',
|
|
162
|
-
})
|
|
163
|
-
const timer = setTimeout(() => run.kill(), CONFIG_TIMEOUT_MS)
|
|
164
|
-
const [out, err, code] = await Promise.all([
|
|
165
|
-
new Response(run.stdout).text(),
|
|
166
|
-
new Response(run.stderr).text(),
|
|
167
|
-
run.exited,
|
|
168
|
-
])
|
|
169
|
-
clearTimeout(timer)
|
|
170
|
-
const marker = out.split('\n').find((line) => line.startsWith(MARKER))
|
|
171
|
-
if (code !== 0 || !marker) {
|
|
172
|
-
const tail = err.trim().split('\n').slice(-5).join(' / ')
|
|
173
|
-
return {
|
|
174
|
-
bundles: [],
|
|
175
|
-
problem: `crombolo.config.ts could not be read: ${tail || `exit ${code}`}`,
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return { bundles: JSON.parse(marker.slice(MARKER.length)) as ServerBundle[] }
|
|
179
|
-
} finally {
|
|
180
|
-
rmSync(scratch, { recursive: true, force: true })
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
126
|
/**
|
|
185
127
|
* Every reason a bundle's code cannot run on this CMS: its hash, a frozen
|
|
186
|
-
* install, `@crombolo/*` installed beside it, and the
|
|
187
|
-
*
|
|
128
|
+
* install, `@crombolo/*` installed beside it, and the bundle packages it
|
|
129
|
+
* declares. All of them, not the first. The site's code is never run here: a
|
|
130
|
+
* host has not yet accepted it, so its config's wiring is checked by the boot.
|
|
188
131
|
*/
|
|
189
132
|
export async function checkBundleCode(
|
|
190
133
|
packageDir: string,
|
|
@@ -192,10 +135,10 @@ export async function checkBundleCode(
|
|
|
192
135
|
): Promise<BundleCodeCheck> {
|
|
193
136
|
const coreVersion = options.coreVersion ?? VERSION
|
|
194
137
|
const loaded = loadBundleCode(packageDir)
|
|
195
|
-
if (!loaded.dir) return { problems: loaded.problems,
|
|
138
|
+
if (!loaded.dir) return { problems: loaded.problems, serverBundles: [], files: 0 }
|
|
196
139
|
const result: BundleCodeCheck = {
|
|
197
140
|
problems: [...loaded.problems],
|
|
198
|
-
|
|
141
|
+
serverBundles: [],
|
|
199
142
|
files: loaded.paths.length,
|
|
200
143
|
}
|
|
201
144
|
const json = JSON.parse(readFileSync(join(loaded.dir, 'package.json'), 'utf8')) as PackageJson
|
|
@@ -215,20 +158,16 @@ export async function checkBundleCode(
|
|
|
215
158
|
)
|
|
216
159
|
result.problems.push(...linkCms(json, work))
|
|
217
160
|
|
|
218
|
-
const read = await wiredBundles(work)
|
|
219
|
-
if (read.problem) result.problems.push(read.problem)
|
|
220
|
-
result.wired = read.bundles.map((bundle) => bundle.id)
|
|
221
|
-
|
|
222
161
|
const discovered = discoverBundles(work)
|
|
223
162
|
for (const entry of discovered.problems)
|
|
224
163
|
for (const problem of entry.problems) result.problems.push(`${entry.packageName}: ${problem}`)
|
|
225
|
-
const wired = new Set(result.wired)
|
|
226
164
|
for (const bundle of discovered.bundles) {
|
|
227
|
-
if (wired.has(bundle.id)) continue
|
|
228
165
|
const peer = peerRangeProblem(bundle, coreVersion)
|
|
229
166
|
if (peer) result.problems.push(peer)
|
|
230
167
|
}
|
|
231
|
-
result.
|
|
168
|
+
result.serverBundles = discovered.bundles
|
|
169
|
+
.filter((bundle) => bundle.carries.server)
|
|
170
|
+
.map((bundle) => bundle.id)
|
|
232
171
|
return result
|
|
233
172
|
} finally {
|
|
234
173
|
rmSync(work, { recursive: true, force: true })
|