@crombolo/server 0.63.0 → 0.65.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 +14 -14
- package/src/access.ts +6 -2
- package/src/adapters/content.ts +66 -11
- package/src/adapters/documents.ts +6 -2
- package/src/adapters/schema-files.ts +19 -27
- package/src/approvals.ts +31 -17
- package/src/bundle-admin.ts +39 -3
- package/src/bundle-reload.ts +2 -1
- package/src/bundles.ts +60 -25
- package/src/config.ts +47 -8
- package/src/content-notifications.ts +6 -3
- package/src/content-operations.ts +4 -3
- package/src/core.ts +362 -136
- package/src/email-notice.ts +2 -2
- package/src/email-settings.ts +394 -0
- package/src/email.ts +9 -4
- package/src/extension-components.ts +20 -4
- package/src/extension-discovery.ts +84 -65
- package/src/form-workflows.ts +3 -3
- package/src/grant-trust.ts +6 -4
- package/src/index.ts +2 -0
- package/src/ports.ts +19 -17
- package/src/routes.ts +22 -3
- package/src/schema-transfer.ts +472 -0
- package/src/seed/values.ts +126 -85
- package/src/server.ts +173 -14
- package/src/settings.ts +14 -10
- package/src/site-public.ts +2 -1
- package/src/status.ts +3 -0
- package/src/telemetry.ts +9 -2
- package/src/trusted-signers-admin.ts +39 -3
- package/src/view-as.ts +95 -0
- package/src/zip.ts +86 -3
package/src/config.ts
CHANGED
|
@@ -91,6 +91,40 @@ export interface RemoteSettings {
|
|
|
91
91
|
oidcIssuers?: string[]
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
export type ContentMode = 'development' | 'production'
|
|
95
|
+
|
|
96
|
+
/** `CROMBOLO_CONTENT_MODE`, refusing the switch it replaced so locked files never quietly unlock. */
|
|
97
|
+
function contentModeSetting(): ContentMode {
|
|
98
|
+
// Read directly: it is no longer a setting, only a name to refuse.
|
|
99
|
+
if (Bun.env.CROMBOLO_CONTENT_FILES_READONLY !== undefined)
|
|
100
|
+
throw new Error(
|
|
101
|
+
'CROMBOLO_CONTENT_FILES_READONLY has gone: set CROMBOLO_CONTENT_MODE to production to keep templates, stylesheets and scripts read-only, or to development (story 343).',
|
|
102
|
+
)
|
|
103
|
+
const value = (setting('CROMBOLO_CONTENT_MODE') ?? 'development').trim().toLowerCase()
|
|
104
|
+
if (value !== 'development' && value !== 'production')
|
|
105
|
+
throw new Error(`CROMBOLO_CONTENT_MODE is "${value}": it is development or production.`)
|
|
106
|
+
return value
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Whether the Delivery API is public, from `CROMBOLO_DELIVERY_API_PRIVATE` (story 348):
|
|
111
|
+
* unset, it serves what the site publishes. The switch it replaced is refused, since
|
|
112
|
+
* ignoring `CROMBOLO_DELIVERY_API_PUBLIC=false` would quietly open a private API.
|
|
113
|
+
*/
|
|
114
|
+
function deliveryApiPublic(): boolean | undefined {
|
|
115
|
+
// Read directly: it is no longer a setting, only a name to refuse.
|
|
116
|
+
if (Bun.env.CROMBOLO_DELIVERY_API_PUBLIC !== undefined)
|
|
117
|
+
throw new Error(
|
|
118
|
+
'CROMBOLO_DELIVERY_API_PUBLIC has gone: set CROMBOLO_DELIVERY_API_PRIVATE=true to keep the Delivery API private, every request needing its key, or leave both unset for it to serve what the site publishes (story 348).',
|
|
119
|
+
)
|
|
120
|
+
const isPrivate = envFlag(setting('CROMBOLO_DELIVERY_API_PRIVATE'))
|
|
121
|
+
return isPrivate === undefined ? undefined : !isPrivate
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Whether the back office must leave templates, stylesheets and scripts alone. */
|
|
125
|
+
export const contentFilesLocked = (config: Pick<CromboloConfig, 'contentMode'>) =>
|
|
126
|
+
config.contentMode === 'production'
|
|
127
|
+
|
|
94
128
|
/** `CROMBOLO_REMOTE_ACCESS`, refusing the switch it replaced so a site does not quietly stop being a remote. */
|
|
95
129
|
function remoteAccessSetting(): RemoteAccess {
|
|
96
130
|
// Read directly: it is no longer a setting, only a name to refuse.
|
|
@@ -342,11 +376,11 @@ export interface CromboloConfig {
|
|
|
342
376
|
*/
|
|
343
377
|
schemaWritable: boolean
|
|
344
378
|
/**
|
|
345
|
-
*
|
|
346
|
-
* for a site whose files come from its repository
|
|
347
|
-
* production too. `
|
|
379
|
+
* `production` keeps templates, stylesheets and scripts read-only in the back
|
|
380
|
+
* office, for a site whose files come from its repository (stories 337, 343).
|
|
381
|
+
* `development` unless set, in production too. `CROMBOLO_CONTENT_MODE`.
|
|
348
382
|
*/
|
|
349
|
-
|
|
383
|
+
contentMode: ContentMode
|
|
350
384
|
/** Sync `schema/` at boot; a pipeline that runs `crombolo types sync` turns this off. */
|
|
351
385
|
syncSchemaAtBoot: boolean
|
|
352
386
|
/** Which database engine; from CROMBOLO_DB. */
|
|
@@ -498,7 +532,7 @@ export interface CromboloConfig {
|
|
|
498
532
|
/**
|
|
499
533
|
* Umbraco's Delivery API (`docs/delivery-api.md`): off unless enabled.
|
|
500
534
|
* `CROMBOLO_DELIVERY_API`, `CROMBOLO_DELIVERY_API_KEY`,
|
|
501
|
-
* `
|
|
535
|
+
* `CROMBOLO_DELIVERY_API_PRIVATE`, `CROMBOLO_DELIVERY_API_MEDIA`,
|
|
502
536
|
* `CROMBOLO_DELIVERY_API_CORS_ORIGINS`, `CROMBOLO_DELIVERY_API_PREVIEW_URL` and
|
|
503
537
|
* `CROMBOLO_DELIVERY_API_PREVIEW_TOKEN_MINUTES`; member
|
|
504
538
|
* sign-in is configured here, since its clients and secrets are a list.
|
|
@@ -904,7 +938,7 @@ export function loadConfig(
|
|
|
904
938
|
? setting('CROMBOLO_SCHEMA_WRITABLE') === 'true'
|
|
905
939
|
: setting('NODE_ENV') !== 'production',
|
|
906
940
|
syncSchemaAtBoot: setting('CROMBOLO_SYNC_SCHEMA_AT_BOOT') !== 'false',
|
|
907
|
-
|
|
941
|
+
contentMode: contentModeSetting(),
|
|
908
942
|
dialect: setting('CROMBOLO_DB') === 'postgres' ? 'postgres' : 'sqlite',
|
|
909
943
|
pgDump: setting('CROMBOLO_PG_DUMP'),
|
|
910
944
|
upgradePolicy:
|
|
@@ -1009,7 +1043,7 @@ export function loadConfig(
|
|
|
1009
1043
|
deliveryApi: stripUndefined({
|
|
1010
1044
|
enabled: envFlag(setting('CROMBOLO_DELIVERY_API')),
|
|
1011
1045
|
apiKey: setting('CROMBOLO_DELIVERY_API_KEY') || undefined,
|
|
1012
|
-
publicAccess:
|
|
1046
|
+
publicAccess: deliveryApiPublic(),
|
|
1013
1047
|
media:
|
|
1014
1048
|
envFlag(setting('CROMBOLO_DELIVERY_API_MEDIA')) === undefined
|
|
1015
1049
|
? undefined
|
|
@@ -1057,6 +1091,11 @@ export function loadConfig(
|
|
|
1057
1091
|
host: undefined,
|
|
1058
1092
|
}
|
|
1059
1093
|
const merged: CromboloConfig = { ...fromEnv, ...stripUndefined(overrides) }
|
|
1094
|
+
// The file is checked as the environment is: an unknown mode must not fall back to editable.
|
|
1095
|
+
if (merged.contentMode !== 'development' && merged.contentMode !== 'production')
|
|
1096
|
+
throw new Error(
|
|
1097
|
+
`contentMode is "${String(merged.contentMode)}" in crombolo.config.ts: it is development or production.`,
|
|
1098
|
+
)
|
|
1060
1099
|
checkIdentityProviders(merged.memberIdentityProviders, 'member')
|
|
1061
1100
|
checkIdentityProviders(merged.backofficeIdentityProviders, 'backoffice')
|
|
1062
1101
|
// Field by field, so a site setting its title suffix keeps the environment's switches.
|
|
@@ -1200,7 +1239,7 @@ export function describeDatabase(
|
|
|
1200
1239
|
}
|
|
1201
1240
|
}
|
|
1202
1241
|
|
|
1203
|
-
export const VERSION = '0.
|
|
1242
|
+
export const VERSION = '0.65.1'
|
|
1204
1243
|
|
|
1205
1244
|
/** A whole number of seconds from the environment; undefined when unset or not one. */
|
|
1206
1245
|
/** A positive number from a setting, else the default. */
|
|
@@ -40,7 +40,7 @@ export interface Actor {
|
|
|
40
40
|
|
|
41
41
|
export interface ContentNotifierOptions {
|
|
42
42
|
/** False when the site cannot send e-mail: nothing is queued, and nothing piles up. */
|
|
43
|
-
canSend: boolean
|
|
43
|
+
canSend: boolean | (() => boolean)
|
|
44
44
|
delayMs?: number
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -82,6 +82,9 @@ const pathIds = (path: string): number[] =>
|
|
|
82
82
|
.filter((id) => Number.isFinite(id) && id > 0)
|
|
83
83
|
|
|
84
84
|
export function createContentNotifier(db: Db, options: ContentNotifierOptions): ContentNotifier {
|
|
85
|
+
// Asked each time: e-mail set up in Settings starts and stops without a restart (story 340).
|
|
86
|
+
const canSend = () =>
|
|
87
|
+
typeof options.canSend === 'function' ? options.canSend() : options.canSend
|
|
85
88
|
const factsFor: ContentNotifier['factsFor'] = async (on, change, actor, detail) => {
|
|
86
89
|
const nodes = new NodeRepository(on)
|
|
87
90
|
const documents = new DocumentRepository(on)
|
|
@@ -126,7 +129,7 @@ export function createContentNotifier(db: Db, options: ContentNotifierOptions):
|
|
|
126
129
|
|
|
127
130
|
const enqueueFor: ContentNotifier['enqueueFor'] = async (on, eventId, facts) => {
|
|
128
131
|
// A site that cannot send e-mail queues nothing, so nothing piles up.
|
|
129
|
-
if (!
|
|
132
|
+
if (!canSend()) return
|
|
130
133
|
const subscriptions = new NotificationRepository(on)
|
|
131
134
|
const actorId = facts.actorUserKey
|
|
132
135
|
? (await new UserRepository(on).byKey(facts.actorUserKey))?.id
|
|
@@ -165,7 +168,7 @@ export function createContentNotifier(db: Db, options: ContentNotifierOptions):
|
|
|
165
168
|
factsFor,
|
|
166
169
|
enqueueFor,
|
|
167
170
|
async raise(change, actor, detail) {
|
|
168
|
-
if (!
|
|
171
|
+
if (!canSend()) return
|
|
169
172
|
try {
|
|
170
173
|
const facts = await factsFor(db, change, actor, detail)
|
|
171
174
|
if (facts) await enqueueFor(db, undefined, facts)
|
|
@@ -14,7 +14,8 @@ import { backOfficeUrl } from './back-office-url.ts'
|
|
|
14
14
|
import type { CromboloConfig } from './config.ts'
|
|
15
15
|
import { createContentEventSink } from './content-events.ts'
|
|
16
16
|
import { createContentNotifier } from './content-notifications.ts'
|
|
17
|
-
import {
|
|
17
|
+
import { emailReady } from './email.ts'
|
|
18
|
+
import { siteEmail } from './email-settings.ts'
|
|
18
19
|
import { MediaFileStore, mediaStoreFor } from './media-files.ts'
|
|
19
20
|
import { createNodeOperations } from './node-operations.ts'
|
|
20
21
|
import { createWebhookService } from './webhooks.ts'
|
|
@@ -31,8 +32,8 @@ export async function siteDocumentOperations(
|
|
|
31
32
|
): Promise<SiteOperations> {
|
|
32
33
|
const state = await currentSchemaState(db)
|
|
33
34
|
const nodeState = { version: state.version, revision: state.revision }
|
|
34
|
-
const email =
|
|
35
|
-
const notifier = createContentNotifier(db, { canSend:
|
|
35
|
+
const email = await siteEmail(db, config)
|
|
36
|
+
const notifier = createContentNotifier(db, { canSend: () => emailReady(email) })
|
|
36
37
|
const webhooks = createWebhookService({
|
|
37
38
|
db,
|
|
38
39
|
schemaDir: config.schemaDir,
|