@crombolo/server 0.62.0 → 0.64.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/access.ts +5 -5
- package/src/adapters/content.ts +79 -12
- package/src/adapters/documents.ts +6 -2
- package/src/adapters/file-system.ts +27 -3
- package/src/adapters/schema-files.ts +19 -27
- package/src/adapters/template-files.ts +10 -0
- package/src/adapters/users.ts +55 -84
- package/src/approvals.ts +2 -2
- package/src/bundle-admin.ts +21 -1
- package/src/bundle-api.ts +1 -3
- package/src/bundle-install.ts +28 -5
- package/src/bundle-sections.ts +10 -0
- package/src/config.ts +32 -1
- package/src/content-notifications.ts +6 -3
- package/src/content-operations.ts +4 -3
- package/src/content-query.ts +2 -4
- package/src/core.ts +11 -3
- package/src/email-notice.ts +2 -2
- package/src/email-settings.ts +394 -0
- package/src/email.ts +9 -4
- package/src/form-workflows.ts +3 -3
- package/src/grant-policy.ts +23 -3
- package/src/grant-trust.ts +73 -0
- package/src/index.ts +3 -0
- package/src/marketplace.ts +14 -6
- package/src/ports.ts +37 -18
- package/src/provenance.ts +13 -1
- package/src/remote.ts +23 -8
- package/src/schema-transfer.ts +472 -0
- package/src/seed/values.ts +126 -85
- package/src/server.ts +116 -11
- package/src/settings.ts +9 -0
- package/src/site-public.ts +2 -1
- package/src/site-trust.ts +16 -0
- package/src/status.ts +3 -0
- package/src/telemetry.ts +9 -2
- package/src/transfer-dashboard.ts +3 -0
- package/src/zip.ts +86 -3
package/src/seed/values.ts
CHANGED
|
@@ -5,18 +5,21 @@
|
|
|
5
5
|
* `content` commands read `--set`; and stored values back into that shorthand,
|
|
6
6
|
* as `content export` and `content show` write them.
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
type Block,
|
|
10
|
+
type ContentTypeAggregate,
|
|
11
|
+
dateFromText,
|
|
12
|
+
isBlockValue,
|
|
13
|
+
normaliseUuid,
|
|
14
|
+
readBlocks,
|
|
15
|
+
SINGLE_BLOCK_EDITOR_ALIAS,
|
|
16
|
+
} from '@crombolo/core'
|
|
9
17
|
import { ContentTypeRepository, DataTypeRepository, type Db, looksLikeKey } from '@crombolo/data'
|
|
10
18
|
import { blockKey, pickKey } from './keys.ts'
|
|
11
19
|
|
|
12
20
|
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
13
21
|
typeof value === 'object' && value !== null && !Array.isArray(value) && !(value instanceof Date)
|
|
14
22
|
|
|
15
|
-
const BLOCK_LAYOUT = {
|
|
16
|
-
'Umbraco.BlockList': 'Umbraco.BlockList',
|
|
17
|
-
'Umbraco.BlockGrid': 'Umbraco.BlockGrid',
|
|
18
|
-
} as const
|
|
19
|
-
|
|
20
23
|
/** A block's alias: a name a view or a command picks it out by (story 253). */
|
|
21
24
|
export const BLOCK_ALIAS = /^[A-Za-z][A-Za-z0-9_-]*$/
|
|
22
25
|
|
|
@@ -136,58 +139,91 @@ export function valueWriter(lookup: SchemaLookup, refs: ValueRefs) {
|
|
|
136
139
|
return { ok: true, data: { key, contentTypeKey: type.key, values: values.value } }
|
|
137
140
|
}
|
|
138
141
|
|
|
142
|
+
/**
|
|
143
|
+
* Blocks from their shorthand: a list of `{ type, alias, values, settings }`,
|
|
144
|
+
* a grid block's `areas` as `[{ key, blocks = [ … ] }]`, and a Single Block's one
|
|
145
|
+
* block as a table (story 345). A value already in the stored shape passes.
|
|
146
|
+
*/
|
|
139
147
|
const blocks = async (
|
|
140
|
-
editor:
|
|
148
|
+
editor: string,
|
|
141
149
|
raw: unknown,
|
|
142
150
|
owner: string,
|
|
143
151
|
where: string,
|
|
144
152
|
): Promise<Converted> => {
|
|
153
|
+
const single = editor === SINGLE_BLOCK_EDITOR_ALIAS
|
|
154
|
+
if (isRecord(raw) && 'layout' in raw) return { ok: true, value: raw }
|
|
155
|
+
if (single && isRecord(raw)) raw = [raw]
|
|
156
|
+
if (single && (raw === null || raw === undefined)) raw = []
|
|
145
157
|
if (!Array.isArray(raw)) {
|
|
146
|
-
|
|
147
|
-
|
|
158
|
+
return fail(
|
|
159
|
+
single
|
|
160
|
+
? 'a Single Block is one { type = "<element alias>", values = { … } }'
|
|
161
|
+
: 'blocks are a list of { type = "<element alias>", values = { … } }',
|
|
162
|
+
)
|
|
148
163
|
}
|
|
149
|
-
|
|
164
|
+
if (single && raw.length > 1) return fail('a Single Block holds one block')
|
|
150
165
|
const contentData: unknown[] = []
|
|
151
166
|
const settingsData: unknown[] = []
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
167
|
+
const entries = async (
|
|
168
|
+
list: unknown[],
|
|
169
|
+
path: string,
|
|
170
|
+
label: string,
|
|
171
|
+
): Promise<Record<string, unknown>[] | string> => {
|
|
172
|
+
const layout: Record<string, unknown>[] = []
|
|
173
|
+
const aliases = new Set<string>()
|
|
174
|
+
for (const [index, entry] of list.entries()) {
|
|
175
|
+
const name = `${label}${index + 1}`
|
|
176
|
+
if (!isRecord(entry)) return `block ${name} has no type`
|
|
177
|
+
const content = await element(entry, owner, `${path}/${index}`, `block ${name}`)
|
|
178
|
+
if (!content.ok) return content.message
|
|
179
|
+
contentData.push(content.data)
|
|
180
|
+
const item: Record<string, unknown> = { contentKey: content.data.key }
|
|
181
|
+
if (entry.alias !== undefined) {
|
|
182
|
+
if (typeof entry.alias !== 'string' || !BLOCK_ALIAS.test(entry.alias))
|
|
183
|
+
return `block ${name}: an alias is letters, digits, - and _, starting with a letter`
|
|
184
|
+
if (aliases.has(entry.alias.toLowerCase()))
|
|
185
|
+
return `two blocks are called "${entry.alias}"`
|
|
186
|
+
aliases.add(entry.alias.toLowerCase())
|
|
187
|
+
item.alias = entry.alias
|
|
188
|
+
}
|
|
189
|
+
if (isRecord(entry.settings)) {
|
|
190
|
+
const settings = await element(
|
|
191
|
+
entry.settings,
|
|
192
|
+
owner,
|
|
193
|
+
`${path}/${index}/settings`,
|
|
194
|
+
`block ${name} settings`,
|
|
163
195
|
)
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
196
|
+
if (!settings.ok) return settings.message
|
|
197
|
+
settingsData.push(settings.data)
|
|
198
|
+
item.settingsKey = settings.data.key
|
|
199
|
+
}
|
|
200
|
+
if (editor === 'Umbraco.BlockGrid') {
|
|
201
|
+
item.columnSpan = typeof entry.columns === 'number' ? entry.columns : 12
|
|
202
|
+
item.rowSpan = typeof entry.rows === 'number' ? entry.rows : 1
|
|
203
|
+
const areas: unknown[] = []
|
|
204
|
+
for (const [a, area] of (Array.isArray(entry.areas) ? entry.areas : []).entries()) {
|
|
205
|
+
// An area already in the stored shape, as older files have it, passes.
|
|
206
|
+
if (!isRecord(area) || !Array.isArray(area.blocks)) {
|
|
207
|
+
areas.push(area)
|
|
208
|
+
continue
|
|
209
|
+
}
|
|
210
|
+
const items = await entries(
|
|
211
|
+
area.blocks,
|
|
212
|
+
`${path}/${index}/areas/${a}`,
|
|
213
|
+
`${name}.${String(area.key ?? a + 1)}.`,
|
|
214
|
+
)
|
|
215
|
+
if (typeof items === 'string') return items
|
|
216
|
+
areas.push({ key: area.key, items })
|
|
217
|
+
}
|
|
218
|
+
item.areas = areas
|
|
219
|
+
}
|
|
220
|
+
layout.push(item)
|
|
184
221
|
}
|
|
185
|
-
layout
|
|
186
|
-
}
|
|
187
|
-
return {
|
|
188
|
-
ok: true,
|
|
189
|
-
value: { layout: { [BLOCK_LAYOUT[editor]]: layout }, contentData, settingsData },
|
|
222
|
+
return layout
|
|
190
223
|
}
|
|
224
|
+
const layout = await entries(raw, where, '')
|
|
225
|
+
if (typeof layout === 'string') return fail(layout)
|
|
226
|
+
return { ok: true, value: { layout: { [editor]: layout }, contentData, settingsData } }
|
|
191
227
|
}
|
|
192
228
|
|
|
193
229
|
const elementValues = async (
|
|
@@ -352,6 +388,7 @@ export function valueWriter(lookup: SchemaLookup, refs: ValueRefs) {
|
|
|
352
388
|
}
|
|
353
389
|
case 'Umbraco.BlockList':
|
|
354
390
|
case 'Umbraco.BlockGrid':
|
|
391
|
+
case SINGLE_BLOCK_EDITOR_ALIAS:
|
|
355
392
|
return blocks(editor, raw, owner, where)
|
|
356
393
|
default:
|
|
357
394
|
return { ok: true, value: raw }
|
|
@@ -428,6 +465,7 @@ export function shorthandReader(
|
|
|
428
465
|
}
|
|
429
466
|
case 'Umbraco.BlockList':
|
|
430
467
|
case 'Umbraco.BlockGrid':
|
|
468
|
+
case SINGLE_BLOCK_EDITOR_ALIAS:
|
|
431
469
|
return blocks(editor, value)
|
|
432
470
|
default:
|
|
433
471
|
return value
|
|
@@ -453,49 +491,52 @@ export function shorthandReader(
|
|
|
453
491
|
return link
|
|
454
492
|
}
|
|
455
493
|
|
|
456
|
-
/**
|
|
494
|
+
/**
|
|
495
|
+
* Blocks as `{ type, alias, key, values, settings }`, read through `readBlocks`
|
|
496
|
+
* (story 345): a grid block's areas as `[{ key, blocks }]`, and a Single Block as
|
|
497
|
+
* its one block, or nothing. A value whose blocks cannot all be said that way
|
|
498
|
+
* stays as it is stored.
|
|
499
|
+
*/
|
|
457
500
|
const blocks = async (editor: string, value: unknown): Promise<unknown> => {
|
|
458
|
-
if (!
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
.map((d) => [String(d.key), d]),
|
|
469
|
-
)
|
|
470
|
-
const out: unknown[] = []
|
|
471
|
-
for (const item of layout) {
|
|
472
|
-
if (!isRecord(item)) return value
|
|
473
|
-
const data = content.get(String(item.contentKey))
|
|
474
|
-
if (!data || typeof data.contentTypeKey !== 'string') return value
|
|
475
|
-
if (editor === 'Umbraco.BlockGrid' && Array.isArray(item.areas) && item.areas.length > 0)
|
|
476
|
-
return value
|
|
477
|
-
const entry: Record<string, unknown> = {
|
|
478
|
-
type: await aliasOf(data.contentTypeKey),
|
|
479
|
-
...(typeof item.alias === 'string' ? { alias: item.alias } : {}),
|
|
480
|
-
key: item.contentKey,
|
|
481
|
-
values: await elementValues(data),
|
|
482
|
-
}
|
|
483
|
-
if (typeof item.settingsKey === 'string') {
|
|
484
|
-
const setting = settings.get(item.settingsKey)
|
|
485
|
-
if (!setting || typeof setting.contentTypeKey !== 'string') return value
|
|
486
|
-
entry.settings = {
|
|
487
|
-
type: await aliasOf(setting.contentTypeKey),
|
|
488
|
-
key: item.settingsKey,
|
|
489
|
-
values: await elementValues(setting),
|
|
501
|
+
if (!isBlockValue(value)) return value
|
|
502
|
+
const say = async (list: Block[]): Promise<unknown[] | undefined> => {
|
|
503
|
+
const out: unknown[] = []
|
|
504
|
+
for (const { layout, content, settings, areas } of list) {
|
|
505
|
+
if (!content || typeof content.contentTypeKey !== 'string') return undefined
|
|
506
|
+
const entry: Record<string, unknown> = {
|
|
507
|
+
type: await aliasOf(content.contentTypeKey),
|
|
508
|
+
...(typeof layout.alias === 'string' ? { alias: layout.alias } : {}),
|
|
509
|
+
key: layout.contentKey,
|
|
510
|
+
values: await elementValues(content as unknown as Record<string, unknown>),
|
|
490
511
|
}
|
|
512
|
+
if (typeof layout.settingsKey === 'string') {
|
|
513
|
+
if (!settings || typeof settings.contentTypeKey !== 'string') return undefined
|
|
514
|
+
entry.settings = {
|
|
515
|
+
type: await aliasOf(settings.contentTypeKey),
|
|
516
|
+
key: layout.settingsKey,
|
|
517
|
+
values: await elementValues(settings as unknown as Record<string, unknown>),
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
if (editor === 'Umbraco.BlockGrid') {
|
|
521
|
+
entry.columns = layout.columnSpan
|
|
522
|
+
entry.rows = layout.rowSpan
|
|
523
|
+
if (areas.length > 0) {
|
|
524
|
+
const said: unknown[] = []
|
|
525
|
+
for (const area of areas) {
|
|
526
|
+
const inner = await say(area.blocks)
|
|
527
|
+
if (!inner) return undefined
|
|
528
|
+
said.push({ key: area.key, blocks: inner })
|
|
529
|
+
}
|
|
530
|
+
entry.areas = said
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
out.push(entry)
|
|
491
534
|
}
|
|
492
|
-
|
|
493
|
-
entry.columns = item.columnSpan
|
|
494
|
-
entry.rows = item.rowSpan
|
|
495
|
-
}
|
|
496
|
-
out.push(entry)
|
|
535
|
+
return out
|
|
497
536
|
}
|
|
498
|
-
|
|
537
|
+
const said = await say(readBlocks(value, editor))
|
|
538
|
+
if (!said) return value
|
|
539
|
+
return editor === SINGLE_BLOCK_EDITOR_ALIAS ? (said[0] ?? null) : said
|
|
499
540
|
}
|
|
500
541
|
|
|
501
542
|
const elementValues = async (data: Record<string, unknown>) => {
|
package/src/server.ts
CHANGED
|
@@ -80,6 +80,7 @@ import {
|
|
|
80
80
|
managementApiPrefix,
|
|
81
81
|
ObjectTypes,
|
|
82
82
|
PREVIEW_HUB_PATH,
|
|
83
|
+
RemotePermissions,
|
|
83
84
|
SERVER_EVENT_HUB_PATH,
|
|
84
85
|
} from '@crombolo/core'
|
|
85
86
|
import {
|
|
@@ -194,8 +195,9 @@ import { createDeliveryMemberSecurity } from './delivery-members.ts'
|
|
|
194
195
|
import { handleDictionaryWords } from './dictionary-words-api.ts'
|
|
195
196
|
import { syncDomainsFile } from './domains.ts'
|
|
196
197
|
import { editorTypeLibs, siteJsxImportSource } from './editor-types.ts'
|
|
197
|
-
import { emailAvailability } from './email.ts'
|
|
198
|
+
import { emailAvailability, emailReady } from './email.ts'
|
|
198
199
|
import { noticeAboutEmail } from './email-notice.ts'
|
|
200
|
+
import { createEmailSettings, type EmailSettingsInput } from './email-settings.ts'
|
|
199
201
|
import { activityCsv, readActivityQuery } from './extension-activity.ts'
|
|
200
202
|
import { createBackOfficeBuilds } from './extension-backoffice.ts'
|
|
201
203
|
import { warnAboutAppPlugins } from './extensions-notice.ts'
|
|
@@ -238,10 +240,12 @@ import {
|
|
|
238
240
|
signPreviewToken,
|
|
239
241
|
} from './preview-tokens.ts'
|
|
240
242
|
import { provenanceProblem } from './provenance.ts'
|
|
241
|
-
import { createRemote, type RestartOutcome } from './remote.ts'
|
|
243
|
+
import { createRemote, may, type RestartOutcome } from './remote.ts'
|
|
244
|
+
import { createSchemaTransfer, UPLOAD_LIMITS } from './schema-transfer.ts'
|
|
242
245
|
import { SiteAssets } from './site-assets.ts'
|
|
243
246
|
import { unknownHostProvided } from './site-file.ts'
|
|
244
247
|
import { PublicFiles } from './site-public.ts'
|
|
248
|
+
import { signerTrusted } from './site-trust.ts'
|
|
245
249
|
import {
|
|
246
250
|
activeSpan,
|
|
247
251
|
inSpan,
|
|
@@ -497,6 +501,7 @@ export async function createServer(
|
|
|
497
501
|
keyword: config.packageKeyword,
|
|
498
502
|
marketplaceUrl: config.marketplaceUrl,
|
|
499
503
|
componentsDir: config.componentsDir,
|
|
504
|
+
trustSigner: (provenance) => signerTrusted(db, config, provenance),
|
|
500
505
|
extensions: { ...extensions, invalidate: () => void bundleReloader.reload() },
|
|
501
506
|
siteDir: config.siteDir,
|
|
502
507
|
wired: () => bundles?.mounted.map((bundle) => bundle.id) ?? [],
|
|
@@ -1300,7 +1305,16 @@ export async function createServer(
|
|
|
1300
1305
|
// Whether an invitation or a reset link can reach anyone at all, which is what
|
|
1301
1306
|
// gates the options rather than `emailStatus.available`: development delivers
|
|
1302
1307
|
// to the console, and that is a working flow for the person using it.
|
|
1303
|
-
|
|
1308
|
+
// Asked each time, as e-mail set up in Settings changes without a restart (story 340).
|
|
1309
|
+
const canSendUserLinks = () => Boolean(resolveUserLinkSender(config, email))
|
|
1310
|
+
const emailSettings = createEmailSettings(db, config, { port: () => email })
|
|
1311
|
+
const schemaTransfer = createSchemaTransfer(db, config, {
|
|
1312
|
+
boot: schema,
|
|
1313
|
+
afterApply: async (report) => {
|
|
1314
|
+
cache.invalidate()
|
|
1315
|
+
await afterSync(report)
|
|
1316
|
+
},
|
|
1317
|
+
})
|
|
1304
1318
|
const images = new ImageProcessor(mediaStore)
|
|
1305
1319
|
// Asked at boot, so the first AVIF request does not wait on it.
|
|
1306
1320
|
void canEncodeAvif()
|
|
@@ -1513,6 +1527,7 @@ export async function createServer(
|
|
|
1513
1527
|
const MEDIA_JOB_QUEUED_EVENT = { eventSource: 'Crombolo:MediaJob', eventType: 'Queued' } as const
|
|
1514
1528
|
const hostTokenPath = `${paths.pluginPath}/api/host-token`
|
|
1515
1529
|
const contentQueryPath = `${paths.pluginPath}/api/content-query`
|
|
1530
|
+
const selfAudited = [`${paths.pluginPath}/api/email/`, `${paths.pluginPath}/api/schema-transfer/`]
|
|
1516
1531
|
const bundleInstallPaths = new Set(
|
|
1517
1532
|
['install', 'uninstall', 'disable', 'enable', 'grant', 'settings'].flatMap((action) => [
|
|
1518
1533
|
`${paths.pluginPath}/api/extensions/${action}`,
|
|
@@ -1930,8 +1945,10 @@ export async function createServer(
|
|
|
1930
1945
|
if (pathname === hostTokenPath) return
|
|
1931
1946
|
// A content query is a POST that reads.
|
|
1932
1947
|
if (pathname === contentQueryPath) return
|
|
1933
|
-
// Installs and removals write their own entry, with the package (story 194)
|
|
1948
|
+
// Installs and removals write their own entry, with the package (story 194),
|
|
1949
|
+
// as do e-mail settings (story 340) and schema imports (story 342).
|
|
1934
1950
|
if (bundleInstallPaths.has(pathname) || pathname.startsWith(`${jobsPath}/`)) return
|
|
1951
|
+
if (selfAudited.some((path) => pathname.startsWith(path))) return
|
|
1935
1952
|
const principal = await authenticate(request)
|
|
1936
1953
|
if (!principal) return
|
|
1937
1954
|
const plan = pluginAuditPlan(request.method, pathname.slice(prefix.length))
|
|
@@ -2464,16 +2481,100 @@ export async function createServer(
|
|
|
2464
2481
|
|
|
2465
2482
|
if (pathname === `${paths.pluginPath}/api/email` && request.method === 'GET') {
|
|
2466
2483
|
if (!(await authenticate(request))) return new Response('Unauthorized', { status: 401 })
|
|
2484
|
+
const status = emailAvailability(email)
|
|
2467
2485
|
return Response.json({
|
|
2468
|
-
available:
|
|
2469
|
-
provider:
|
|
2470
|
-
reason:
|
|
2471
|
-
affects:
|
|
2472
|
-
canSendUserLinks,
|
|
2473
|
-
canSendNotifications:
|
|
2486
|
+
available: status.available,
|
|
2487
|
+
provider: status.provider,
|
|
2488
|
+
reason: status.reason,
|
|
2489
|
+
affects: status.affects,
|
|
2490
|
+
canSendUserLinks: canSendUserLinks(),
|
|
2491
|
+
canSendNotifications: emailReady(email),
|
|
2474
2492
|
})
|
|
2475
2493
|
}
|
|
2476
2494
|
|
|
2495
|
+
// Story 342: Settings → Schema, administrators only. An upload waits for
|
|
2496
|
+
// approval on the Changes dashboard; nothing changes until it is applied.
|
|
2497
|
+
const schemaAction = /^\/api\/schema-transfer\/(export|import|import\/apply)$/.exec(
|
|
2498
|
+
pathname.slice(paths.pluginPath.length),
|
|
2499
|
+
)?.[1]
|
|
2500
|
+
if (pathname.startsWith(paths.pluginPath) && schemaAction) {
|
|
2501
|
+
const principal = await authenticate(request)
|
|
2502
|
+
if (!principal) return new Response('Unauthorized', { status: 401 })
|
|
2503
|
+
if (!principal.isAdmin)
|
|
2504
|
+
return Response.json(
|
|
2505
|
+
{ ok: false, message: 'Only an administrator imports or exports the schema.' },
|
|
2506
|
+
{ status: 403 },
|
|
2507
|
+
)
|
|
2508
|
+
const actor = actorOf(principal, request)
|
|
2509
|
+
if (schemaAction === 'export' && request.method === 'GET')
|
|
2510
|
+
return new Response(schemaTransfer.exportZip(), {
|
|
2511
|
+
headers: {
|
|
2512
|
+
'content-type': 'application/zip',
|
|
2513
|
+
'content-disposition': 'attachment; filename="schema.zip"',
|
|
2514
|
+
'cache-control': PRIVATE_NO_STORE,
|
|
2515
|
+
},
|
|
2516
|
+
})
|
|
2517
|
+
if (schemaAction === 'import' && request.method === 'GET')
|
|
2518
|
+
return Response.json({
|
|
2519
|
+
pending: (await schemaTransfer.pending()) ?? null,
|
|
2520
|
+
writable: config.schemaWritable,
|
|
2521
|
+
})
|
|
2522
|
+
let outcome: Awaited<ReturnType<typeof schemaTransfer.discard>> | undefined
|
|
2523
|
+
if (schemaAction === 'import' && request.method === 'POST') {
|
|
2524
|
+
const length = Number(request.headers.get('content-length') ?? 0)
|
|
2525
|
+
if (length > UPLOAD_LIMITS.maxUploadBytes)
|
|
2526
|
+
return Response.json(
|
|
2527
|
+
{ ok: false, message: 'That file is too large to be a schema.' },
|
|
2528
|
+
{ status: 413 },
|
|
2529
|
+
)
|
|
2530
|
+
const name = new URL(request.url).searchParams.get('name') ?? 'schema.zip'
|
|
2531
|
+
outcome = await schemaTransfer.upload(
|
|
2532
|
+
actor,
|
|
2533
|
+
name,
|
|
2534
|
+
new Uint8Array(await request.arrayBuffer()),
|
|
2535
|
+
)
|
|
2536
|
+
} else if (schemaAction === 'import' && request.method === 'DELETE')
|
|
2537
|
+
outcome = await schemaTransfer.discard(actor)
|
|
2538
|
+
else if (schemaAction === 'import/apply' && request.method === 'POST')
|
|
2539
|
+
outcome = await schemaTransfer.apply(actor)
|
|
2540
|
+
if (!outcome) return new Response('Method Not Allowed', { status: 405 })
|
|
2541
|
+
return outcome.ok
|
|
2542
|
+
? Response.json(outcome)
|
|
2543
|
+
: Response.json(outcome, { status: outcome.status })
|
|
2544
|
+
}
|
|
2545
|
+
|
|
2546
|
+
// Story 340: Settings → E-mail, administrators only.
|
|
2547
|
+
const emailAction = /^\/api\/email\/(settings|test)$/.exec(
|
|
2548
|
+
pathname.slice(paths.pluginPath.length),
|
|
2549
|
+
)?.[1]
|
|
2550
|
+
if (pathname.startsWith(paths.pluginPath) && emailAction) {
|
|
2551
|
+
const principal = await authenticate(request)
|
|
2552
|
+
if (!principal) return new Response('Unauthorized', { status: 401 })
|
|
2553
|
+
if (!principal.isAdmin)
|
|
2554
|
+
return Response.json(
|
|
2555
|
+
{ ok: false, message: 'Only an administrator sets up e-mail.' },
|
|
2556
|
+
{ status: 403 },
|
|
2557
|
+
)
|
|
2558
|
+
const actor = actorOf(principal, request)
|
|
2559
|
+
if (emailAction === 'settings' && request.method === 'GET')
|
|
2560
|
+
return Response.json(await emailSettings.view())
|
|
2561
|
+
const outcome =
|
|
2562
|
+
emailAction === 'settings' && request.method === 'PUT'
|
|
2563
|
+
? await emailSettings.save(
|
|
2564
|
+
actor,
|
|
2565
|
+
((await request.json().catch(() => ({}))) ?? {}) as EmailSettingsInput,
|
|
2566
|
+
)
|
|
2567
|
+
: emailAction === 'settings' && request.method === 'DELETE'
|
|
2568
|
+
? await emailSettings.clear(actor)
|
|
2569
|
+
: emailAction === 'test' && request.method === 'POST'
|
|
2570
|
+
? await emailSettings.test(actor)
|
|
2571
|
+
: undefined
|
|
2572
|
+
if (!outcome) return new Response('Method Not Allowed', { status: 405 })
|
|
2573
|
+
return outcome.ok
|
|
2574
|
+
? Response.json(outcome)
|
|
2575
|
+
: Response.json({ ok: false, message: outcome.message }, { status: outcome.status })
|
|
2576
|
+
}
|
|
2577
|
+
|
|
2477
2578
|
/**
|
|
2478
2579
|
* Non-contract: forms and their entries. There is no form operation in the
|
|
2479
2580
|
* vendored contract — Umbraco Forms ships its own API and its own client,
|
|
@@ -3092,6 +3193,7 @@ export async function createServer(
|
|
|
3092
3193
|
db,
|
|
3093
3194
|
config,
|
|
3094
3195
|
user: principal.email,
|
|
3196
|
+
mayInstallCode: may(principal, RemotePermissions.InstallCode),
|
|
3095
3197
|
onApplied: () => {
|
|
3096
3198
|
cache.invalidate()
|
|
3097
3199
|
mediaCache.clear()
|
|
@@ -3145,7 +3247,10 @@ export async function createServer(
|
|
|
3145
3247
|
bundles,
|
|
3146
3248
|
upgrades,
|
|
3147
3249
|
transfers: await pendingTransfers(db),
|
|
3250
|
+
// Story 342: an uploaded schema waiting for an administrator.
|
|
3251
|
+
schemaImport: principal.isAdmin ? ((await schemaTransfer.pending()) ?? null) : null,
|
|
3148
3252
|
mayImport,
|
|
3253
|
+
mayApplySchema: principal.isAdmin,
|
|
3149
3254
|
})
|
|
3150
3255
|
}
|
|
3151
3256
|
|
|
@@ -3246,7 +3351,7 @@ export async function createServer(
|
|
|
3246
3351
|
allowUserInvite: false,
|
|
3247
3352
|
// Offering "forgot password" with no way to send the link is a dead
|
|
3248
3353
|
// end that looks like a bug; without a sender the option is not there.
|
|
3249
|
-
allowPasswordReset: config.allowPasswordReset && canSendUserLinks,
|
|
3354
|
+
allowPasswordReset: config.allowPasswordReset && canSendUserLinks(),
|
|
3250
3355
|
disableLocalLogin: !config.allowLocalLogin,
|
|
3251
3356
|
// Set by the authorize endpoint so sign-in resumes the OAuth flow. Only
|
|
3252
3357
|
// a path on this site: the login page hands this to the browser once
|
package/src/settings.ts
CHANGED
|
@@ -442,6 +442,15 @@ const DECLARED = [
|
|
|
442
442
|
section: 'Schema',
|
|
443
443
|
description: 'Whether the back office may change the schema files.',
|
|
444
444
|
},
|
|
445
|
+
{
|
|
446
|
+
env: 'CROMBOLO_CONTENT_MODE',
|
|
447
|
+
kind: 'enum',
|
|
448
|
+
values: ['development', 'production'],
|
|
449
|
+
default: 'development',
|
|
450
|
+
section: 'Schema',
|
|
451
|
+
description:
|
|
452
|
+
'In production, the back office cannot change templates, stylesheets and scripts, for a site whose files come from its repository.',
|
|
453
|
+
},
|
|
445
454
|
{
|
|
446
455
|
env: 'CROMBOLO_SYNC_SCHEMA_AT_BOOT',
|
|
447
456
|
kind: 'boolean',
|
package/src/site-public.ts
CHANGED
|
@@ -299,7 +299,8 @@ export class PublicFiles {
|
|
|
299
299
|
/** The servable files of a folder, which may not exist. */
|
|
300
300
|
function filesFrom(root: string): string[] {
|
|
301
301
|
try {
|
|
302
|
-
|
|
302
|
+
// Sorted: the folder's own order differs between file systems.
|
|
303
|
+
return existsSync(root) ? filesIn(root).filter(isServable).sort() : []
|
|
303
304
|
} catch {
|
|
304
305
|
return []
|
|
305
306
|
}
|
package/src/site-trust.ts
CHANGED
|
@@ -119,6 +119,22 @@ export async function trustedSigners(db: Db, config: CromboloConfig): Promise<Tr
|
|
|
119
119
|
return entries
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
/** Whether a signature's key, or the repository that built it, is on this site's list (story 335). */
|
|
123
|
+
export async function signerTrusted(
|
|
124
|
+
db: Db,
|
|
125
|
+
config: CromboloConfig,
|
|
126
|
+
result: ProvenanceResult,
|
|
127
|
+
): Promise<boolean> {
|
|
128
|
+
if (result.state !== 'signed') return false
|
|
129
|
+
const entries = await trustedSigners(db, config)
|
|
130
|
+
if (result.key) return entries.some((entry) => entry.fingerprint === result.key?.fingerprint)
|
|
131
|
+
const source = result.source
|
|
132
|
+
if (!source) return false
|
|
133
|
+
return entries.some(
|
|
134
|
+
(entry) => entry.kind === 'source' && entry.source && sourceAllowed(source, entry.source),
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
|
|
122
138
|
/** What a site bundle's check decided: refused, or applied, flagged or not, and who signed it. */
|
|
123
139
|
export interface SiteBundleTrust {
|
|
124
140
|
problem?: string
|
package/src/status.ts
CHANGED
|
@@ -31,6 +31,7 @@ import { loadSchemaDirectory } from '@crombolo/schema'
|
|
|
31
31
|
import { type CromboloConfig, describeDatabase, VERSION } from './config.ts'
|
|
32
32
|
import { BundleConfigurationError, pendingTablesSteps, tablesChainsFor } from './custom-tables.ts'
|
|
33
33
|
import { type EmailAvailability, emailAvailability, resolveEmailPort } from './email.ts'
|
|
34
|
+
import { siteEmail } from './email-settings.ts'
|
|
34
35
|
import { formTypesFor } from './form-types.ts'
|
|
35
36
|
import { assertViewRuntime } from './view-runtime.ts'
|
|
36
37
|
|
|
@@ -197,6 +198,8 @@ export async function siteStatus(config: CromboloConfig): Promise<SiteStatus> {
|
|
|
197
198
|
status.problems.push('the database is not installed yet; `crombolo start` will install it')
|
|
198
199
|
return status
|
|
199
200
|
}
|
|
201
|
+
// Story 340: e-mail may be set up in Settings, which only the database knows.
|
|
202
|
+
status.email = emailAvailability(await siteEmail(db, config).catch(() => undefined))
|
|
200
203
|
if (status.framework.pending.length > 0 && !config.development)
|
|
201
204
|
status.problems.push(
|
|
202
205
|
`${status.framework.pending.length} framework migration(s) pending: run \`crombolo upgrade\``,
|
package/src/telemetry.ts
CHANGED
|
@@ -468,9 +468,16 @@ export function tracedDb(db: Db): Db {
|
|
|
468
468
|
/** The site's e-mail with each message a span: its provider and outcome, never its addresses. */
|
|
469
469
|
export function tracedEmail<T extends EmailPort | undefined>(email: T): T {
|
|
470
470
|
if (!email) return email
|
|
471
|
+
// Getters, and `refresh` passed through: e-mail set up in Settings changes under it (story 340).
|
|
472
|
+
const refresh = (email as { refresh?: () => Promise<void> }).refresh
|
|
471
473
|
return {
|
|
472
|
-
description
|
|
473
|
-
|
|
474
|
+
get description() {
|
|
475
|
+
return email.description
|
|
476
|
+
},
|
|
477
|
+
get provider() {
|
|
478
|
+
return email.provider
|
|
479
|
+
},
|
|
480
|
+
...(refresh ? { refresh: () => refresh.call(email) } : {}),
|
|
474
481
|
send: (message) =>
|
|
475
482
|
inSpan(
|
|
476
483
|
'email send',
|
|
@@ -84,6 +84,8 @@ export interface TransferActionContext {
|
|
|
84
84
|
config: CromboloConfig
|
|
85
85
|
/** Who is acting, recorded with each answer. */
|
|
86
86
|
user: string
|
|
87
|
+
/** They were given "Install code on this site", so a bundle's templates may come in (story 336). */
|
|
88
|
+
mayInstallCode?: boolean
|
|
87
89
|
/** After an import lands: the published cache was built before it. */
|
|
88
90
|
onApplied(): void
|
|
89
91
|
}
|
|
@@ -185,6 +187,7 @@ export async function handleTransferAction(
|
|
|
185
187
|
label: pending.label ?? undefined,
|
|
186
188
|
by: ctx.user,
|
|
187
189
|
passphrase,
|
|
190
|
+
installTemplates: ctx.mayInstallCode === true,
|
|
188
191
|
})
|
|
189
192
|
if (result.runId) ctx.onApplied()
|
|
190
193
|
const names = new Map(result.check.plan.map((entry) => [entry.key, entry.name] as const))
|