@crombolo/server 0.61.0 → 0.63.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 +13 -1
- package/src/adapters/file-system.ts +27 -3
- package/src/adapters/template-files.ts +10 -0
- package/src/adapters/users.ts +55 -84
- package/src/bundle-admin.ts +21 -1
- package/src/bundle-api.ts +1 -3
- package/src/bundle-code.ts +93 -5
- package/src/bundle-install.ts +28 -5
- package/src/bundle-sections.ts +10 -0
- package/src/config.ts +46 -7
- package/src/content-query.ts +2 -4
- package/src/core.ts +83 -25
- package/src/extension-install.ts +631 -0
- package/src/extension-process.ts +30 -7
- package/src/external-sign-in.ts +10 -0
- package/src/form-workflows.ts +110 -12
- package/src/grant-policy.ts +23 -3
- package/src/grant-trust.ts +73 -0
- package/src/identity-provider-overrides.ts +186 -36
- package/src/identity-providers.ts +23 -0
- package/src/index.ts +7 -0
- package/src/marketplace.ts +54 -338
- package/src/member-auth.ts +5 -1
- package/src/outbound-address.ts +1 -1
- package/src/ports.ts +24 -7
- package/src/provenance.ts +13 -1
- package/src/remote.ts +23 -8
- package/src/server.ts +87 -3
- package/src/settings.ts +22 -0
- package/src/site-trust.ts +16 -0
- package/src/transfer-dashboard.ts +3 -0
package/src/bundle-code.ts
CHANGED
|
@@ -18,13 +18,22 @@ import { tmpdir } from 'node:os'
|
|
|
18
18
|
import { dirname, join, relative } from 'node:path'
|
|
19
19
|
import {
|
|
20
20
|
discoverBundles,
|
|
21
|
+
INSTALLED_AS_DEPENDENCY,
|
|
21
22
|
isSemverRange,
|
|
22
23
|
type PackageJson,
|
|
24
|
+
packageInRoot,
|
|
23
25
|
peerRangeProblem,
|
|
26
|
+
RECORD_FILE,
|
|
27
|
+
type RecordedExtension,
|
|
28
|
+
ROOTS_DIR,
|
|
29
|
+
readPackageJson,
|
|
30
|
+
readRecord,
|
|
31
|
+
recordProblems,
|
|
24
32
|
resolvePackageDir,
|
|
25
33
|
} from '@crombolo/backoffice-host/registry'
|
|
26
34
|
import { loadBundleCode } from '@crombolo/transfer'
|
|
27
35
|
import { VERSION } from './config.ts'
|
|
36
|
+
import { lockedIntegrity } from './extension-install.ts'
|
|
28
37
|
|
|
29
38
|
const SCOPE = '@crombolo/'
|
|
30
39
|
const CORE_PACKAGE = '@crombolo/crombolo'
|
|
@@ -43,10 +52,19 @@ export interface BundleCodeCheck {
|
|
|
43
52
|
files: number
|
|
44
53
|
}
|
|
45
54
|
|
|
55
|
+
/** An extension's root the code carries, and whether it installed as its record says (story 332). */
|
|
56
|
+
export interface BundleCodeRoot {
|
|
57
|
+
id: string
|
|
58
|
+
ok: boolean
|
|
59
|
+
problem?: string
|
|
60
|
+
}
|
|
61
|
+
|
|
46
62
|
export interface BundleCodeInstall {
|
|
47
63
|
problems: string[]
|
|
48
64
|
dir: string
|
|
49
65
|
files: number
|
|
66
|
+
/** Each extension root the code carries, installed from its own lockfile. */
|
|
67
|
+
roots: BundleCodeRoot[]
|
|
50
68
|
}
|
|
51
69
|
|
|
52
70
|
/** `bun install` exactly as the lockfile says: no lifecycle scripts, and no peers. */
|
|
@@ -123,10 +141,70 @@ function linkCms(json: PackageJson, dir: string): string[] {
|
|
|
123
141
|
return problems
|
|
124
142
|
}
|
|
125
143
|
|
|
144
|
+
/** The extension roots under a directory: each folder in `extensions/`. */
|
|
145
|
+
function rootIds(dir: string): string[] {
|
|
146
|
+
const roots = join(dir, ROOTS_DIR)
|
|
147
|
+
if (!existsSync(roots)) return []
|
|
148
|
+
return readdirSync(roots, { withFileTypes: true })
|
|
149
|
+
.filter((entry) => entry.isDirectory())
|
|
150
|
+
.map((entry) => entry.name)
|
|
151
|
+
.sort()
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Why what a root installed is not what the record names, or undefined when it is. */
|
|
155
|
+
function rootMismatch(
|
|
156
|
+
dir: string,
|
|
157
|
+
id: string,
|
|
158
|
+
line: RecordedExtension | undefined,
|
|
159
|
+
): string | undefined {
|
|
160
|
+
if (!line) return undefined
|
|
161
|
+
const installed = readPackageJson(join(packageInRoot(dir, id, line.name), 'package.json'))
|
|
162
|
+
if (!installed) return `its bun.lock does not install ${line.name}, which ${RECORD_FILE} names`
|
|
163
|
+
if (installed.version !== line.version)
|
|
164
|
+
return `it installs ${line.name}@${installed.version}, where ${RECORD_FILE} names ${line.version}`
|
|
165
|
+
const locked = lockedIntegrity(join(dir, ROOTS_DIR, id), line.name)
|
|
166
|
+
if (line.integrity && locked && locked !== line.integrity)
|
|
167
|
+
return `its bun.lock holds ${line.name} as ${locked}, where ${RECORD_FILE} records ${line.integrity}`
|
|
168
|
+
return undefined
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Each extension root installed from its own lockfile, as `site apply` installs
|
|
173
|
+
* one (story 326), then held to its line in the record. One that fails leaves
|
|
174
|
+
* the others to install.
|
|
175
|
+
*/
|
|
176
|
+
async function installRoots(dir: string): Promise<BundleCodeRoot[]> {
|
|
177
|
+
const record = readRecord(dir)
|
|
178
|
+
const out: BundleCodeRoot[] = []
|
|
179
|
+
for (const id of rootIds(dir)) {
|
|
180
|
+
const root = join(dir, ROOTS_DIR, id)
|
|
181
|
+
const problem = existsSync(join(root, 'bun.lock'))
|
|
182
|
+
? ((await frozenInstall(root)) ?? rootMismatch(dir, id, record[id]))
|
|
183
|
+
: 'it has no bun.lock, so it could not be installed as it was tested'
|
|
184
|
+
out.push(problem ? { id, ok: false, problem } : { id, ok: true })
|
|
185
|
+
}
|
|
186
|
+
return out
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const rootProblems = (roots: readonly BundleCodeRoot[]): string[] =>
|
|
190
|
+
roots.flatMap((root) => (root.problem ? [`${ROOTS_DIR}/${root.id}/: ${root.problem}`] : []))
|
|
191
|
+
|
|
192
|
+
/** Whether the site's config imports a package: the boot runs one it wires, the old way. */
|
|
193
|
+
function configImports(dir: string, name: string): boolean {
|
|
194
|
+
const config = ['crombolo.config.ts', 'crombolo.config.js', 'crombolo.config.mjs']
|
|
195
|
+
.map((file) => join(dir, file))
|
|
196
|
+
.find((file) => existsSync(file))
|
|
197
|
+
if (!config) return false
|
|
198
|
+
const escaped = name.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&')
|
|
199
|
+
return new RegExp(`(?:from|import)\\s*\\(?\\s*['"]${escaped}(?:/[^'"]*)?['"]`).test(
|
|
200
|
+
readFileSync(config, 'utf8'),
|
|
201
|
+
)
|
|
202
|
+
}
|
|
203
|
+
|
|
126
204
|
/**
|
|
127
205
|
* Every reason a bundle's code cannot run on this CMS: its hash, a frozen
|
|
128
|
-
* install, `@crombolo/*` installed beside it,
|
|
129
|
-
*
|
|
206
|
+
* install, `@crombolo/*` installed beside it, the bundle packages it declares,
|
|
207
|
+
* and the extension roots it carries against its record. All of them, not the first. The site's code is never run here: a
|
|
130
208
|
* host has not yet accepted it, so its config's wiring is checked by the boot.
|
|
131
209
|
*/
|
|
132
210
|
export async function checkBundleCode(
|
|
@@ -157,6 +235,8 @@ export async function checkBundleCode(
|
|
|
157
235
|
`${copy} is installed with the code; the CMS provides @crombolo packages, so nothing the site installs may depend on one directly`,
|
|
158
236
|
)
|
|
159
237
|
result.problems.push(...linkCms(json, work))
|
|
238
|
+
result.problems.push(...rootProblems(await installRoots(work)))
|
|
239
|
+
result.problems.push(...recordProblems(work))
|
|
160
240
|
|
|
161
241
|
const discovered = discoverBundles(work)
|
|
162
242
|
for (const entry of discovered.problems)
|
|
@@ -164,6 +244,9 @@ export async function checkBundleCode(
|
|
|
164
244
|
for (const bundle of discovered.bundles) {
|
|
165
245
|
const peer = peerRangeProblem(bundle, coreVersion)
|
|
166
246
|
if (peer) result.problems.push(peer)
|
|
247
|
+
// Story 332: the boot names an extension the site depends on, and does not run it.
|
|
248
|
+
if (bundle.dependency && !(bundle.carries.server && configImports(work, bundle.packageName)))
|
|
249
|
+
result.problems.push(`${bundle.packageName} (${bundle.id}): ${INSTALLED_AS_DEPENDENCY}`)
|
|
167
250
|
}
|
|
168
251
|
result.serverBundles = discovered.bundles
|
|
169
252
|
.filter((bundle) => bundle.carries.server)
|
|
@@ -176,7 +259,7 @@ export async function checkBundleCode(
|
|
|
176
259
|
|
|
177
260
|
/**
|
|
178
261
|
* The bundle's code installed into `dir`, ready for a host to start once it
|
|
179
|
-
* provides the `@crombolo/*` packages. Refuses a directory that already holds
|
|
262
|
+
* provides the `@crombolo/*` packages, with each extension root it carries. Refuses a directory that already holds
|
|
180
263
|
* files, rather than mixing two sites' code.
|
|
181
264
|
*/
|
|
182
265
|
export async function installBundleCode(
|
|
@@ -184,12 +267,14 @@ export async function installBundleCode(
|
|
|
184
267
|
dir: string,
|
|
185
268
|
): Promise<BundleCodeInstall> {
|
|
186
269
|
const loaded = loadBundleCode(packageDir)
|
|
187
|
-
if (!loaded.dir || loaded.problems.length > 0)
|
|
270
|
+
if (!loaded.dir || loaded.problems.length > 0)
|
|
271
|
+
return { problems: loaded.problems, dir, files: 0, roots: [] }
|
|
188
272
|
if (existsSync(dir) && readdirSync(dir).length > 0)
|
|
189
273
|
return {
|
|
190
274
|
problems: [`${dir} already holds files; install into an empty directory`],
|
|
191
275
|
dir,
|
|
192
276
|
files: 0,
|
|
277
|
+
roots: [],
|
|
193
278
|
}
|
|
194
279
|
mkdirSync(dir, { recursive: true })
|
|
195
280
|
cpSync(loaded.dir, dir, { recursive: true })
|
|
@@ -201,5 +286,8 @@ export async function installBundleCode(
|
|
|
201
286
|
problems.push(
|
|
202
287
|
`${copy} was installed with the code; the CMS provides @crombolo packages, so nothing the site installs may depend on one directly`,
|
|
203
288
|
)
|
|
204
|
-
|
|
289
|
+
// Story 332: each extension root the code carries, as `site apply` installs it.
|
|
290
|
+
const roots = await installRoots(dir)
|
|
291
|
+
problems.push(...rootProblems(roots))
|
|
292
|
+
return { problems, dir, files: loaded.paths.length, roots }
|
|
205
293
|
}
|
package/src/bundle-install.ts
CHANGED
|
@@ -74,6 +74,7 @@ import {
|
|
|
74
74
|
carriedSections,
|
|
75
75
|
carriesSections,
|
|
76
76
|
changedFileSections,
|
|
77
|
+
componentChanges,
|
|
77
78
|
type FileAction,
|
|
78
79
|
keepDictionary,
|
|
79
80
|
keptDictionary,
|
|
@@ -324,10 +325,19 @@ export interface TransferInput extends SectionOptions {
|
|
|
324
325
|
* asked, as story 192 had it. Only where runtime installs are on.
|
|
325
326
|
*/
|
|
326
327
|
installCode?: boolean
|
|
328
|
+
/**
|
|
329
|
+
* Install the templates it adds or changes, which are code the server runs
|
|
330
|
+
* (story 336); `installCode` unless said. The Transfer dashboard asks for these
|
|
331
|
+
* alone, for a user given "Install code on this site".
|
|
332
|
+
*/
|
|
333
|
+
installTemplates?: boolean
|
|
327
334
|
/** Apply a site bundle older than one this site applied from the same signer (story 316). */
|
|
328
335
|
allowDowngrade?: boolean
|
|
329
336
|
}
|
|
330
337
|
|
|
338
|
+
/** Why a bundle's code, migrations or templates are refused where installs are off (story 336). */
|
|
339
|
+
export const RUNTIME_INSTALLS_OFF = 'installing code while the site runs is turned off on this site'
|
|
340
|
+
|
|
331
341
|
/**
|
|
332
342
|
* Who vouches for a bundle's source in place of a signer, given only by code in
|
|
333
343
|
* this process and never from a request (story 319):
|
|
@@ -769,10 +779,7 @@ export async function installBundleContent(
|
|
|
769
779
|
)
|
|
770
780
|
// The code half (story 241): only when asked, only where installs happen here.
|
|
771
781
|
const code = effective.installCode ? codeChanges(planCode(config, carried)) : []
|
|
772
|
-
|
|
773
|
-
config.installsElsewhere?.message ??
|
|
774
|
-
"this site does not install code while it runs: add the bundle's code to the site and deploy it"
|
|
775
|
-
if (code.length > 0 && !config.runtimeInstalls) return refuse([installsElsewhere], backup)
|
|
782
|
+
if (code.length > 0 && !config.runtimeInstalls) return refuse([RUNTIME_INSTALLS_OFF], backup)
|
|
776
783
|
// A bundle's value migrations are code too (story 300), unless they are the site's own.
|
|
777
784
|
const migrations =
|
|
778
785
|
vouch?.vouchedBy === 'site' || effective.withoutSchema ? [] : migrationChanges(config, carried)
|
|
@@ -780,12 +787,28 @@ export async function installBundleContent(
|
|
|
780
787
|
return refuse(
|
|
781
788
|
[
|
|
782
789
|
effective.installCode
|
|
783
|
-
?
|
|
790
|
+
? RUNTIME_INSTALLS_OFF
|
|
784
791
|
: 'this bundle brings schema migrations, which are code: install its code to bring them',
|
|
785
792
|
...migrations.map((file) => file.path),
|
|
786
793
|
],
|
|
787
794
|
backup,
|
|
788
795
|
)
|
|
796
|
+
// Templates are code as well (story 336): the server imports and runs them.
|
|
797
|
+
const templates =
|
|
798
|
+
vouch?.vouchedBy === 'site' || effective.withoutFiles ? [] : componentChanges(config, carried)
|
|
799
|
+
if (
|
|
800
|
+
templates.length > 0 &&
|
|
801
|
+
(!(effective.installTemplates ?? effective.installCode) || !config.runtimeInstalls)
|
|
802
|
+
)
|
|
803
|
+
return refuse(
|
|
804
|
+
[
|
|
805
|
+
config.runtimeInstalls
|
|
806
|
+
? 'this bundle adds or changes templates, which are code: installing them needs the permission to install code on this site'
|
|
807
|
+
: RUNTIME_INSTALLS_OFF,
|
|
808
|
+
...templates.map((file) => file.path),
|
|
809
|
+
],
|
|
810
|
+
backup,
|
|
811
|
+
)
|
|
789
812
|
const needingPermission = [
|
|
790
813
|
...(plan ? replacementsNeedingPermission(plan, effective) : []),
|
|
791
814
|
...(effective.replaceFiles ? [] : code.filter((file) => file.action === 'overwrite')),
|
package/src/bundle-sections.ts
CHANGED
|
@@ -140,6 +140,16 @@ export function migrationChanges(config: CromboloConfig, carried: CarriedSection
|
|
|
140
140
|
.filter((file) => file.action !== 'unchanged')
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
/** The templates a bundle would add or change here: code the server runs (story 336). */
|
|
144
|
+
export function componentChanges(config: CromboloConfig, carried: CarriedSections): SectionFile[] {
|
|
145
|
+
return (carried.carries.components ?? [])
|
|
146
|
+
.map((path) => {
|
|
147
|
+
const target = join(config.componentsDir, withinSection(path, 'components'))
|
|
148
|
+
return { path, target, action: actionFor(target, sourceOf(carried, path)) }
|
|
149
|
+
})
|
|
150
|
+
.filter((file) => file.action !== 'unchanged')
|
|
151
|
+
}
|
|
152
|
+
|
|
143
153
|
/** Compared as bytes: a public file is an image as often as it is text. */
|
|
144
154
|
function actionFor(target: string, source: string): FileAction {
|
|
145
155
|
if (!existsSync(target)) return 'create'
|
package/src/config.ts
CHANGED
|
@@ -25,7 +25,11 @@ import type { EmailPort } from './email.ts'
|
|
|
25
25
|
import type { GitConfig } from './git-routes.ts'
|
|
26
26
|
import { type UnrestrictedFrom, unrestrictedFrom } from './grant-policy.ts'
|
|
27
27
|
import { checkHost, type HostConfig } from './host-token.ts'
|
|
28
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
checkIdentityProviders,
|
|
30
|
+
type IdentityProvider,
|
|
31
|
+
type LockedIdentityProviders,
|
|
32
|
+
} from './identity-providers.ts'
|
|
29
33
|
import type { MediaStore } from './media-store.ts'
|
|
30
34
|
import type { JobSchedule } from './owner-jobs.ts'
|
|
31
35
|
import type { ProvenancePolicy, SignaturePolicy } from './provenance.ts'
|
|
@@ -176,6 +180,18 @@ export interface CromboloConfig {
|
|
|
176
180
|
* except under `bun test`.
|
|
177
181
|
*/
|
|
178
182
|
liveReload: boolean
|
|
183
|
+
/**
|
|
184
|
+
* Whether webhooks, a form's send-to-URL workflow and an identity provider's
|
|
185
|
+
* test may reach loopback, private and link-local addresses (stories 301,
|
|
186
|
+
* 304). `CROMBOLO_ALLOW_PRIVATE_ADDRESSES`; on in development only.
|
|
187
|
+
*/
|
|
188
|
+
allowPrivateAddresses: boolean
|
|
189
|
+
/**
|
|
190
|
+
* Identity providers no change from the back office reaches (story 305), by
|
|
191
|
+
* id, or all of them: `CROMBOLO_LOCKED_IDENTITY_PROVIDERS`, so a host locks
|
|
192
|
+
* them without the site's code. A provider's own `locked: true` does too.
|
|
193
|
+
*/
|
|
194
|
+
lockedIdentityProviders: LockedIdentityProviders
|
|
179
195
|
/**
|
|
180
196
|
* Whether the cache-busted asset path may be cached immutably. Defaults to
|
|
181
197
|
* `!development`.
|
|
@@ -325,6 +341,12 @@ export interface CromboloConfig {
|
|
|
325
341
|
* CROMBOLO_SCHEMA_WRITABLE says otherwise outright.
|
|
326
342
|
*/
|
|
327
343
|
schemaWritable: boolean
|
|
344
|
+
/**
|
|
345
|
+
* The back office may not change templates, stylesheets or scripts (story 337):
|
|
346
|
+
* for a site whose files come from its repository. Off unless set, in
|
|
347
|
+
* production too. `CROMBOLO_CONTENT_FILES_READONLY`.
|
|
348
|
+
*/
|
|
349
|
+
contentFilesReadOnly: boolean
|
|
328
350
|
/** Sync `schema/` at boot; a pipeline that runs `crombolo types sync` turns this off. */
|
|
329
351
|
syncSchemaAtBoot: boolean
|
|
330
352
|
/** Which database engine; from CROMBOLO_DB. */
|
|
@@ -543,12 +565,10 @@ export interface CromboloConfig {
|
|
|
543
565
|
*/
|
|
544
566
|
events?: Readonly<Record<string, SiteEventHandler>>
|
|
545
567
|
/**
|
|
546
|
-
*
|
|
547
|
-
* `
|
|
548
|
-
* go to loopback, private and link-local addresses: by default only on a
|
|
549
|
-
* development site. docs/webhooks.md.
|
|
568
|
+
* The server variables a webhook header's `env:NAME` may name besides
|
|
569
|
+
* `CROMBOLO_WEBHOOK_*` (story 301). docs/webhooks.md.
|
|
550
570
|
*/
|
|
551
|
-
webhooks?: { headerVariables?: readonly string[]
|
|
571
|
+
webhooks?: { headerVariables?: readonly string[] }
|
|
552
572
|
/**
|
|
553
573
|
* Installed extensions the site's code grants and sets (story 310), by bundle
|
|
554
574
|
* id: what it grants, as "Developer installed", and settings, which lock them
|
|
@@ -884,6 +904,7 @@ export function loadConfig(
|
|
|
884
904
|
? setting('CROMBOLO_SCHEMA_WRITABLE') === 'true'
|
|
885
905
|
: setting('NODE_ENV') !== 'production',
|
|
886
906
|
syncSchemaAtBoot: setting('CROMBOLO_SYNC_SCHEMA_AT_BOOT') !== 'false',
|
|
907
|
+
contentFilesReadOnly: setting('CROMBOLO_CONTENT_FILES_READONLY') === 'true',
|
|
887
908
|
dialect: setting('CROMBOLO_DB') === 'postgres' ? 'postgres' : 'sqlite',
|
|
888
909
|
pgDump: setting('CROMBOLO_PG_DUMP'),
|
|
889
910
|
upgradePolicy:
|
|
@@ -978,6 +999,8 @@ export function loadConfig(
|
|
|
978
999
|
// Resolved again below, once it is known whether this is development.
|
|
979
1000
|
errors: { showDetails: envFlag(setting('CROMBOLO_SHOW_ERROR_DETAILS')) ?? false },
|
|
980
1001
|
liveReload: envFlag(setting('CROMBOLO_LIVE_RELOAD')) ?? false,
|
|
1002
|
+
allowPrivateAddresses: envFlag(setting('CROMBOLO_ALLOW_PRIVATE_ADDRESSES')) ?? false,
|
|
1003
|
+
lockedIdentityProviders: lockedProviders(setting('CROMBOLO_LOCKED_IDENTITY_PROVIDERS')),
|
|
981
1004
|
seo: stripUndefined({
|
|
982
1005
|
sitemap: envFlag(setting('CROMBOLO_SITEMAP')),
|
|
983
1006
|
indexable: envFlag(setting('CROMBOLO_INDEXABLE')),
|
|
@@ -1054,6 +1077,14 @@ export function loadConfig(
|
|
|
1054
1077
|
overrides.liveReload ??
|
|
1055
1078
|
envFlag(setting('CROMBOLO_LIVE_RELOAD')) ??
|
|
1056
1079
|
(merged.development && setting('NODE_ENV') !== 'test')
|
|
1080
|
+
merged.allowPrivateAddresses =
|
|
1081
|
+
overrides.allowPrivateAddresses ??
|
|
1082
|
+
envFlag(setting('CROMBOLO_ALLOW_PRIVATE_ADDRESSES')) ??
|
|
1083
|
+
merged.development
|
|
1084
|
+
if (overrides.webhooks && 'allowPrivateAddresses' in overrides.webhooks)
|
|
1085
|
+
throw new Error(
|
|
1086
|
+
'webhooks.allowPrivateAddresses is now CROMBOLO_ALLOW_PRIVATE_ADDRESSES (allowPrivateAddresses in the config), which covers forms and identity providers too (story 304).',
|
|
1087
|
+
)
|
|
1057
1088
|
checkApiClient(merged.apiClient)
|
|
1058
1089
|
checkHost(merged.host)
|
|
1059
1090
|
// The key itself is refused, so a config left over from before says so rather
|
|
@@ -1126,6 +1157,14 @@ function nonNegative(value: string | undefined, fallback: number): number {
|
|
|
1126
1157
|
return Number.isInteger(parsed) && parsed >= 0 ? parsed : fallback
|
|
1127
1158
|
}
|
|
1128
1159
|
|
|
1160
|
+
function lockedProviders(value: string | undefined): LockedIdentityProviders {
|
|
1161
|
+
const ids = (value ?? '')
|
|
1162
|
+
.split(',')
|
|
1163
|
+
.map((id) => id.trim())
|
|
1164
|
+
.filter(Boolean)
|
|
1165
|
+
return ids.includes('all') ? 'all' : ids
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1129
1168
|
function envFlag(value: string | undefined): boolean | undefined {
|
|
1130
1169
|
return value === undefined ? undefined : value !== 'false'
|
|
1131
1170
|
}
|
|
@@ -1161,7 +1200,7 @@ export function describeDatabase(
|
|
|
1161
1200
|
}
|
|
1162
1201
|
}
|
|
1163
1202
|
|
|
1164
|
-
export const VERSION = '0.
|
|
1203
|
+
export const VERSION = '0.63.0'
|
|
1165
1204
|
|
|
1166
1205
|
/** A whole number of seconds from the environment; undefined when unset or not one. */
|
|
1167
1206
|
/** A positive number from a setting, else the default. */
|
package/src/content-query.ts
CHANGED
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
DocumentPermissions,
|
|
10
10
|
type GroupGrant,
|
|
11
11
|
permissionsForPath,
|
|
12
|
-
propertyValuePermissions,
|
|
13
12
|
ROOT_ACCESS,
|
|
14
13
|
} from '@crombolo/core'
|
|
15
14
|
import {
|
|
@@ -37,9 +36,8 @@ export function contentQueryScope(principal: Principal): QueryScope {
|
|
|
37
36
|
principal.isAdmin || browsesEverything(groups)
|
|
38
37
|
? undefined
|
|
39
38
|
: (chain) => permissionsForPath(groups, chain).has(DocumentPermissions.Read),
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
propertyValuePermissions(groups, key).has(DocumentPermissions.PropertyValueRead),
|
|
39
|
+
// Story 338: a field is never hidden from someone who may see the page.
|
|
40
|
+
readsProperty: () => true,
|
|
43
41
|
}
|
|
44
42
|
}
|
|
45
43
|
|
package/src/core.ts
CHANGED
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
ViewSnapshots,
|
|
41
41
|
} from '@crombolo/render'
|
|
42
42
|
import type { SyncReport } from '@crombolo/schema'
|
|
43
|
-
import { recordAudit } from './adapters/audit.ts'
|
|
43
|
+
import { attributed, recordAudit } from './adapters/audit.ts'
|
|
44
44
|
import { createMediaSource, createPublishedContentSource } from './adapters/documents.ts'
|
|
45
45
|
import { backOfficeUrl, documentEditUrl } from './back-office-url.ts'
|
|
46
46
|
import { BACKOFFICE_EXTERNAL_PATH } from './backoffice-external.ts'
|
|
@@ -78,6 +78,7 @@ import {
|
|
|
78
78
|
import { createFormRegistry, formSigningSecret, signFormToken } from './form-submit.ts'
|
|
79
79
|
import { formTypesOf } from './form-types.ts'
|
|
80
80
|
import { createWorkflowRunner } from './form-workflows.ts'
|
|
81
|
+
import { switchOffUntrusted } from './grant-trust.ts'
|
|
81
82
|
import {
|
|
82
83
|
createBundleIdentityProviders,
|
|
83
84
|
IdentityProviderOverrides,
|
|
@@ -341,6 +342,11 @@ export async function createCore(config: CromboloConfig, hooks: CoreHooks) {
|
|
|
341
342
|
detail: `narrowed to what it asks for: ${declaredPermissions(pkg).join(', ') || 'nothing'}`,
|
|
342
343
|
source: 'boot',
|
|
343
344
|
})
|
|
345
|
+
// Story 335: before any extension runs, one nobody this site trusts vouches for loses its upper level.
|
|
346
|
+
if (owns)
|
|
347
|
+
await switchOffUntrusted(db, config, extensions, bundleGrants).catch((error: unknown) =>
|
|
348
|
+
log.error('Checking who vouches for extensions failed: {error}', { error: String(error) }),
|
|
349
|
+
)
|
|
344
350
|
// A configured schema store is copied down before anything reads `schema/`, and
|
|
345
351
|
// becomes the schema directory for this boot. Everything after here — loading,
|
|
346
352
|
// validation, hashing, sync, the writer — works on files exactly as it always has.
|
|
@@ -500,7 +506,7 @@ export async function createCore(config: CromboloConfig, hooks: CoreHooks) {
|
|
|
500
506
|
// A development site's receivers are on this machine, as the Next.js template's is.
|
|
501
507
|
outbound: {
|
|
502
508
|
...config.webhooks,
|
|
503
|
-
allowPrivateAddresses: config.
|
|
509
|
+
allowPrivateAddresses: config.allowPrivateAddresses,
|
|
504
510
|
},
|
|
505
511
|
isBundleOn: (bundleId) => bundleGrants.isOn(bundleId),
|
|
506
512
|
bundleOrigins: (bundleId) => {
|
|
@@ -575,6 +581,60 @@ export async function createCore(config: CromboloConfig, hooks: CoreHooks) {
|
|
|
575
581
|
* boot — see `createServerBundles`.
|
|
576
582
|
*/
|
|
577
583
|
// Story 198: media as the member, built at the first request.
|
|
584
|
+
/** The identity providers an extension edits (story 033), auditing each change when told how (305). */
|
|
585
|
+
const identityProvidersFor = (
|
|
586
|
+
audit?: Parameters<typeof createBundleIdentityProviders>[0]['audit'],
|
|
587
|
+
) =>
|
|
588
|
+
createBundleIdentityProviders({
|
|
589
|
+
audit,
|
|
590
|
+
overrides: new IdentityProviderOverrides(
|
|
591
|
+
db,
|
|
592
|
+
config.secretKey,
|
|
593
|
+
config.lockedIdentityProviders,
|
|
594
|
+
),
|
|
595
|
+
members: config.memberIdentityProviders,
|
|
596
|
+
backoffice: config.backofficeIdentityProviders,
|
|
597
|
+
memberCallbackPath: MEMBER_EXTERNAL_SIGN_IN_PATH,
|
|
598
|
+
backofficeCallbackPath: BACKOFFICE_EXTERNAL_PATH,
|
|
599
|
+
outbound: { allowPrivateAddresses: config.allowPrivateAddresses },
|
|
600
|
+
groups: async (audience) =>
|
|
601
|
+
audience === 'user'
|
|
602
|
+
? (await new UserGroupRepository(db).all()).map((g) => ({
|
|
603
|
+
value: g.alias,
|
|
604
|
+
name: g.name,
|
|
605
|
+
}))
|
|
606
|
+
: (
|
|
607
|
+
await db.q
|
|
608
|
+
.selectFrom('node')
|
|
609
|
+
.select('text')
|
|
610
|
+
.where('node_object_type', '=', ObjectTypes.MemberGroup)
|
|
611
|
+
.orderBy('text')
|
|
612
|
+
.execute()
|
|
613
|
+
).map((g) => ({ value: String(g.text), name: String(g.text) })),
|
|
614
|
+
})
|
|
615
|
+
// Story 305: said at boot, a provider that signs nobody in and a locked id that names none.
|
|
616
|
+
void (async () => {
|
|
617
|
+
const overrides = new IdentityProviderOverrides(
|
|
618
|
+
db,
|
|
619
|
+
config.secretKey,
|
|
620
|
+
config.lockedIdentityProviders,
|
|
621
|
+
)
|
|
622
|
+
const declared = [
|
|
623
|
+
...config.memberIdentityProviders.map((provider) => ['member', provider] as const),
|
|
624
|
+
...config.backofficeIdentityProviders.map((provider) => ['user', provider] as const),
|
|
625
|
+
]
|
|
626
|
+
for (const [audience, provider] of declared) {
|
|
627
|
+
const effective = await overrides.apply(audience, provider).catch(() => provider)
|
|
628
|
+
if (effective.unavailable) log.warning('{reason}', { reason: effective.unavailable })
|
|
629
|
+
}
|
|
630
|
+
if (Array.isArray(config.lockedIdentityProviders))
|
|
631
|
+
for (const id of config.lockedIdentityProviders)
|
|
632
|
+
if (!declared.some(([, provider]) => provider.oidc.id === id))
|
|
633
|
+
log.warning(
|
|
634
|
+
'CROMBOLO_LOCKED_IDENTITY_PROVIDERS names {id}, which the config declares no identity provider as.',
|
|
635
|
+
{ id },
|
|
636
|
+
)
|
|
637
|
+
})()
|
|
578
638
|
let bundleMedia: BundleMediaFactory | undefined
|
|
579
639
|
let bundleMediaFolders = new Map<string, ResolvedMediaFolder[]>()
|
|
580
640
|
const bundles =
|
|
@@ -601,30 +661,27 @@ export async function createCore(config: CromboloConfig, hooks: CoreHooks) {
|
|
|
601
661
|
},
|
|
602
662
|
},
|
|
603
663
|
log: bundleLog('bundle'),
|
|
604
|
-
identityProviders:
|
|
605
|
-
overrides: new IdentityProviderOverrides(db, config.secretKey),
|
|
606
|
-
members: config.memberIdentityProviders,
|
|
607
|
-
backoffice: config.backofficeIdentityProviders,
|
|
608
|
-
memberCallbackPath: MEMBER_EXTERNAL_SIGN_IN_PATH,
|
|
609
|
-
backofficeCallbackPath: BACKOFFICE_EXTERNAL_PATH,
|
|
610
|
-
groups: async (audience) =>
|
|
611
|
-
audience === 'user'
|
|
612
|
-
? (await new UserGroupRepository(db).all()).map((g) => ({
|
|
613
|
-
value: g.alias,
|
|
614
|
-
name: g.name,
|
|
615
|
-
}))
|
|
616
|
-
: (
|
|
617
|
-
await db.q
|
|
618
|
-
.selectFrom('node')
|
|
619
|
-
.select('text')
|
|
620
|
-
.where('node_object_type', '=', ObjectTypes.MemberGroup)
|
|
621
|
-
.orderBy('text')
|
|
622
|
-
.execute()
|
|
623
|
-
).map((g) => ({ value: String(g.text), name: String(g.text) })),
|
|
624
|
-
}),
|
|
664
|
+
identityProviders: identityProvidersFor(),
|
|
625
665
|
},
|
|
626
666
|
log: (id) => bundleLog(id),
|
|
627
667
|
callerHost: {
|
|
668
|
+
// Story 305: each change audited as the person, by the extension.
|
|
669
|
+
identityProviders: (caller, bundle) =>
|
|
670
|
+
identityProvidersFor(async (action, provider, detail) => {
|
|
671
|
+
const person = personOf(caller)
|
|
672
|
+
const name = bundlePackages.find((pkg) => pkg.id === bundle.id)?.name ?? bundle.id
|
|
673
|
+
await recordAudit(db, {
|
|
674
|
+
category: 'settings',
|
|
675
|
+
action,
|
|
676
|
+
source: 'request',
|
|
677
|
+
userKey: person.personKey,
|
|
678
|
+
userName: person.personName,
|
|
679
|
+
entityType: 'IdentityProvider',
|
|
680
|
+
entityKey: `${provider.audience}:${provider.id}`,
|
|
681
|
+
entityName: provider.name,
|
|
682
|
+
detail: attributed(name, person.personName, detail),
|
|
683
|
+
})
|
|
684
|
+
}),
|
|
628
685
|
// Story 308: the site's areas, as the extension; story 325, or as the person using it.
|
|
629
686
|
api: (caller, bundle) => {
|
|
630
687
|
const pkg = bundlePackages.find((candidate) => candidate.id === bundle.id)
|
|
@@ -678,8 +735,7 @@ export async function createCore(config: CromboloConfig, hooks: CoreHooks) {
|
|
|
678
735
|
}
|
|
679
736
|
return timed(activity, event, () =>
|
|
680
737
|
pinnedFetch(input, init, {
|
|
681
|
-
allowPrivateAddresses:
|
|
682
|
-
config.webhooks?.allowPrivateAddresses ?? config.development,
|
|
738
|
+
allowPrivateAddresses: config.allowPrivateAddresses,
|
|
683
739
|
}),
|
|
684
740
|
)
|
|
685
741
|
},
|
|
@@ -854,6 +910,8 @@ export async function createCore(config: CromboloConfig, hooks: CoreHooks) {
|
|
|
854
910
|
resolveForm: (form) => cache.resolveForm(form),
|
|
855
911
|
operations: operations.documents,
|
|
856
912
|
bundleWorkflows: formTypes.workflows,
|
|
913
|
+
outbound: { allowPrivateAddresses: config.allowPrivateAddresses },
|
|
914
|
+
secretKey: config.secretKey,
|
|
857
915
|
renderEmail: (alias, props) => renderer.renderEmail(alias, props),
|
|
858
916
|
site: async () => ({
|
|
859
917
|
name: (await hooks.siteName?.()) || config.siteName,
|