@crombolo/server 0.36.2 → 0.38.1
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 +15 -13
- package/src/access.ts +29 -27
- package/src/adapters/audit.ts +1 -1
- package/src/adapters/blueprints.ts +22 -13
- package/src/adapters/content.ts +1 -1
- package/src/adapters/dictionary.ts +1 -1
- package/src/adapters/documents.ts +17 -10
- package/src/adapters/elements.ts +47 -37
- package/src/adapters/file-system.ts +1 -1
- package/src/adapters/health.ts +33 -5
- package/src/adapters/media.ts +12 -8
- package/src/adapters/member-groups.ts +8 -6
- package/src/adapters/members.ts +6 -4
- package/src/adapters/public-access.ts +7 -5
- package/src/adapters/redirects.ts +1 -1
- package/src/adapters/references.ts +1 -1
- package/src/adapters/relations.ts +1 -1
- package/src/adapters/schema-files.ts +33 -1
- package/src/adapters/search-index.ts +1 -1
- package/src/adapters/template-files.ts +6 -1
- package/src/adapters/template-query.ts +1 -1
- package/src/adapters/users.ts +13 -13
- package/src/adapters/webhooks.ts +1 -1
- package/src/anonymise-rules.ts +83 -0
- package/src/approvals-api.ts +1 -1
- package/src/approvals.ts +75 -38
- package/src/back-office-url.ts +20 -0
- package/src/backup.ts +26 -2
- package/src/bundle-code.ts +1 -1
- package/src/bundle-grants.ts +265 -0
- package/src/bundle-install.ts +13 -2
- package/src/bundle-media.ts +12 -11
- package/src/bundles.ts +258 -444
- package/src/component-snippets.ts +1 -1
- package/src/components.ts +48 -7
- package/src/config.ts +141 -4
- package/src/content-notifications.ts +13 -9
- package/src/content-operations.ts +23 -65
- package/src/content-query.ts +1 -1
- package/src/core.ts +663 -0
- package/src/cron.ts +139 -0
- package/src/custom-tables.ts +274 -0
- package/src/database.ts +22 -14
- package/src/dictionary-transfer.ts +1 -1
- package/src/git-routes.ts +1 -1
- package/src/identity-provider-overrides.ts +18 -16
- package/src/imaging.ts +65 -15
- package/src/index.ts +14 -1
- package/src/islands.ts +197 -0
- package/src/job-wake.ts +23 -0
- package/src/live-reload.ts +195 -0
- package/src/log-viewer.ts +6 -1
- package/src/marketplace.ts +82 -10
- package/src/media-access.ts +12 -9
- package/src/member-auth.ts +6 -4
- package/src/middleware.ts +236 -0
- package/src/models-builder.ts +1 -1
- package/src/node-operations.ts +122 -0
- package/src/owner-jobs.ts +428 -0
- package/src/ports.ts +39 -154
- package/src/preview-tokens.ts +6 -12
- package/src/remote.ts +3 -1
- package/src/routes.ts +420 -0
- package/src/schema.ts +8 -3
- package/src/seed/compile.ts +7 -5
- package/src/seed/export.ts +6 -4
- package/src/seo.ts +2 -2
- package/src/server.ts +866 -483
- package/src/settings.ts +49 -2
- package/src/site-data.ts +195 -0
- package/src/site-file.ts +30 -4
- package/src/site-queries.ts +140 -0
- package/src/site-replace.ts +25 -19
- package/src/site-sections.ts +1 -1
- package/src/site-services.ts +116 -0
- package/src/status-pages.ts +142 -0
- package/src/status.ts +11 -9
- package/src/url-settings.ts +1 -2
- package/src/webhook-files.ts +18 -1
- package/src/webhooks.ts +83 -15
- package/src/worker-watch.ts +73 -0
- package/src/worker.ts +138 -0
- package/src/bundle-tables.ts +0 -161
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* `<Breadcrumb model={model} nav={nav} />`. `Empty` is also the skeleton a new
|
|
5
5
|
* component starts with.
|
|
6
6
|
*/
|
|
7
|
-
import type { Snippet } from '@crombolo/api-management'
|
|
7
|
+
import type { Snippet } from '@crombolo/api-management/domain'
|
|
8
8
|
|
|
9
9
|
const IMPORTS = "import type { PageProps } from '@crombolo/crombolo'\n\n"
|
|
10
10
|
|
package/src/components.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
|
|
2
2
|
import { join, relative, resolve, sep } from 'node:path'
|
|
3
|
+
import { isClientModule } from '@crombolo/render'
|
|
4
|
+
import { isServerOnly } from './islands.ts'
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* A `.tsx` under the site's `components/` directory.
|
|
@@ -24,6 +26,9 @@ export interface ComponentFile {
|
|
|
24
26
|
|
|
25
27
|
const SOURCE = /\.(tsx|jsx)$/
|
|
26
28
|
|
|
29
|
+
/** Folders whose files are one component each, where a `page.tsx` is just a component named page. */
|
|
30
|
+
const FLAT_FOLDERS = new Set(['blocks', 'emails'])
|
|
31
|
+
|
|
27
32
|
/** An alias that stays inside the root: no climbing, no absolute path, no drive. */
|
|
28
33
|
export function isSafeAlias(alias: string): boolean {
|
|
29
34
|
if (alias.length === 0 || alias.startsWith('/') || alias.includes('\\')) return false
|
|
@@ -47,12 +52,21 @@ export function listComponents(root: string): ComponentFile[] {
|
|
|
47
52
|
}
|
|
48
53
|
}
|
|
49
54
|
walk(root)
|
|
50
|
-
|
|
55
|
+
// `x.tsx` wins over `x/page.tsx`, as it does when rendering.
|
|
56
|
+
const seen = new Set<string>()
|
|
57
|
+
return out
|
|
58
|
+
.sort((a, b) => a.alias.localeCompare(b.alias) || a.path.length - b.path.length)
|
|
59
|
+
.filter((file) => !seen.has(file.alias) && Boolean(seen.add(file.alias)))
|
|
51
60
|
}
|
|
52
61
|
|
|
53
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* The alias a file answers to: its path under the root, without the extension.
|
|
64
|
+
* A folder's `page.tsx` answers to the folder, as a Next.js route does (story 206).
|
|
65
|
+
*/
|
|
54
66
|
export function aliasOf(root: string, path: string): string {
|
|
55
|
-
|
|
67
|
+
const alias = relative(root, path).split(sep).join('/').replace(SOURCE, '')
|
|
68
|
+
const folder = alias.endsWith('/page') ? alias.slice(0, -'/page'.length) : undefined
|
|
69
|
+
return folder && !FLAT_FOLDERS.has(folder) ? folder : alias
|
|
56
70
|
}
|
|
57
71
|
|
|
58
72
|
export interface ComponentProblem {
|
|
@@ -124,6 +138,18 @@ export async function checkComponents(options: {
|
|
|
124
138
|
for (const found of unawaitedMedia(source))
|
|
125
139
|
problems.push({ file: `${where}:${found.line}`, message: found.message })
|
|
126
140
|
|
|
141
|
+
// Browser code (story 209): never imported here, where React or Vue would
|
|
142
|
+
// load into the CMS, and held to the boundary instead.
|
|
143
|
+
if (isClientModule(source) || component.alias.startsWith('client/')) {
|
|
144
|
+
for (const specifier of transpiler.scanImports(source))
|
|
145
|
+
if (isServerOnly(specifier.path))
|
|
146
|
+
problems.push({
|
|
147
|
+
file: where,
|
|
148
|
+
message: `imports ${specifier.path}, which only runs on the server. Code that runs in the browser cannot use it.`,
|
|
149
|
+
})
|
|
150
|
+
continue
|
|
151
|
+
}
|
|
152
|
+
|
|
127
153
|
try {
|
|
128
154
|
// A query does not bust Bun's module cache, so a path imported once in
|
|
129
155
|
// this process answers from the registry. Harmless: the CLI checks each
|
|
@@ -219,7 +245,10 @@ export function withAwaitHint(line: string): string {
|
|
|
219
245
|
* `typescript` is not a dependency of crombolo — a site that has not installed
|
|
220
246
|
* it is told so rather than being made to carry one.
|
|
221
247
|
*/
|
|
222
|
-
async function checkTypes(
|
|
248
|
+
export async function checkTypes(
|
|
249
|
+
siteDir: string,
|
|
250
|
+
options: { signal?: AbortSignal } = {},
|
|
251
|
+
): Promise<ComponentCheckReport['types']> {
|
|
223
252
|
const tsc = join(siteDir, 'node_modules', 'typescript', 'bin', 'tsc')
|
|
224
253
|
if (!existsSync(tsc))
|
|
225
254
|
return {
|
|
@@ -235,6 +264,8 @@ async function checkTypes(siteDir: string): Promise<ComponentCheckReport['types'
|
|
|
235
264
|
stdout: 'pipe',
|
|
236
265
|
stderr: 'pipe',
|
|
237
266
|
})
|
|
267
|
+
// A newer change has made this check's answer stale (story 214).
|
|
268
|
+
options.signal?.addEventListener('abort', () => proc.kill(), { once: true })
|
|
238
269
|
const [out, err] = await Promise.all([
|
|
239
270
|
new Response(proc.stdout).text(),
|
|
240
271
|
new Response(proc.stderr).text(),
|
|
@@ -248,10 +279,20 @@ async function checkTypes(siteDir: string): Promise<ComponentCheckReport['types'
|
|
|
248
279
|
return { checked: true, problems: lines }
|
|
249
280
|
}
|
|
250
281
|
|
|
251
|
-
/** Where a component with this alias lives
|
|
252
|
-
export function componentFileFor(
|
|
282
|
+
/** Where a component with this alias lives: `<alias>.tsx`, or `<alias>/page.tsx` as a folder. */
|
|
283
|
+
export function componentFileFor(
|
|
284
|
+
root: string,
|
|
285
|
+
alias: string,
|
|
286
|
+
options: { folder?: boolean } = {},
|
|
287
|
+
): string {
|
|
253
288
|
if (!isSafeAlias(alias)) throw new Error(`"${alias}" is not a path inside components/`)
|
|
254
|
-
|
|
289
|
+
if (
|
|
290
|
+
!options.folder &&
|
|
291
|
+
existsSync(join(root, alias, 'page.tsx')) &&
|
|
292
|
+
!existsSync(join(root, `${alias}.tsx`))
|
|
293
|
+
)
|
|
294
|
+
return join(root, alias, 'page.tsx')
|
|
295
|
+
return options.folder ? join(root, alias, 'page.tsx') : join(root, `${alias}.tsx`)
|
|
255
296
|
}
|
|
256
297
|
|
|
257
298
|
/** What an e-mail template looks like: a default export over `EmailProps`. */
|
package/src/config.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { hostname, tmpdir } from 'node:os'
|
|
2
2
|
import { join, resolve } from 'node:path'
|
|
3
3
|
import type { DeliveryApiOptions } from '@crombolo/api-delivery'
|
|
4
|
+
import type { MiddlewareChain, SiteRoute } from '@crombolo/common'
|
|
4
5
|
import {
|
|
5
6
|
DEFAULT_BACKOFFICE_PATH,
|
|
6
7
|
DEFAULT_PASSWORD_CONFIGURATION,
|
|
@@ -9,7 +10,10 @@ import {
|
|
|
9
10
|
import {
|
|
10
11
|
type CacheOptions,
|
|
11
12
|
DEFAULT_RENDER_TIMEOUT_MS,
|
|
13
|
+
type PublishedContent,
|
|
12
14
|
type RedirectRule,
|
|
15
|
+
type RequestMember,
|
|
16
|
+
type SiteServices,
|
|
13
17
|
type SnapshotLimits,
|
|
14
18
|
} from '@crombolo/render'
|
|
15
19
|
import type { ServerBundle } from './bundles.ts'
|
|
@@ -18,8 +22,10 @@ import type { GitConfig } from './git-routes.ts'
|
|
|
18
22
|
import { checkHost, type HostConfig } from './host-token.ts'
|
|
19
23
|
import { checkIdentityProviders, type IdentityProvider } from './identity-providers.ts'
|
|
20
24
|
import type { MediaStore } from './media-store.ts'
|
|
25
|
+
import type { JobSchedule } from './owner-jobs.ts'
|
|
21
26
|
import type { SchemaStore } from './schema-store.ts'
|
|
22
27
|
import { setting } from './settings.ts'
|
|
28
|
+
import type { SiteDatabaseConfig, SiteQueryModules } from './site-queries.ts'
|
|
23
29
|
|
|
24
30
|
/**
|
|
25
31
|
* Runtime settings for a site. Umbraco's equivalents live in appsettings.json;
|
|
@@ -27,7 +33,7 @@ import { setting } from './settings.ts'
|
|
|
27
33
|
* `loadConfig` fills anything unset from the environment.
|
|
28
34
|
*/
|
|
29
35
|
/** What a process serves; see `CromboloConfig.role`. */
|
|
30
|
-
export const SERVER_ROLES = ['all', 'api', 'web'] as const
|
|
36
|
+
export const SERVER_ROLES = ['all', 'api', 'web', 'worker'] as const
|
|
31
37
|
|
|
32
38
|
export type ServerRole = (typeof SERVER_ROLES)[number]
|
|
33
39
|
|
|
@@ -117,6 +123,12 @@ export interface CromboloConfig {
|
|
|
117
123
|
*/
|
|
118
124
|
signalRSkipNegotiation: boolean
|
|
119
125
|
development: boolean
|
|
126
|
+
/**
|
|
127
|
+
* Open pages reload when the views, the schema or the content change, and
|
|
128
|
+
* show the background type check's findings (story 214). On in development,
|
|
129
|
+
* except under `bun test`.
|
|
130
|
+
*/
|
|
131
|
+
liveReload: boolean
|
|
120
132
|
/**
|
|
121
133
|
* Whether the cache-busted asset path may be cached immutably. Defaults to
|
|
122
134
|
* `!development`.
|
|
@@ -192,6 +204,22 @@ export interface CromboloConfig {
|
|
|
192
204
|
* template error and its `signal` aborts; 0 for no limit.
|
|
193
205
|
*/
|
|
194
206
|
renderTimeoutMs: number
|
|
207
|
+
/**
|
|
208
|
+
* The site's middleware, by stage (story 210): code it imports and lists,
|
|
209
|
+
* each run in the order given. docs/rendering.md, "Middleware".
|
|
210
|
+
*/
|
|
211
|
+
middleware?: MiddlewareChain<SiteServices, PublishedContent, RequestMember>
|
|
212
|
+
/** How long the whole middleware chain may take, crombolo's own work aside; 0 for no limit. */
|
|
213
|
+
middlewareTimeoutMs: number
|
|
214
|
+
/**
|
|
215
|
+
* The site's own endpoints (story 211), at their paths, ahead of content
|
|
216
|
+
* finding. docs/rendering.md, "Route handlers".
|
|
217
|
+
*/
|
|
218
|
+
routes?: SiteRoute<SiteServices, RequestMember>[]
|
|
219
|
+
/** How long a route handler may take before it answers 504; 0 for no limit. */
|
|
220
|
+
routeTimeoutMs: number
|
|
221
|
+
/** Requests a minute each caller may make to the site's routes, on each server; 0 for no limit. */
|
|
222
|
+
routeRateLimitPerMinute: number
|
|
195
223
|
/** Where `schema/*.toml` lives; sync is skipped when the directory is absent. */
|
|
196
224
|
schemaDir: string
|
|
197
225
|
/** Supplied at deploy time (CROMBOLO_SCHEMA_REVISION); orders deploys within one schema version. */
|
|
@@ -213,12 +241,20 @@ export interface CromboloConfig {
|
|
|
213
241
|
* neither migrates nor seeds, and refuses to boot against a database that
|
|
214
242
|
* has not been migrated yet — that is `api`'s job.
|
|
215
243
|
*
|
|
216
|
-
*
|
|
244
|
+
* - `worker` runs the background jobs and nothing else (story 223): no
|
|
245
|
+
* pages, back office or APIs, only `/health`. Like `web` it never migrates.
|
|
246
|
+
*
|
|
247
|
+
* Every split node holds a database connection and stays coherent through
|
|
217
248
|
* `cache_instruction`, exactly as a load-balanced set already does. Splitting
|
|
218
249
|
* needs Postgres: `locks.ts`'s SQLite manager is an in-process queue, so it
|
|
219
250
|
* coordinates nothing between processes.
|
|
220
251
|
*/
|
|
221
252
|
role: ServerRole
|
|
253
|
+
/**
|
|
254
|
+
* Whether an `all` or `api` node runs the background jobs (`CROMBOLO_JOBS`).
|
|
255
|
+
* False leaves them to a `worker`; the node still queues them.
|
|
256
|
+
*/
|
|
257
|
+
runJobs: boolean
|
|
222
258
|
/**
|
|
223
259
|
* Where the schema files live, when not in `schemaDir` on this disk. Unset means
|
|
224
260
|
* the directory, which is what a repository checkout wants. Set — with
|
|
@@ -361,6 +397,15 @@ export interface CromboloConfig {
|
|
|
361
397
|
* answers on. Every field may also be set in the backoffice, which wins.
|
|
362
398
|
*/
|
|
363
399
|
seo: SeoConfig
|
|
400
|
+
/**
|
|
401
|
+
* Pages in the content tree, by path, that answer a status a page's code ends
|
|
402
|
+
* with (story 206): `notFound`, `unauthorized`, and `error` for the rest.
|
|
403
|
+
*/
|
|
404
|
+
pages?: StatusPagesConfig
|
|
405
|
+
/** Whether a server error shows its message and stack. CROMBOLO_SHOW_ERROR_DETAILS. */
|
|
406
|
+
errors: ErrorsConfig
|
|
407
|
+
/** Where `'use client'` islands' browser code comes from (story 209): built here, unless Vite builds it. */
|
|
408
|
+
islands?: IslandsConfig
|
|
364
409
|
/**
|
|
365
410
|
* Umbraco's Delivery API (`docs/delivery-api.md`): off unless enabled.
|
|
366
411
|
* `CROMBOLO_DELIVERY_API`, `CROMBOLO_DELIVERY_API_KEY`,
|
|
@@ -385,6 +430,25 @@ export interface CromboloConfig {
|
|
|
385
430
|
* (`bundles.ts`, `docs/bundles.md`).
|
|
386
431
|
*/
|
|
387
432
|
bundles: ServerBundle[]
|
|
433
|
+
/**
|
|
434
|
+
* The site's own tables (story 189): `defineSiteTables` steps, migrated with
|
|
435
|
+
* crombolo's, and what an anonymised export may carry of each table.
|
|
436
|
+
* docs/data-model.md, "Custom tables".
|
|
437
|
+
*/
|
|
438
|
+
database?: SiteDatabaseConfig
|
|
439
|
+
/**
|
|
440
|
+
* The site's named queries (story 189): modules, each export a query run as
|
|
441
|
+
* `site().queries.<module>.<export>(…)` against the site's own tables.
|
|
442
|
+
*/
|
|
443
|
+
queries?: SiteQueryModules
|
|
444
|
+
/**
|
|
445
|
+
* The site's background jobs (story 187): modules, each export a job queued
|
|
446
|
+
* as `site().jobs.enqueue('<module>.<export>', payload)` and run on a node
|
|
447
|
+
* that owns writes. docs/rendering.md, "Background jobs".
|
|
448
|
+
*/
|
|
449
|
+
jobs?: SiteQueryModules
|
|
450
|
+
/** When the site's jobs run by themselves: cron expressions in a timezone. */
|
|
451
|
+
schedules?: JobSchedule[]
|
|
388
452
|
/**
|
|
389
453
|
* Package names this installation provides to every site it runs, rather
|
|
390
454
|
* than the site choosing them (story 177): a whole-site file leaves them out
|
|
@@ -466,6 +530,9 @@ export const DEFAULTS = {
|
|
|
466
530
|
componentsDir: 'components',
|
|
467
531
|
componentsCacheDir: join('.crombolo', 'components'),
|
|
468
532
|
renderTimeoutMs: DEFAULT_RENDER_TIMEOUT_MS,
|
|
533
|
+
middlewareTimeoutMs: 2_000,
|
|
534
|
+
routeTimeoutMs: 10_000,
|
|
535
|
+
routeRateLimitPerMinute: 2_000,
|
|
469
536
|
schemaDir: 'schema',
|
|
470
537
|
schemaRevision: '0',
|
|
471
538
|
mediaDir: 'media',
|
|
@@ -501,6 +568,22 @@ function roleFromEnvironment(value: string | undefined): ServerRole {
|
|
|
501
568
|
return value
|
|
502
569
|
}
|
|
503
570
|
|
|
571
|
+
function jobsFromEnvironment(value: string | undefined): boolean {
|
|
572
|
+
if (value === undefined || value === '' || value === 'on') return true
|
|
573
|
+
if (value === 'off') return false
|
|
574
|
+
throw new Error(`CROMBOLO_JOBS must be on or off, not '${value}'.`)
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/** A node told to leave jobs alone, or a worker on a database it cannot share, is refused. */
|
|
578
|
+
function assertJobs(config: Pick<CromboloConfig, 'role' | 'runJobs' | 'dialect'>): void {
|
|
579
|
+
if (!config.runJobs && (config.role === 'web' || config.role === 'worker'))
|
|
580
|
+
throw new Error(
|
|
581
|
+
`CROMBOLO_JOBS=off applies to an api or all node; a ${config.role} node ${config.role === 'web' ? 'never runs jobs' : 'only runs jobs'}.`,
|
|
582
|
+
)
|
|
583
|
+
if (config.role === 'worker' && config.dialect !== 'postgres')
|
|
584
|
+
throw new Error('A worker needs Postgres: SQLite cannot be shared between processes.')
|
|
585
|
+
}
|
|
586
|
+
|
|
504
587
|
/** Which page answers an address nothing else does, optionally for one hostname or language. */
|
|
505
588
|
export interface NotFoundRule {
|
|
506
589
|
/** The page's key. */
|
|
@@ -509,6 +592,38 @@ export interface NotFoundRule {
|
|
|
509
592
|
culture?: string
|
|
510
593
|
}
|
|
511
594
|
|
|
595
|
+
/** A status page for one hostname or language; the most specific match wins. */
|
|
596
|
+
export interface StatusPageRule {
|
|
597
|
+
/** The page's path in the content tree, as a visitor would ask for it. */
|
|
598
|
+
path: string
|
|
599
|
+
host?: string
|
|
600
|
+
culture?: string
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/** A status page: a path, or rules choosing one per hostname or language. */
|
|
604
|
+
export type StatusPage = string | StatusPageRule[]
|
|
605
|
+
|
|
606
|
+
export interface StatusPagesConfig {
|
|
607
|
+
/** 404; wins over `seo.notFoundPage`. */
|
|
608
|
+
notFound?: StatusPage
|
|
609
|
+
/** 401. */
|
|
610
|
+
unauthorized?: StatusPage
|
|
611
|
+
/** 400, 403, 410, 422 and 500. */
|
|
612
|
+
error?: StatusPage
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
export interface IslandsConfig {
|
|
616
|
+
/** A Vite manifest, relative to the site: its build is served, and Crombolo bundles nothing. */
|
|
617
|
+
manifest?: string
|
|
618
|
+
/** A running Vite dev server, such as `http://localhost:5173`, to load islands from in development. */
|
|
619
|
+
devServer?: string
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
export interface ErrorsConfig {
|
|
623
|
+
/** A server error's message, source and stack on the error page. Default: in development only. */
|
|
624
|
+
showDetails: boolean
|
|
625
|
+
}
|
|
626
|
+
|
|
512
627
|
export interface SeoConfig {
|
|
513
628
|
/** Serve `/sitemap.xml`. Default true; CROMBOLO_SITEMAP. */
|
|
514
629
|
sitemap?: boolean
|
|
@@ -522,7 +637,7 @@ export interface SeoConfig {
|
|
|
522
637
|
titleSuffix?: string
|
|
523
638
|
/** Shown when a page without its own image is shared: an address, or a media item's key. */
|
|
524
639
|
defaultImage?: string
|
|
525
|
-
/** A page key, or rules choosing one per hostname or language. */
|
|
640
|
+
/** A page key, or rules choosing one per hostname or language; `pages.notFound` wins. */
|
|
526
641
|
notFoundPage?: string | NotFoundRule[]
|
|
527
642
|
/**
|
|
528
643
|
* Where visitors see the site, when that is not here — an app on another host
|
|
@@ -597,10 +712,18 @@ export function loadConfig(
|
|
|
597
712
|
: {}),
|
|
598
713
|
},
|
|
599
714
|
renderTimeoutMs: Number(setting('CROMBOLO_RENDER_TIMEOUT_MS') ?? DEFAULTS.renderTimeoutMs),
|
|
715
|
+
middlewareTimeoutMs: Number(
|
|
716
|
+
setting('CROMBOLO_MIDDLEWARE_TIMEOUT_MS') ?? DEFAULTS.middlewareTimeoutMs,
|
|
717
|
+
),
|
|
718
|
+
routeTimeoutMs: Number(setting('CROMBOLO_ROUTE_TIMEOUT_MS') ?? DEFAULTS.routeTimeoutMs),
|
|
719
|
+
routeRateLimitPerMinute: Number(
|
|
720
|
+
setting('CROMBOLO_ROUTE_RATE_LIMIT_PER_MINUTE') ?? DEFAULTS.routeRateLimitPerMinute,
|
|
721
|
+
),
|
|
600
722
|
schemaDir: setting('CROMBOLO_SCHEMA_DIR') ?? DEFAULTS.schemaDir,
|
|
601
723
|
schemaRevision: setting('CROMBOLO_SCHEMA_REVISION') ?? DEFAULTS.schemaRevision,
|
|
602
724
|
nodeId: setting('CROMBOLO_NODE_ID') ?? `${hostname()}:${process.pid}`,
|
|
603
725
|
role: roleFromEnvironment(setting('CROMBOLO_ROLE')),
|
|
726
|
+
runJobs: jobsFromEnvironment(setting('CROMBOLO_JOBS')),
|
|
604
727
|
git: undefined,
|
|
605
728
|
schemaStore: undefined,
|
|
606
729
|
schemaCacheDir: setting('CROMBOLO_SCHEMA_CACHE_DIR') ?? join(tmpdir(), 'crombolo-schema'),
|
|
@@ -682,6 +805,9 @@ export function loadConfig(
|
|
|
682
805
|
applyBundleContentOnInstall: setting('CROMBOLO_APPLY_BUNDLE_CONTENT') !== 'false',
|
|
683
806
|
// Resolved again below, once it is known whether a store was configured.
|
|
684
807
|
runtimeInstalls: setting('CROMBOLO_RUNTIME_INSTALLS') !== 'false',
|
|
808
|
+
// Resolved again below, once it is known whether this is development.
|
|
809
|
+
errors: { showDetails: envFlag(setting('CROMBOLO_SHOW_ERROR_DETAILS')) ?? false },
|
|
810
|
+
liveReload: envFlag(setting('CROMBOLO_LIVE_RELOAD')) ?? false,
|
|
685
811
|
seo: stripUndefined({
|
|
686
812
|
sitemap: envFlag(setting('CROMBOLO_SITEMAP')),
|
|
687
813
|
indexable: envFlag(setting('CROMBOLO_INDEXABLE')),
|
|
@@ -734,6 +860,16 @@ export function loadConfig(
|
|
|
734
860
|
// Field by field, so a site setting its title suffix keeps the environment's switches.
|
|
735
861
|
merged.seo = { ...fromEnv.seo, ...stripUndefined(overrides.seo ?? {}) }
|
|
736
862
|
merged.remote = { ...fromEnv.remote, ...stripUndefined(overrides.remote ?? {}) }
|
|
863
|
+
merged.errors = {
|
|
864
|
+
showDetails:
|
|
865
|
+
overrides.errors?.showDetails ??
|
|
866
|
+
envFlag(setting('CROMBOLO_SHOW_ERROR_DETAILS')) ??
|
|
867
|
+
merged.development,
|
|
868
|
+
}
|
|
869
|
+
merged.liveReload =
|
|
870
|
+
overrides.liveReload ??
|
|
871
|
+
envFlag(setting('CROMBOLO_LIVE_RELOAD')) ??
|
|
872
|
+
(merged.development && setting('NODE_ENV') !== 'test')
|
|
737
873
|
checkApiClient(merged.apiClient)
|
|
738
874
|
checkHost(merged.host)
|
|
739
875
|
// The key itself is refused, so a config left over from before says so rather
|
|
@@ -794,6 +930,7 @@ export function loadConfig(
|
|
|
794
930
|
// Checked on the merged value, so a typo in `crombolo.config.ts` is refused on
|
|
795
931
|
// the same terms as one in the environment.
|
|
796
932
|
assertRole(merged.role)
|
|
933
|
+
assertJobs(merged)
|
|
797
934
|
return merged
|
|
798
935
|
}
|
|
799
936
|
|
|
@@ -839,7 +976,7 @@ export function describeDatabase(
|
|
|
839
976
|
}
|
|
840
977
|
}
|
|
841
978
|
|
|
842
|
-
export const VERSION = '0.
|
|
979
|
+
export const VERSION = '0.38.1'
|
|
843
980
|
|
|
844
981
|
/** A whole number of seconds from the environment; undefined when unset or not one. */
|
|
845
982
|
/** A positive number from a setting, else the default. */
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* publish arrive as one e-mail, and a background job on the nodes that run
|
|
10
10
|
* jobs sends them; each person's rows are claimed by one node.
|
|
11
11
|
*/
|
|
12
|
-
import type { RaisedContentChange } from '@crombolo/api-management'
|
|
12
|
+
import type { RaisedContentChange } from '@crombolo/api-management/domain'
|
|
13
13
|
import { hasPathAccess, isValidEmail, ObjectTypes, permissionsForPath } from '@crombolo/core'
|
|
14
14
|
import {
|
|
15
15
|
type ContentNotification,
|
|
@@ -102,10 +102,13 @@ export function createContentNotifier(db: Db, options: ContentNotifierOptions):
|
|
|
102
102
|
}
|
|
103
103
|
let summary = detail ?? null
|
|
104
104
|
if (change.withDescendants) {
|
|
105
|
-
const
|
|
106
|
-
'
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
const row = await on.q
|
|
106
|
+
.selectFrom('node')
|
|
107
|
+
.select((eb) => eb.fn.countAll().as('n'))
|
|
108
|
+
.where('path', 'like', `${node.path},%`)
|
|
109
|
+
.where('node_object_type', '=', ObjectTypes.Document)
|
|
110
|
+
.where('trashed', '=', on.dialect.boolValue(false) as boolean)
|
|
111
|
+
.executeTakeFirst()
|
|
109
112
|
const under = Number(row?.n ?? 0)
|
|
110
113
|
if (under > 0) summary = `and ${under} page${under === 1 ? '' : 's'} under it`
|
|
111
114
|
}
|
|
@@ -136,10 +139,11 @@ export function createContentNotifier(db: Db, options: ContentNotifierOptions):
|
|
|
136
139
|
(id) => id !== actorId,
|
|
137
140
|
)
|
|
138
141
|
if (userIds.length === 0) continue
|
|
139
|
-
const keys = await on.
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
142
|
+
const keys = await on.q
|
|
143
|
+
.selectFrom('user_account')
|
|
144
|
+
.select('key')
|
|
145
|
+
.where('id', 'in', userIds)
|
|
146
|
+
.execute()
|
|
143
147
|
for (const { key } of keys)
|
|
144
148
|
rows.push({
|
|
145
149
|
recipientUserKey: String(key),
|
|
@@ -6,31 +6,17 @@
|
|
|
6
6
|
* the running nodes instead.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
createMediaOperations,
|
|
12
|
-
type DocumentOperations,
|
|
13
|
-
type EventSink,
|
|
14
|
-
type MediaOperations,
|
|
15
|
-
} from '@crombolo/content'
|
|
16
|
-
import {
|
|
17
|
-
appendCacheInstruction,
|
|
18
|
-
currentSchemaState,
|
|
19
|
-
type Db,
|
|
20
|
-
RedirectRepository,
|
|
21
|
-
} from '@crombolo/data'
|
|
9
|
+
import type { DocumentOperations, EventSink, MediaOperations } from '@crombolo/content'
|
|
10
|
+
import { currentSchemaState, type Db } from '@crombolo/data'
|
|
22
11
|
import { PublishedCache } from '@crombolo/render'
|
|
23
12
|
import { createPublishedContentSource } from './adapters/documents.ts'
|
|
24
|
-
import {
|
|
13
|
+
import { backOfficeUrl } from './back-office-url.ts'
|
|
25
14
|
import type { CromboloConfig } from './config.ts'
|
|
26
|
-
import { createContentEventSink
|
|
15
|
+
import { createContentEventSink } from './content-events.ts'
|
|
27
16
|
import { createContentNotifier } from './content-notifications.ts'
|
|
28
|
-
import { writeDomainsFor } from './domains.ts'
|
|
29
17
|
import { resolveEmailPort } from './email.ts'
|
|
30
|
-
import { createFileIntake, TemporaryFileMissingError } from './file-intake.ts'
|
|
31
18
|
import { MediaFileStore, mediaStoreFor } from './media-files.ts'
|
|
32
|
-
import {
|
|
33
|
-
import { createRedirectTracker } from './redirects.ts'
|
|
19
|
+
import { createNodeOperations } from './node-operations.ts'
|
|
34
20
|
import { createWebhookService } from './webhooks.ts'
|
|
35
21
|
|
|
36
22
|
export interface SiteOperations {
|
|
@@ -57,45 +43,21 @@ export async function siteDocumentOperations(
|
|
|
57
43
|
// Recorded only: a running server's dispatcher sends what this records (story 171).
|
|
58
44
|
const events = createContentEventSink({ webhooks, notifier })
|
|
59
45
|
const cache = new PublishedCache(createPublishedContentSource(db, { nodeState }))
|
|
60
|
-
|
|
61
|
-
|
|
46
|
+
// The routes a redirect is tracked from are read from this cache once a change
|
|
47
|
+
// has committed, so the change drops it first.
|
|
48
|
+
const { documents: operations } = createNodeOperations({
|
|
62
49
|
db,
|
|
50
|
+
config,
|
|
51
|
+
cache,
|
|
63
52
|
nodeState,
|
|
53
|
+
nodeId: config.nodeId,
|
|
54
|
+
instructedBy: `cli:${config.nodeId}`,
|
|
55
|
+
mediaFiles: new MediaFileStore(await mediaStoreFor(config)),
|
|
64
56
|
email,
|
|
65
|
-
backOfficeUrl: backOfficeUrl(config),
|
|
66
57
|
notifier,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
cultures,
|
|
71
|
-
expectedHead: approvedHead,
|
|
72
|
-
}),
|
|
73
|
-
unpublish: (key, cultures, actor) =>
|
|
74
|
-
(operations as DocumentOperations).unpublish(actor, key, cultures),
|
|
75
|
-
},
|
|
76
|
-
})
|
|
77
|
-
operations = createDocumentOperations({
|
|
78
|
-
db,
|
|
79
|
-
repository: { nodeState, nodeId: config.nodeId },
|
|
80
|
-
events,
|
|
81
|
-
approvals: approvalsGate(approvals),
|
|
82
|
-
redirects: createRedirectTracker({
|
|
83
|
-
cache,
|
|
84
|
-
redirects: new RedirectRepository(db),
|
|
85
|
-
enabled: config.trackRedirects,
|
|
86
|
-
instruct: () =>
|
|
87
|
-
appendCacheInstruction(db, {
|
|
88
|
-
kind: 'content',
|
|
89
|
-
payload: { redirects: true },
|
|
90
|
-
by: `cli:${config.nodeId}`,
|
|
91
|
-
}),
|
|
92
|
-
}),
|
|
93
|
-
// The routes a redirect is tracked from are read from this cache once a change
|
|
94
|
-
// has committed, so the change has to drop it first.
|
|
95
|
-
onChange: () => cache.invalidate(),
|
|
96
|
-
afterDomains: (node, assignment) => writeDomainsFor(db, config.siteDir, node, assignment),
|
|
97
|
-
refusalReason: (error) =>
|
|
98
|
-
error instanceof TemporaryFileMissingError ? error.message : undefined,
|
|
58
|
+
contentEvents: events,
|
|
59
|
+
webhooks,
|
|
60
|
+
backOfficeUrl: backOfficeUrl(config),
|
|
99
61
|
})
|
|
100
62
|
return { operations, events }
|
|
101
63
|
}
|
|
@@ -118,16 +80,12 @@ export async function siteMediaOperations(
|
|
|
118
80
|
secretKey: config.secretKey,
|
|
119
81
|
bundles: config.bundles,
|
|
120
82
|
})
|
|
121
|
-
return
|
|
83
|
+
return createNodeOperations({
|
|
122
84
|
db,
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
files,
|
|
130
|
-
refusalReason: (error) =>
|
|
131
|
-
error instanceof TemporaryFileMissingError ? error.message : undefined,
|
|
132
|
-
})
|
|
85
|
+
config,
|
|
86
|
+
nodeState: { version: state.version, revision: state.revision },
|
|
87
|
+
nodeId: config.nodeId,
|
|
88
|
+
mediaFiles: files,
|
|
89
|
+
webhooks,
|
|
90
|
+
}).media
|
|
133
91
|
}
|
package/src/content-query.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* some group could withhold it, and a property the user cannot read may not be
|
|
5
5
|
* filtered or sorted on.
|
|
6
6
|
*/
|
|
7
|
-
import type { Principal } from '@crombolo/api-management'
|
|
7
|
+
import type { Principal } from '@crombolo/api-management/domain'
|
|
8
8
|
import {
|
|
9
9
|
DocumentPermissions,
|
|
10
10
|
type GroupGrant,
|