@crombolo/server 0.56.0 → 0.57.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 +16 -13
- package/src/adapters/bundles.ts +72 -6
- package/src/adapters/health.ts +30 -1
- package/src/bundle-admin.ts +246 -23
- package/src/bundle-api.ts +299 -0
- package/src/bundle-build.ts +4 -3
- package/src/bundle-grants.ts +133 -18
- package/src/bundle-install.ts +127 -8
- package/src/bundle-sections.ts +19 -0
- package/src/bundles.ts +87 -7
- package/src/component-templates-api.ts +27 -6
- package/src/components.ts +7 -0
- package/src/config.ts +36 -3
- package/src/core.ts +188 -16
- package/src/created-extension.ts +101 -0
- package/src/extension-components.ts +157 -0
- package/src/extension-discovery.ts +180 -0
- package/src/extension-process.ts +854 -0
- package/src/extension-sql.ts +85 -0
- package/src/index.ts +17 -0
- package/src/marketplace.ts +182 -54
- package/src/ports.ts +8 -0
- package/src/provenance.ts +181 -15
- package/src/remote.ts +54 -8
- package/src/schema.ts +31 -4
- package/src/seed/compile.ts +4 -2
- package/src/seed/export.ts +1 -1
- package/src/seed/values.ts +3 -3
- package/src/seo.ts +13 -5
- package/src/server.ts +190 -43
- package/src/settings.ts +12 -4
- package/src/signing-keys.ts +155 -0
- package/src/site-content.ts +11 -1
- package/src/site-file.ts +20 -6
- package/src/site-public.ts +1 -1
- package/src/site-sections.ts +1 -1
- package/src/site-trust.ts +238 -0
- package/src/transfer-dashboard.ts +6 -0
- package/src/trusted-signers-admin.ts +132 -0
- package/src/webhooks.ts +16 -1
package/src/provenance.ts
CHANGED
|
@@ -13,6 +13,14 @@ import { bundleFromJSON, type SerializedBundle } from '@sigstore/bundle'
|
|
|
13
13
|
import { X509Certificate } from '@sigstore/core'
|
|
14
14
|
import { TrustedRoot } from '@sigstore/protobuf-specs'
|
|
15
15
|
import { toSignedEntity, toTrustMaterial, Verifier } from '@sigstore/verify'
|
|
16
|
+
import {
|
|
17
|
+
type KeyPair,
|
|
18
|
+
type PublicKey,
|
|
19
|
+
readPublicKey,
|
|
20
|
+
signedStatement,
|
|
21
|
+
signWith,
|
|
22
|
+
verifiedBy,
|
|
23
|
+
} from './signing-keys.ts'
|
|
16
24
|
|
|
17
25
|
/** The file in a package that holds its signature, and the one file the digest leaves out. */
|
|
18
26
|
export const PROVENANCE_FILE = 'provenance.json'
|
|
@@ -67,13 +75,22 @@ export interface ProvenanceLinks {
|
|
|
67
75
|
log: string | null
|
|
68
76
|
}
|
|
69
77
|
|
|
70
|
-
/**
|
|
78
|
+
/** A key's signature (story 316): its public line, over the digest, name and version. */
|
|
79
|
+
export interface KeySignatureFile {
|
|
80
|
+
publicKey: string
|
|
81
|
+
signature: string
|
|
82
|
+
name: string
|
|
83
|
+
version: string
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** `provenance.json`: a Sigstore signature from CI, a key's, or both. */
|
|
71
87
|
export interface ProvenanceFile {
|
|
72
88
|
format: 1
|
|
73
89
|
digest: string
|
|
74
|
-
signature
|
|
75
|
-
source
|
|
76
|
-
links
|
|
90
|
+
signature?: SerializedBundle
|
|
91
|
+
source?: ProvenanceSource
|
|
92
|
+
links?: ProvenanceLinks
|
|
93
|
+
key?: KeySignatureFile
|
|
77
94
|
}
|
|
78
95
|
|
|
79
96
|
/**
|
|
@@ -85,12 +102,26 @@ export type ProvenanceState = 'signed' | 'unsigned' | 'invalid' | 'unchecked' |
|
|
|
85
102
|
export interface ProvenanceResult {
|
|
86
103
|
state: ProvenanceState
|
|
87
104
|
digest?: string
|
|
105
|
+
/** The CI build that signed it, by Sigstore. */
|
|
88
106
|
source?: ProvenanceSource
|
|
89
107
|
links?: ProvenanceLinks
|
|
108
|
+
/** The key that signed it (story 316). */
|
|
109
|
+
key?: PublicKey
|
|
110
|
+
/** The package it is, from its own signed `package.json`, for the downgrade check. */
|
|
111
|
+
package?: { name: string; version: string }
|
|
90
112
|
/** Why a signature was not accepted, in words a person can act on. */
|
|
91
113
|
reason?: string
|
|
92
114
|
}
|
|
93
115
|
|
|
116
|
+
/** A package's `provenance.json`, when it has one that reads. */
|
|
117
|
+
function readProvenance(dir: string): ProvenanceFile | undefined {
|
|
118
|
+
try {
|
|
119
|
+
return JSON.parse(readFileSync(join(dir, PROVENANCE_FILE), 'utf8')) as ProvenanceFile
|
|
120
|
+
} catch {
|
|
121
|
+
return undefined
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
94
125
|
/** Every file a package's digest covers: all of it but its signature, installs and history. */
|
|
95
126
|
function packageFiles(dir: string): string[] {
|
|
96
127
|
const out: string[] = []
|
|
@@ -113,16 +144,73 @@ function packageFiles(dir: string): string[] {
|
|
|
113
144
|
* integrity does not: `package.json` and an extension bundle's code.
|
|
114
145
|
*/
|
|
115
146
|
export function packageDigest(dir: string): string {
|
|
147
|
+
return digestOfFiles(
|
|
148
|
+
packageFiles(dir).map((path) => ({ path, bytes: readFileSync(join(dir, path)) })),
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** The same digest, of files held in memory: a package not yet written out. */
|
|
153
|
+
export function digestOfFiles(files: readonly { path: string; bytes: Uint8Array }[]): string {
|
|
116
154
|
const hasher = new Bun.CryptoHasher('sha256')
|
|
117
|
-
for (const
|
|
118
|
-
|
|
155
|
+
for (const file of files
|
|
156
|
+
.filter((entry) => entry.path !== PROVENANCE_FILE)
|
|
157
|
+
.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0))) {
|
|
158
|
+
hasher.update(file.path)
|
|
119
159
|
hasher.update('\0')
|
|
120
|
-
hasher.update(
|
|
160
|
+
hasher.update(file.bytes)
|
|
121
161
|
hasher.update('\n')
|
|
122
162
|
}
|
|
123
163
|
return `sha256-${hasher.digest('hex')}`
|
|
124
164
|
}
|
|
125
165
|
|
|
166
|
+
/** A package's name and version, from its `package.json`. */
|
|
167
|
+
function packageOf(dir: string): { name: string; version: string } | undefined {
|
|
168
|
+
try {
|
|
169
|
+
const json = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')) as {
|
|
170
|
+
name?: unknown
|
|
171
|
+
version?: unknown
|
|
172
|
+
}
|
|
173
|
+
return typeof json.name === 'string' && typeof json.version === 'string'
|
|
174
|
+
? { name: json.name, version: json.version }
|
|
175
|
+
: undefined
|
|
176
|
+
} catch {
|
|
177
|
+
return undefined
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* A key's signature over a package's files (story 316), as `provenance.json`
|
|
183
|
+
* holds it; a Sigstore signature already there is kept beside it.
|
|
184
|
+
*/
|
|
185
|
+
export function keySignatureOver(
|
|
186
|
+
files: readonly { path: string; bytes: Uint8Array }[],
|
|
187
|
+
pair: KeyPair,
|
|
188
|
+
existing?: ProvenanceFile,
|
|
189
|
+
): ProvenanceFile {
|
|
190
|
+
const json = files.find((file) => file.path === 'package.json')
|
|
191
|
+
const pkg = json
|
|
192
|
+
? (JSON.parse(new TextDecoder().decode(json.bytes)) as { name?: string; version?: string })
|
|
193
|
+
: {}
|
|
194
|
+
if (!pkg.name || !pkg.version) throw new Error('A bundle is signed once it is a package.')
|
|
195
|
+
const digest = digestOfFiles(files)
|
|
196
|
+
if (existing?.digest && existing.digest !== digest)
|
|
197
|
+
throw new Error('The bundle changed after its CI signature: sign it with its key first.')
|
|
198
|
+
return {
|
|
199
|
+
...(existing ?? {}),
|
|
200
|
+
format: 1,
|
|
201
|
+
digest,
|
|
202
|
+
key: {
|
|
203
|
+
publicKey: pair.publicKey.line,
|
|
204
|
+
signature: signWith(
|
|
205
|
+
pair.privateKey,
|
|
206
|
+
signedStatement({ digest, name: pkg.name, version: pkg.version }),
|
|
207
|
+
),
|
|
208
|
+
name: pkg.name,
|
|
209
|
+
version: pkg.version,
|
|
210
|
+
},
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
126
214
|
const hexOf = (digest: string) => digest.replace(/^sha256-/, '')
|
|
127
215
|
|
|
128
216
|
/** The statement signed: the digest alone, so the public log learns nothing of the bundle but it. */
|
|
@@ -189,8 +277,15 @@ export const refName = (ref: string): string => ref.replace(/^refs\/(tags|heads)
|
|
|
189
277
|
export function describeProvenance(result: ProvenanceResult): string {
|
|
190
278
|
switch (result.state) {
|
|
191
279
|
case 'signed': {
|
|
192
|
-
const source = result.source
|
|
193
|
-
|
|
280
|
+
const source = result.source
|
|
281
|
+
const built = source
|
|
282
|
+
? `built from github.com/${source.repository} at ${refName(source.ref)} (${source.commit.slice(0, 7)})`
|
|
283
|
+
: undefined
|
|
284
|
+
const key = result.key
|
|
285
|
+
? `signed by ${result.key.comment || 'a key'} (${result.key.fingerprint})`
|
|
286
|
+
: undefined
|
|
287
|
+
const said = [built, key].filter(Boolean).join(', and ')
|
|
288
|
+
return `Signed: ${said}`
|
|
194
289
|
}
|
|
195
290
|
case 'unsigned':
|
|
196
291
|
return 'Not signed'
|
|
@@ -237,7 +332,17 @@ export function repositoryVisibility(): 'public' | 'private' | 'internal' | unde
|
|
|
237
332
|
* job needs `id-token: write`; Sigstore turns its identity token into a
|
|
238
333
|
* short-lived certificate naming the repository, ref, commit and workflow.
|
|
239
334
|
*/
|
|
240
|
-
|
|
335
|
+
/** What a Sigstore signing writes: its source and links always there. */
|
|
336
|
+
export type SigstoreProvenance = ProvenanceFile & {
|
|
337
|
+
signature: SerializedBundle
|
|
338
|
+
source: ProvenanceSource
|
|
339
|
+
links: ProvenanceLinks
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
export async function signPackage(
|
|
343
|
+
dir: string,
|
|
344
|
+
options: SignOptions = {},
|
|
345
|
+
): Promise<SigstoreProvenance> {
|
|
241
346
|
if (Bun.env.GITHUB_ACTIONS !== 'true' || !Bun.env.ACTIONS_ID_TOKEN_REQUEST_URL)
|
|
242
347
|
throw new Error(
|
|
243
348
|
'A bundle is signed in GitHub Actions, by a job with `permissions: id-token: write`: run `crombolo bundle sign` there.',
|
|
@@ -252,7 +357,10 @@ export async function signPackage(dir: string, options: SignOptions = {}): Promi
|
|
|
252
357
|
const signature = await attest(statement(digest), IN_TOTO)
|
|
253
358
|
const source = sourceOf(signature)
|
|
254
359
|
if (!source) throw new Error('The signature Sigstore returned names no GitHub repository.')
|
|
255
|
-
|
|
360
|
+
// A key's signature already there is over the same digest, and kept (story 316).
|
|
361
|
+
const existing = readProvenance(dir)
|
|
362
|
+
const file: SigstoreProvenance = {
|
|
363
|
+
...(existing?.digest === digest && existing.key ? { key: existing.key } : {}),
|
|
256
364
|
format: 1,
|
|
257
365
|
digest,
|
|
258
366
|
signature,
|
|
@@ -338,11 +446,33 @@ export async function verifyProvenanceWith(
|
|
|
338
446
|
} catch {
|
|
339
447
|
return invalid(`${PROVENANCE_FILE} is not JSON`)
|
|
340
448
|
}
|
|
341
|
-
if (provenance.format !== 1 || !provenance.signature)
|
|
449
|
+
if (provenance.format !== 1 || (!provenance.signature && !provenance.key))
|
|
342
450
|
return invalid(`${PROVENANCE_FILE} is not a format this release reads`)
|
|
343
451
|
const digest = packageDigest(dir)
|
|
344
452
|
if (provenance.digest !== digest)
|
|
345
453
|
return invalid('the bundle has changed since it was signed', digest)
|
|
454
|
+
const pkg = packageOf(dir)
|
|
455
|
+
|
|
456
|
+
// A key's signature (story 316), checked on its own terms.
|
|
457
|
+
let key: PublicKey | undefined
|
|
458
|
+
if (provenance.key) {
|
|
459
|
+
const read = readPublicKey(provenance.key.publicKey)
|
|
460
|
+
if ('problem' in read) return invalid(`its key is not one: ${read.problem}`, digest)
|
|
461
|
+
if (
|
|
462
|
+
!pkg ||
|
|
463
|
+
provenance.key.name !== pkg.name ||
|
|
464
|
+
provenance.key.version !== pkg.version ||
|
|
465
|
+
!verifiedBy(
|
|
466
|
+
read,
|
|
467
|
+
signedStatement({ digest, name: pkg.name, version: pkg.version }),
|
|
468
|
+
provenance.key.signature,
|
|
469
|
+
)
|
|
470
|
+
)
|
|
471
|
+
return invalid('the key signature does not check out', digest)
|
|
472
|
+
key = read
|
|
473
|
+
}
|
|
474
|
+
if (!provenance.signature)
|
|
475
|
+
return { state: 'signed', digest, key, ...(pkg ? { package: pkg } : {}) }
|
|
346
476
|
|
|
347
477
|
let check = seams.verifySignature
|
|
348
478
|
if (!check) {
|
|
@@ -403,7 +533,14 @@ export async function verifyProvenanceWith(
|
|
|
403
533
|
`${PROVENANCE_FILE} says ${key} ${claimed?.[key] ?? '(none)'}, and the certificate says ${source[key]}`,
|
|
404
534
|
digest,
|
|
405
535
|
)
|
|
406
|
-
return {
|
|
536
|
+
return {
|
|
537
|
+
state: 'signed',
|
|
538
|
+
digest,
|
|
539
|
+
source,
|
|
540
|
+
links: linksFor(source, provenance.signature),
|
|
541
|
+
...(key ? { key } : {}),
|
|
542
|
+
...(pkg ? { package: pkg } : {}),
|
|
543
|
+
}
|
|
407
544
|
}
|
|
408
545
|
|
|
409
546
|
export type SignaturePolicy = 'optional' | 'required'
|
|
@@ -439,7 +576,9 @@ export function provenanceProblem(
|
|
|
439
576
|
return policy.signatures === 'required'
|
|
440
577
|
? 'this site takes only signed bundles (CROMBOLO_BUNDLE_SIGNATURES=required); the producer signs it with `crombolo bundle sign` in GitHub Actions'
|
|
441
578
|
: undefined
|
|
442
|
-
const source = result.source
|
|
579
|
+
const source = result.source
|
|
580
|
+
// A bundle signed by a key alone is a site bundle's matter (story 316).
|
|
581
|
+
if (!source) return undefined
|
|
443
582
|
if (policy.sources.length > 0 && !policy.sources.some((entry) => sourceAllowed(source, entry)))
|
|
444
583
|
return `it was built from github.com/${source.repository} at ${refName(source.ref)}, and this site takes signed bundles only from ${policy.sources.join(', ')} (CROMBOLO_BUNDLE_SOURCES)`
|
|
445
584
|
return undefined
|
|
@@ -479,7 +618,10 @@ export async function verifyPackage(
|
|
|
479
618
|
}
|
|
480
619
|
|
|
481
620
|
/** Signs a package directory, or a `.tgz` in place with `provenance.json` added to it. */
|
|
482
|
-
export async function signPath(
|
|
621
|
+
export async function signPath(
|
|
622
|
+
path: string,
|
|
623
|
+
options: SignOptions = {},
|
|
624
|
+
): Promise<SigstoreProvenance> {
|
|
483
625
|
if (!isTarball(path)) return signPackage(path, options)
|
|
484
626
|
const { writeNpmTarball } = await import('./tar.ts')
|
|
485
627
|
return withUnpacked(path, async (dir) => {
|
|
@@ -492,3 +634,27 @@ export async function signPath(path: string, options: SignOptions = {}): Promise
|
|
|
492
634
|
return signed
|
|
493
635
|
})
|
|
494
636
|
}
|
|
637
|
+
|
|
638
|
+
/** Signs a package directory, or a `.tgz` in place, with a key (story 316). */
|
|
639
|
+
export async function signPathWithKey(path: string, pair: KeyPair): Promise<ProvenanceFile> {
|
|
640
|
+
const sign = (dir: string) => {
|
|
641
|
+
const files = packageFiles(dir).map((file) => ({
|
|
642
|
+
path: file,
|
|
643
|
+
bytes: new Uint8Array(readFileSync(join(dir, file))),
|
|
644
|
+
}))
|
|
645
|
+
const signed = keySignatureOver(files, pair, readProvenance(dir))
|
|
646
|
+
writeFileSync(join(dir, PROVENANCE_FILE), `${JSON.stringify(signed, null, 2)}\n`)
|
|
647
|
+
return signed
|
|
648
|
+
}
|
|
649
|
+
if (!isTarball(path)) return sign(path)
|
|
650
|
+
const { writeNpmTarball } = await import('./tar.ts')
|
|
651
|
+
return withUnpacked(path, async (dir) => {
|
|
652
|
+
const signed = sign(dir)
|
|
653
|
+
const entries = [...packageFiles(dir), PROVENANCE_FILE].map((file) => ({
|
|
654
|
+
path: file,
|
|
655
|
+
bytes: new Uint8Array(readFileSync(join(dir, file))),
|
|
656
|
+
}))
|
|
657
|
+
writeFileSync(path, writeNpmTarball(entries))
|
|
658
|
+
return signed
|
|
659
|
+
})
|
|
660
|
+
}
|
package/src/remote.ts
CHANGED
|
@@ -34,14 +34,17 @@ import {
|
|
|
34
34
|
type TrustRule,
|
|
35
35
|
} from '@crombolo/data'
|
|
36
36
|
import {
|
|
37
|
+
BUNDLE_FORMAT_VERSION,
|
|
37
38
|
type ContentSet,
|
|
38
39
|
isResolution,
|
|
39
40
|
type NodeResolutions,
|
|
41
|
+
OLDEST_BUNDLE_FORMAT_VERSION,
|
|
40
42
|
type Resolution,
|
|
41
43
|
revertRun,
|
|
42
44
|
} from '@crombolo/transfer'
|
|
43
45
|
import { readAuditPageQuery, recordAudit } from './adapters/audit.ts'
|
|
44
|
-
import type
|
|
46
|
+
import { type BundleAdmin, settingsIn } from './bundle-admin.ts'
|
|
47
|
+
import { actAsChoice } from './bundle-api.ts'
|
|
45
48
|
import { codeChanges, installedCode, planCode } from './bundle-code-install.ts'
|
|
46
49
|
import {
|
|
47
50
|
checkBundleContent,
|
|
@@ -197,6 +200,8 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
197
200
|
const discovery = (origin: string) => ({
|
|
198
201
|
protocol: 'crombolo-remote',
|
|
199
202
|
versions: [REMOTE_PROTOCOL_VERSION],
|
|
203
|
+
// The bundle formats this site reads, oldest and newest (story 306).
|
|
204
|
+
bundleFormats: [OLDEST_BUNDLE_FORMAT_VERSION, BUNDLE_FORMAT_VERSION],
|
|
200
205
|
name: config.siteName,
|
|
201
206
|
api: `${origin}${REMOTE_API_PATH}`,
|
|
202
207
|
auth: {
|
|
@@ -512,6 +517,7 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
512
517
|
const canBackUp = config.dialect === 'sqlite' || Boolean(config.pgDump)
|
|
513
518
|
const result = await installBundleContent(db, config, {
|
|
514
519
|
bundle: dir,
|
|
520
|
+
expects: 'site' as const,
|
|
515
521
|
replace: 'replace',
|
|
516
522
|
passphrase,
|
|
517
523
|
backupTaken: !canBackUp,
|
|
@@ -636,7 +642,7 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
636
642
|
return { sha256: hasher.digest('hex'), size }
|
|
637
643
|
}
|
|
638
644
|
|
|
639
|
-
/** The options a
|
|
645
|
+
/** The options a site apply was sent with, in `Crombolo-Options` (story 167). */
|
|
640
646
|
const applyOptions = (request: Request) => {
|
|
641
647
|
let raw: Record<string, unknown> = {}
|
|
642
648
|
try {
|
|
@@ -656,6 +662,7 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
656
662
|
dryRun: raw.dryRun === true,
|
|
657
663
|
publish: raw.publish === true,
|
|
658
664
|
replaceFiles: raw.replaceFiles === true,
|
|
665
|
+
allowDowngrade: raw.allowDowngrade === true,
|
|
659
666
|
label: typeof raw.label === 'string' ? raw.label.slice(0, 200) : undefined,
|
|
660
667
|
resolutions,
|
|
661
668
|
resolveAll,
|
|
@@ -664,7 +671,7 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
664
671
|
|
|
665
672
|
/**
|
|
666
673
|
* A bundle applied here (story 167): checked, and unless a dry run backed up
|
|
667
|
-
* and applied in one transaction as `
|
|
674
|
+
* and applied in one transaction as `site apply` does on a site's own
|
|
668
675
|
* machine. Content needs the `content` level and the right to change this
|
|
669
676
|
* site; schema, views or code need `all` and Crombolo.Remote.ApplyStructure.
|
|
670
677
|
*/
|
|
@@ -750,11 +757,13 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
750
757
|
})
|
|
751
758
|
const input = {
|
|
752
759
|
bundle: dir,
|
|
760
|
+
expects: 'site' as const,
|
|
753
761
|
publish: asked.publish,
|
|
754
762
|
replaceFiles: asked.replaceFiles,
|
|
755
763
|
installCode: code.length > 0,
|
|
756
764
|
resolutions: asked.resolutions,
|
|
757
765
|
resolveAll: asked.resolveAll,
|
|
766
|
+
allowDowngrade: asked.allowDowngrade,
|
|
758
767
|
by: principal.name,
|
|
759
768
|
}
|
|
760
769
|
const report = (check: {
|
|
@@ -778,6 +787,7 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
778
787
|
structural,
|
|
779
788
|
provenance,
|
|
780
789
|
code: code.map((file) => ({ path: file.path, action: file.action })),
|
|
790
|
+
sitePackage: checked.sitePackage ?? null,
|
|
781
791
|
bundle: checked.bundle,
|
|
782
792
|
...report(checked.check),
|
|
783
793
|
clean: checked.clean,
|
|
@@ -823,7 +833,7 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
823
833
|
}
|
|
824
834
|
}
|
|
825
835
|
|
|
826
|
-
/** The applies on this site, newest first: for `
|
|
836
|
+
/** The applies on this site, newest first: for `site runs --remote`. */
|
|
827
837
|
async function listRuns(url: URL, principal: Principal): Promise<Response> {
|
|
828
838
|
if (!atLeast('read')) return notAtLevel('read', 'reads')
|
|
829
839
|
if (!may(principal, RemotePermissions.Pull) && !mayChange(principal))
|
|
@@ -843,6 +853,7 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
843
853
|
bundleId: run.bundleId,
|
|
844
854
|
bundleLabel: run.bundleLabel ?? null,
|
|
845
855
|
appliedBy: run.appliedBy ?? null,
|
|
856
|
+
bundleType: run.bundleType,
|
|
846
857
|
})),
|
|
847
858
|
})
|
|
848
859
|
}
|
|
@@ -878,6 +889,30 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
878
889
|
}
|
|
879
890
|
if (!fromThisSiteOrBearer(request)) return new Response('Forbidden', { status: 403 })
|
|
880
891
|
if (!atLeast('all')) return notAtLevel('all', 'installing and switching bundles')
|
|
892
|
+
// Story 309: granting an installed extension what it asks for.
|
|
893
|
+
const granting = /^installed\/(.+)\/grant$/.exec(what)
|
|
894
|
+
if (granting && request.method === 'POST') {
|
|
895
|
+
if (!may(principal, RemotePermissions.InstallCode))
|
|
896
|
+
return problem(403, {
|
|
897
|
+
code: 'forbidden-code',
|
|
898
|
+
title: 'You may not grant an extension on this site',
|
|
899
|
+
detail: 'Granting one needs Crombolo.Remote.InstallCode, given by a group.',
|
|
900
|
+
})
|
|
901
|
+
const body = (await request.json().catch(() => ({}))) as Record<string, unknown>
|
|
902
|
+
const { status, ...outcome } = await bundles.grant(
|
|
903
|
+
actor,
|
|
904
|
+
decodeURIComponent(granting[1] as string),
|
|
905
|
+
{
|
|
906
|
+
grant: Array.isArray(body.grant)
|
|
907
|
+
? body.grant.filter((p): p is string => typeof p === 'string')
|
|
908
|
+
: [],
|
|
909
|
+
actAs: actAsChoice(body.actAs),
|
|
910
|
+
},
|
|
911
|
+
)
|
|
912
|
+
return status === 200
|
|
913
|
+
? Response.json(outcome)
|
|
914
|
+
: problem(status, { code: 'grant-mismatch', title: outcome.message })
|
|
915
|
+
}
|
|
881
916
|
const switched = /^installed\/(.+)\/(disable|enable)$/.exec(what)
|
|
882
917
|
if (switched && request.method === 'POST') {
|
|
883
918
|
if (principal.ci ? !may(principal, RemotePermissions.ApplyStructure) : !principal.isAdmin)
|
|
@@ -920,7 +955,9 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
920
955
|
})
|
|
921
956
|
if (removing) {
|
|
922
957
|
const name = decodeURIComponent(what.slice('installed/'.length))
|
|
923
|
-
const outcome = await bundles.uninstall(actor, name
|
|
958
|
+
const outcome = await bundles.uninstall(actor, name, {
|
|
959
|
+
revertContent: new URL(request.url).searchParams.get('revertContent') === 'true',
|
|
960
|
+
})
|
|
924
961
|
return outcome.ok
|
|
925
962
|
? Response.json(outcome)
|
|
926
963
|
: problem(409, { code: 'uninstall-refused', title: outcome.message })
|
|
@@ -935,11 +972,12 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
935
972
|
version: typeof body.version === 'string' ? body.version : undefined,
|
|
936
973
|
applyContent: body.applyContent === true,
|
|
937
974
|
// Naming the grant is the consent: a script that names what it grants has said yes.
|
|
938
|
-
acceptServerCode: true,
|
|
939
975
|
grant,
|
|
976
|
+
actAs: typeof body.actAs === 'string' ? body.actAs : null,
|
|
977
|
+
settings: settingsIn(body.settings),
|
|
940
978
|
})
|
|
941
979
|
if (outcome.ok) return Response.json(outcome)
|
|
942
|
-
if (outcome.
|
|
980
|
+
if (outcome.needsGrant) {
|
|
943
981
|
const asked = (outcome.permissions ?? []).map((p) => p.permission)
|
|
944
982
|
const missing = asked.filter((p) => !grant.includes(p))
|
|
945
983
|
const extra = grant.filter((p) => !asked.includes(p))
|
|
@@ -956,7 +994,7 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
956
994
|
return problem(409, { code: 'install-refused', title: outcome.message })
|
|
957
995
|
}
|
|
958
996
|
|
|
959
|
-
/** Undoes an apply (story 167), as `
|
|
997
|
+
/** Undoes an apply (story 167), as `site revert` does here; files it replaced come back too. */
|
|
960
998
|
async function revertBundleRun(
|
|
961
999
|
request: Request,
|
|
962
1000
|
principal: Principal,
|
|
@@ -967,6 +1005,14 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
967
1005
|
return problem(403, { code: 'forbidden', title: 'You may not change this environment' })
|
|
968
1006
|
if (!fromThisSiteOrBearer(request)) return new Response('Forbidden', { status: 403 })
|
|
969
1007
|
const body = (await request.json().catch(() => ({}))) as { force?: unknown }
|
|
1008
|
+
// An extension's content is put back by uninstalling it (story 306).
|
|
1009
|
+
const run = await new TransferRunRepository(db).byId(runId)
|
|
1010
|
+
if (run?.bundleType === 'extension')
|
|
1011
|
+
return problem(409, {
|
|
1012
|
+
code: 'extension-run',
|
|
1013
|
+
title: "That run brought an extension's content",
|
|
1014
|
+
detail: `It is put back by uninstalling ${run.packageName ?? 'the extension'}, with its content reverted.`,
|
|
1015
|
+
})
|
|
970
1016
|
// A run that installed code changes code back, which needs what it did.
|
|
971
1017
|
if (
|
|
972
1018
|
installedCode(config, runId) &&
|
package/src/schema.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { existsSync, watch } from 'node:fs'
|
|
8
|
+
import { discoverBundles } from '@crombolo/backoffice-host/registry'
|
|
8
9
|
import {
|
|
9
10
|
CACHE_INSTRUCTION_CHANNEL,
|
|
10
11
|
type CacheInstructionKind,
|
|
@@ -108,16 +109,42 @@ export class SchemaBootError extends Error {
|
|
|
108
109
|
|
|
109
110
|
/**
|
|
110
111
|
* The components a schema may name as templates: every one of them, at any
|
|
111
|
-
* depth, keyed by the path that is its alias.
|
|
112
|
+
* depth, keyed by the path that is its alias. With the site's directory, an
|
|
113
|
+
* installed extension's too, as `<id>/<name>` (story 312): its own components
|
|
114
|
+
* are known only once it has started, so any name under its id is accepted, and
|
|
115
|
+
* one it does not offer is logged when a page renders it.
|
|
112
116
|
*/
|
|
113
|
-
export function componentAliasesIn(componentsDir: string):
|
|
114
|
-
|
|
117
|
+
export function componentAliasesIn(componentsDir: string, siteDir?: string): ReadonlySet<string> {
|
|
118
|
+
const files = new Set(listComponents(componentsDir).map((component) => component.alias))
|
|
119
|
+
if (!siteDir) return files
|
|
120
|
+
const ids = new Set(
|
|
121
|
+
discoverBundles(siteDir)
|
|
122
|
+
.bundles.filter((pkg) => pkg.bundleType === 'extension' && pkg.carries.server)
|
|
123
|
+
.map((pkg) => pkg.id),
|
|
124
|
+
)
|
|
125
|
+
return new ComponentAliases(files, ids)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** The site's component files, and any name under an installed extension's id. */
|
|
129
|
+
class ComponentAliases extends Set<string> {
|
|
130
|
+
readonly #extensions: ReadonlySet<string>
|
|
131
|
+
constructor(files: Iterable<string>, extensions: ReadonlySet<string>) {
|
|
132
|
+
super(files)
|
|
133
|
+
this.#extensions = extensions
|
|
134
|
+
}
|
|
135
|
+
override has(alias: string): boolean {
|
|
136
|
+
const slash = alias.indexOf('/')
|
|
137
|
+
return (
|
|
138
|
+
super.has(alias) ||
|
|
139
|
+
(slash > 0 && slash < alias.length - 1 && this.#extensions.has(alias.slice(0, slash)))
|
|
140
|
+
)
|
|
141
|
+
}
|
|
115
142
|
}
|
|
116
143
|
|
|
117
144
|
export function syncOptionsFor(config: CromboloConfig): SyncOptions {
|
|
118
145
|
return {
|
|
119
146
|
mode: config.development ? 'development' : 'production',
|
|
120
|
-
componentAliases: componentAliasesIn(config.componentsDir),
|
|
147
|
+
componentAliases: componentAliasesIn(config.componentsDir, config.siteDir),
|
|
121
148
|
formTypes: formTypesFor(config),
|
|
122
149
|
}
|
|
123
150
|
}
|
package/src/seed/compile.ts
CHANGED
|
@@ -581,7 +581,7 @@ export async function compileSeed(db: Db, config: CromboloConfig): Promise<SeedB
|
|
|
581
581
|
id,
|
|
582
582
|
label: 'Content files',
|
|
583
583
|
createdAt: new Date(0).toISOString(),
|
|
584
|
-
createdBy: 'crombolo
|
|
584
|
+
createdBy: 'crombolo site apply',
|
|
585
585
|
integrity: '',
|
|
586
586
|
snapshot: 'drafts',
|
|
587
587
|
provenance: {
|
|
@@ -622,15 +622,17 @@ export async function compileSeed(db: Db, config: CromboloConfig): Promise<SeedB
|
|
|
622
622
|
},
|
|
623
623
|
]
|
|
624
624
|
: [],
|
|
625
|
+
{ bundleType: 'site' },
|
|
625
626
|
)
|
|
626
627
|
const files = writeBundlePackage(payload, {
|
|
627
628
|
name: 'crombolo-site-seed',
|
|
628
629
|
version: '0.0.0',
|
|
629
630
|
id: 'site-seed',
|
|
630
631
|
label: 'Content files',
|
|
631
|
-
description: `The content files of ${config.siteName}, built by crombolo
|
|
632
|
+
description: `The content files of ${config.siteName}, built by crombolo site build`,
|
|
632
633
|
private: true,
|
|
633
634
|
peerRange: `>=${VERSION}`,
|
|
635
|
+
bundleType: 'site',
|
|
634
636
|
})
|
|
635
637
|
return { findings, set, blobs, files, counts, ...(dictionary ? { dictionary: entries } : {}) }
|
|
636
638
|
}
|
package/src/seed/export.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* `content/pages/`, Library elements to `content/library/`, and media, files and
|
|
5
5
|
* all, to `content/media/`.
|
|
6
6
|
*
|
|
7
|
-
* Values are written in the shorthand `
|
|
7
|
+
* Values are written in the shorthand `site apply` reads back — rich text as
|
|
8
8
|
* `{ html }`, pickers and links as paths to what the export carries, blocks as
|
|
9
9
|
* `{ type, key, values }` — and in their editor's stored shape where there is
|
|
10
10
|
* none. A node keeps its key in its file wherever it is not the one its path
|
package/src/seed/values.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Values in the shorthand a person writes, both ways (stories 163, 253):
|
|
3
3
|
* Markdown, paths and `{ type, alias, values }` blocks into each property
|
|
4
|
-
* editor's stored shape, as `
|
|
4
|
+
* editor's stored shape, as `site apply` reads content files and the
|
|
5
5
|
* `content` commands read `--set`; and stored values back into that shorthand,
|
|
6
|
-
* as `
|
|
6
|
+
* as `content export` and `content show` write them.
|
|
7
7
|
*/
|
|
8
8
|
import { type ContentTypeAggregate, dateFromText, normaliseUuid } from '@crombolo/core'
|
|
9
9
|
import { ContentTypeRepository, DataTypeRepository, type Db, looksLikeKey } from '@crombolo/data'
|
|
@@ -314,7 +314,7 @@ export function valueWriter(lookup: SchemaLookup, refs: ValueRefs) {
|
|
|
314
314
|
const link = typeof entry === 'string' ? { path: entry } : entry
|
|
315
315
|
if (!isRecord(link))
|
|
316
316
|
return fail('a link is a path, a URL, or { path | url, name, target }')
|
|
317
|
-
// A link as the editor stores it, as `
|
|
317
|
+
// A link as the editor stores it, as `content export` writes one.
|
|
318
318
|
if ('unique' in link || 'type' in link) {
|
|
319
319
|
links.push(link)
|
|
320
320
|
continue
|
package/src/seo.ts
CHANGED
|
@@ -175,6 +175,8 @@ export interface DraftModel {
|
|
|
175
175
|
content: PublishedContent
|
|
176
176
|
contentTypeAlias: string
|
|
177
177
|
published: boolean
|
|
178
|
+
/** The page as visitors see it now, when it is published. */
|
|
179
|
+
live?: PublishedContent
|
|
178
180
|
culture: string | null
|
|
179
181
|
}
|
|
180
182
|
|
|
@@ -412,17 +414,23 @@ export function createSeoHost(options: SeoHostOptions): SeoHost {
|
|
|
412
414
|
if (!draft) return Response.json({ message: 'That page could not be found.' }, { status: 404 })
|
|
413
415
|
const origin = publicOrigin(request, config)
|
|
414
416
|
const snapshot = await cache.snapshot()
|
|
415
|
-
const
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
417
|
+
const context = { origin, alternates: urlsIn(snapshot, key), site: await siteDefaults() }
|
|
418
|
+
const meta = await effectiveMeta(draft.content, context)
|
|
419
|
+
// Said only when what search engines see now is not this: unpublished, or changed since.
|
|
420
|
+
const live = draft.live ? await effectiveMeta(draft.live, context) : undefined
|
|
421
|
+
const differs = !draft.published
|
|
422
|
+
? 'unpublished'
|
|
423
|
+
: live && JSON.stringify(live) !== JSON.stringify(meta)
|
|
424
|
+
? 'changed'
|
|
425
|
+
: null
|
|
420
426
|
return Response.json({
|
|
421
427
|
hasSeoFields: await composesSeoFields(draft.contentTypeAlias),
|
|
422
428
|
published: draft.published,
|
|
429
|
+
differs,
|
|
423
430
|
culture: draft.culture,
|
|
424
431
|
meta,
|
|
425
432
|
snippet: {
|
|
433
|
+
name: draft.content.name,
|
|
426
434
|
title: meta.fullTitle,
|
|
427
435
|
url: meta.canonical.value ?? '',
|
|
428
436
|
description: meta.description.value ?? '',
|