@crombolo/server 0.45.0 → 0.46.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +13 -13
- package/src/adapters/media.ts +37 -43
- package/src/config.ts +1 -1
- package/src/core.ts +11 -0
- package/src/index.ts +1 -0
- package/src/marketplace.ts +82 -14
- package/src/no-nodes.ts +1 -1
- package/src/node-operations.ts +3 -0
- package/src/owner-jobs.ts +6 -0
- package/src/provenance.ts +43 -15
- package/src/seed/compile.ts +16 -287
- package/src/seed/export.ts +9 -150
- package/src/seed/index.ts +1 -0
- package/src/seed/values.ts +509 -0
- package/src/server.ts +45 -25
- package/src/webhook-edit.ts +70 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.1",
|
|
4
4
|
"description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. The crombolo HTTP server: routing, configuration, media stores and background jobs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -31,18 +31,18 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@crombolo/api-delivery": "0.
|
|
35
|
-
"@crombolo/api-management": "0.
|
|
36
|
-
"@crombolo/auth": "0.
|
|
37
|
-
"@crombolo/backoffice-host": "0.
|
|
38
|
-
"@crombolo/common": "0.
|
|
39
|
-
"@crombolo/content": "0.
|
|
40
|
-
"@crombolo/contracts": "0.
|
|
41
|
-
"@crombolo/core": "0.
|
|
42
|
-
"@crombolo/data": "0.
|
|
43
|
-
"@crombolo/render": "0.
|
|
44
|
-
"@crombolo/schema": "0.
|
|
45
|
-
"@crombolo/transfer": "0.
|
|
34
|
+
"@crombolo/api-delivery": "0.46.1",
|
|
35
|
+
"@crombolo/api-management": "0.46.1",
|
|
36
|
+
"@crombolo/auth": "0.46.1",
|
|
37
|
+
"@crombolo/backoffice-host": "0.46.1",
|
|
38
|
+
"@crombolo/common": "0.46.1",
|
|
39
|
+
"@crombolo/content": "0.46.1",
|
|
40
|
+
"@crombolo/contracts": "0.46.1",
|
|
41
|
+
"@crombolo/core": "0.46.1",
|
|
42
|
+
"@crombolo/data": "0.46.1",
|
|
43
|
+
"@crombolo/render": "0.46.1",
|
|
44
|
+
"@crombolo/schema": "0.46.1",
|
|
45
|
+
"@crombolo/transfer": "0.46.1",
|
|
46
46
|
"@logtape/logtape": "^2.3.8",
|
|
47
47
|
"@sigstore/bundle": "^3.1.0",
|
|
48
48
|
"@sigstore/core": "^2.0.0",
|
package/src/adapters/media.ts
CHANGED
|
@@ -7,7 +7,6 @@ import type { MediaPort } from '@crombolo/api-management/domain'
|
|
|
7
7
|
import {
|
|
8
8
|
type ContentTypeAggregate,
|
|
9
9
|
DEFAULT_UPLOAD_SETTINGS,
|
|
10
|
-
type DocumentAggregate,
|
|
11
10
|
IMAGE_CROPPER_EDITOR_ALIAS,
|
|
12
11
|
mediaFileOf,
|
|
13
12
|
normaliseUuid,
|
|
@@ -18,11 +17,21 @@ import {
|
|
|
18
17
|
DataTypeRepository,
|
|
19
18
|
type Db,
|
|
20
19
|
DocumentRepository,
|
|
20
|
+
MediaListingRepository,
|
|
21
|
+
type MediaSortField,
|
|
21
22
|
type NodeRow,
|
|
22
23
|
type NodeSchemaState,
|
|
23
24
|
type ValueIntake,
|
|
24
25
|
} from '@crombolo/data'
|
|
25
26
|
|
|
27
|
+
/** The folder view's `orderBy`, as the listing sorts; anything else is sort order. */
|
|
28
|
+
const COLLECTION_SORTS: Record<string, MediaSortField> = {
|
|
29
|
+
name: 'name',
|
|
30
|
+
createDate: 'createDate',
|
|
31
|
+
updateDate: 'updateDate',
|
|
32
|
+
sortOrder: 'sortOrder',
|
|
33
|
+
}
|
|
34
|
+
|
|
26
35
|
/** The Media section's reads; its writes go through the media operations (story 165). */
|
|
27
36
|
export function createMediaPort(
|
|
28
37
|
db: Db,
|
|
@@ -109,50 +118,35 @@ export function createMediaPort(
|
|
|
109
118
|
return { total: page.total, items: await tree(page.items) }
|
|
110
119
|
},
|
|
111
120
|
|
|
121
|
+
/**
|
|
122
|
+
* The folder view (story 246): counted, filtered, sorted and paged in the
|
|
123
|
+
* database, so a folder of a million files costs a page, not the folder.
|
|
124
|
+
* Only the page's items are loaded, and their creators in one query.
|
|
125
|
+
*/
|
|
112
126
|
async collection(parentKey, options) {
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
.where('key', '=', latest.userKey)
|
|
128
|
-
.execute()
|
|
129
|
-
)[0]?.user_name ?? null)
|
|
130
|
-
: null
|
|
131
|
-
loaded.push({ ...media, sortOrder: node.sortOrder, creator })
|
|
132
|
-
}
|
|
133
|
-
const keyOf = (m: (typeof loaded)[number]): string | number => {
|
|
134
|
-
const variant = m.variants[0]
|
|
135
|
-
switch (options.orderBy) {
|
|
136
|
-
case 'name':
|
|
137
|
-
return (variant?.name ?? '').toLowerCase()
|
|
138
|
-
case 'createDate':
|
|
139
|
-
return variant?.createDate.getTime() ?? 0
|
|
140
|
-
case 'updateDate':
|
|
141
|
-
return variant?.updateDate.getTime() ?? 0
|
|
142
|
-
default:
|
|
143
|
-
return m.sortOrder
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
loaded.sort((a, b) => {
|
|
147
|
-
const x = keyOf(a)
|
|
148
|
-
const y = keyOf(b)
|
|
149
|
-
const order = x < y ? -1 : x > y ? 1 : 0
|
|
150
|
-
return options.orderDirection === 'Descending' ? -order : order
|
|
127
|
+
const listing = new MediaListingRepository(db)
|
|
128
|
+
const parent = parentKey ? await listing.byKey(parentKey) : { id: -1, path: '-1' }
|
|
129
|
+
if (!parent) return { total: 0, items: [] }
|
|
130
|
+
const filter = options.filter?.trim()
|
|
131
|
+
const page = await listing.children({
|
|
132
|
+
parentId: parent.id,
|
|
133
|
+
parentPath: parent.path,
|
|
134
|
+
names: filter ? [filter] : [],
|
|
135
|
+
sort: {
|
|
136
|
+
field: COLLECTION_SORTS[options.orderBy ?? ''] ?? 'sortOrder',
|
|
137
|
+
ascending: options.orderDirection !== 'Descending',
|
|
138
|
+
},
|
|
139
|
+
skip: options.skip,
|
|
140
|
+
take: options.take,
|
|
151
141
|
})
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
142
|
+
const [loaded, creators] = await Promise.all([
|
|
143
|
+
Promise.all(page.keys.map((key) => repo.byKey(key))),
|
|
144
|
+
listing.creators(page.keys),
|
|
145
|
+
])
|
|
146
|
+
const items = loaded.flatMap((media) =>
|
|
147
|
+
media ? [{ ...media, creator: creators.get(media.key) ?? null }] : [],
|
|
148
|
+
)
|
|
149
|
+
return { total: page.total, items }
|
|
156
150
|
},
|
|
157
151
|
|
|
158
152
|
async typesForExtension(raw) {
|
package/src/config.ts
CHANGED
|
@@ -1041,7 +1041,7 @@ export function describeDatabase(
|
|
|
1041
1041
|
}
|
|
1042
1042
|
}
|
|
1043
1043
|
|
|
1044
|
-
export const VERSION = '0.
|
|
1044
|
+
export const VERSION = '0.46.1'
|
|
1045
1045
|
|
|
1046
1046
|
/** A whole number of seconds from the environment; undefined when unset or not one. */
|
|
1047
1047
|
/** A positive number from a setting, else the default. */
|
package/src/core.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { ServerEvent } from '@crombolo/api-management/domain'
|
|
8
8
|
import { createBackOfficePaths, createExtensionRegistry } from '@crombolo/backoffice-host/registry'
|
|
9
|
+
import { mediaJobHandlers } from '@crombolo/content'
|
|
9
10
|
import { ObjectTypes } from '@crombolo/core'
|
|
10
11
|
import {
|
|
11
12
|
appendCacheInstruction,
|
|
@@ -65,6 +66,7 @@ import { MediaFileStore } from './media-files.ts'
|
|
|
65
66
|
import { mediaStoreFromEnvironment } from './media-store.ts'
|
|
66
67
|
import { createNodeOperations } from './node-operations.ts'
|
|
67
68
|
import {
|
|
69
|
+
CORE_JOB_OWNER,
|
|
68
70
|
createJobRunner,
|
|
69
71
|
type JobHandler,
|
|
70
72
|
type JobOwner,
|
|
@@ -390,6 +392,7 @@ export async function createCore(config: CromboloConfig, hooks: CoreHooks) {
|
|
|
390
392
|
webhooks,
|
|
391
393
|
nudgeEvents: () => wake('events'),
|
|
392
394
|
backOfficeUrl: backOfficeUrl(config),
|
|
395
|
+
background: (queuedBy) => jobRunner.jobsFor(CORE_JOB_OWNER, queuedBy),
|
|
393
396
|
})
|
|
394
397
|
|
|
395
398
|
/**
|
|
@@ -537,6 +540,14 @@ export async function createCore(config: CromboloConfig, hooks: CoreHooks) {
|
|
|
537
540
|
const siteJobs = siteJobHandlers(config.jobs)
|
|
538
541
|
/** Every owner with jobs: the site's given its tables and `site()` as a visitor; a bundle's, its capabilities for no caller. */
|
|
539
542
|
const jobOwners = (): JobOwner[] => [
|
|
543
|
+
// Core's own queued work: a large media branch's trash, move or delete (story 246).
|
|
544
|
+
{
|
|
545
|
+
id: CORE_JOB_OWNER,
|
|
546
|
+
handlers: mediaJobHandlers(operations.media) as Map<string, JobHandler>,
|
|
547
|
+
schedules: [],
|
|
548
|
+
context: () => ({}),
|
|
549
|
+
on: () => true,
|
|
550
|
+
},
|
|
540
551
|
...(siteJobs.size > 0
|
|
541
552
|
? [
|
|
542
553
|
{
|
package/src/index.ts
CHANGED
|
@@ -121,6 +121,7 @@ export * from './udt.ts'
|
|
|
121
121
|
export * from './upgrade-summary.ts'
|
|
122
122
|
export * from './url-settings.ts'
|
|
123
123
|
export * from './view-runtime.ts'
|
|
124
|
+
export * from './webhook-edit.ts'
|
|
124
125
|
export * from './webhook-files.ts'
|
|
125
126
|
export * from './webhooks.ts'
|
|
126
127
|
export * from './worker.ts'
|
package/src/marketplace.ts
CHANGED
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
* browser cannot reach npm, and the backoffice keeps making same-origin
|
|
18
18
|
* requests only.
|
|
19
19
|
*/
|
|
20
|
-
import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs'
|
|
20
|
+
import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync } from 'node:fs'
|
|
21
21
|
import { tmpdir } from 'node:os'
|
|
22
|
-
import { join } from 'node:path'
|
|
22
|
+
import { join, resolve } from 'node:path'
|
|
23
23
|
import {
|
|
24
24
|
type BundlePackage,
|
|
25
25
|
describePermissions,
|
|
@@ -28,6 +28,12 @@ import {
|
|
|
28
28
|
type PackageJson,
|
|
29
29
|
validateBundlePackage,
|
|
30
30
|
} from '@crombolo/backoffice-host'
|
|
31
|
+
import {
|
|
32
|
+
LOCAL_BUNDLES_DIR,
|
|
33
|
+
localBundleFileName,
|
|
34
|
+
localBundlePath,
|
|
35
|
+
localBundlesNamed,
|
|
36
|
+
} from '@crombolo/transfer'
|
|
31
37
|
import { type BundleGrants, declaredPermissions } from './bundle-grants.ts'
|
|
32
38
|
import { logger } from './logging.ts'
|
|
33
39
|
import {
|
|
@@ -157,6 +163,8 @@ export interface InstallOutcome {
|
|
|
157
163
|
restartPending?: boolean
|
|
158
164
|
/** Where the version checked was built, from its signature (story 060). */
|
|
159
165
|
provenance?: ProvenanceResult
|
|
166
|
+
/** The file an install from a file keeps in the site, to commit: `bundles/acme-crm-1.2.0.tgz` (story 245). */
|
|
167
|
+
file?: string
|
|
160
168
|
}
|
|
161
169
|
|
|
162
170
|
export type PackageInstaller = (
|
|
@@ -296,6 +304,36 @@ export function createMarketplace(options: MarketplaceOptions): Marketplace {
|
|
|
296
304
|
}
|
|
297
305
|
let cached: { at: number; query: string; listings: MarketplaceListing[] } | undefined
|
|
298
306
|
|
|
307
|
+
/**
|
|
308
|
+
* A bundle's file at `bundles/<name>-<version>.tgz`: used in place when it is
|
|
309
|
+
* there already, copied there otherwise. Another file under that name is
|
|
310
|
+
* refused, since one version is one file.
|
|
311
|
+
*/
|
|
312
|
+
const keepInSite = (
|
|
313
|
+
file: string,
|
|
314
|
+
declared: { name: string; version: string },
|
|
315
|
+
): { path: string; copied: boolean } | string => {
|
|
316
|
+
const path = `${LOCAL_BUNDLES_DIR}/${localBundleFileName(declared.name, declared.version)}`
|
|
317
|
+
const target = join(options.siteDir, path)
|
|
318
|
+
if (resolve(file) === resolve(target)) return { path, copied: false }
|
|
319
|
+
const bytes = readFileSync(file)
|
|
320
|
+
if (existsSync(target)) {
|
|
321
|
+
if (readFileSync(target).equals(bytes)) return { path, copied: false }
|
|
322
|
+
return `${path} already holds a different ${declared.name}@${declared.version} than ${file}, so it was not installed: one version is one file. Remove ${path} first if ${file} is the one to keep.`
|
|
323
|
+
}
|
|
324
|
+
mkdirSync(join(options.siteDir, LOCAL_BUNDLES_DIR), { recursive: true })
|
|
325
|
+
copyFileSync(file, target)
|
|
326
|
+
return { path, copied: true }
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** The `bundles/` file a dependency used to name, removed once nothing names it. */
|
|
330
|
+
const removeUnnamed = (previousRange: string | undefined, keep?: string) => {
|
|
331
|
+
const path = localBundlePath(previousRange)
|
|
332
|
+
if (!path || path === keep) return
|
|
333
|
+
if (localBundlesNamed(options.siteDir).includes(path)) return
|
|
334
|
+
rmSync(join(options.siteDir, path), { force: true })
|
|
335
|
+
}
|
|
336
|
+
|
|
299
337
|
const installedVersion = (name: string): string | null =>
|
|
300
338
|
options.extensions.bundles().bundles.find((bundle) => bundle.packageName === name)?.version ??
|
|
301
339
|
null
|
|
@@ -370,7 +408,7 @@ export function createMarketplace(options: MarketplaceOptions): Marketplace {
|
|
|
370
408
|
const response = await call(dist.tarball)
|
|
371
409
|
if (!response.ok)
|
|
372
410
|
return {
|
|
373
|
-
state: '
|
|
411
|
+
state: 'unchecked',
|
|
374
412
|
reason: `${name} could not be fetched to check its signature (the registry answered ${response.status})`,
|
|
375
413
|
}
|
|
376
414
|
const bytes = new Uint8Array(await response.arrayBuffer())
|
|
@@ -386,7 +424,7 @@ export function createMarketplace(options: MarketplaceOptions): Marketplace {
|
|
|
386
424
|
return await verify(unpacked)
|
|
387
425
|
} catch (error) {
|
|
388
426
|
return {
|
|
389
|
-
state: '
|
|
427
|
+
state: 'unchecked',
|
|
390
428
|
reason: `${name} could not be checked: ${error instanceof Error ? error.message : String(error)}`,
|
|
391
429
|
}
|
|
392
430
|
} finally {
|
|
@@ -417,12 +455,15 @@ export function createMarketplace(options: MarketplaceOptions): Marketplace {
|
|
|
417
455
|
let found = installedProvenance.get(key)
|
|
418
456
|
if (!found) {
|
|
419
457
|
found = verify(bundle.directory).catch((error: unknown) => ({
|
|
420
|
-
state: '
|
|
458
|
+
state: 'unchecked' as const,
|
|
421
459
|
reason: error instanceof Error ? error.message : String(error),
|
|
422
460
|
}))
|
|
423
461
|
installedProvenance.set(key, found)
|
|
424
462
|
}
|
|
425
|
-
|
|
463
|
+
const result = await found
|
|
464
|
+
// Not kept: the next look may be able to check it.
|
|
465
|
+
if (result.state === 'unchecked') installedProvenance.delete(key)
|
|
466
|
+
return result
|
|
426
467
|
}
|
|
427
468
|
|
|
428
469
|
/** What the registry says this package's latest version carries, when it is a valid bundle. */
|
|
@@ -592,21 +633,47 @@ export function createMarketplace(options: MarketplaceOptions): Marketplace {
|
|
|
592
633
|
if (typeof declared === 'string') return { ok: false, message: declared }
|
|
593
634
|
if (declared.server && !consented(request, declared.permissions))
|
|
594
635
|
return serverConsentNeeded(declared.name, declared.permissions)
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
}
|
|
636
|
+
// Kept in the site's bundles/ (story 245), so it is committed and every
|
|
637
|
+
// node, checkout and CI build installs the same file.
|
|
638
|
+
const kept = keepInSite(file, declared)
|
|
639
|
+
if (typeof kept === 'string') return { ok: false, message: kept }
|
|
640
|
+
const discard = () => {
|
|
641
|
+
if (kept.copied) rmSync(join(options.siteDir, kept.path), { force: true })
|
|
642
|
+
}
|
|
643
|
+
const provenance = await verifyPackage(join(options.siteDir, kept.path)).catch(
|
|
644
|
+
(error: unknown) => ({
|
|
645
|
+
state: 'unchecked' as const,
|
|
646
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
647
|
+
}),
|
|
648
|
+
)
|
|
599
649
|
const refused = refusedBySignature(declared.name, provenance)
|
|
600
|
-
if (refused)
|
|
601
|
-
|
|
650
|
+
if (refused) {
|
|
651
|
+
discard()
|
|
652
|
+
return refused
|
|
653
|
+
}
|
|
654
|
+
const previous = await rangeFor(declared.name)
|
|
655
|
+
const outcome = await added(declared.name, `./${kept.path}`, undefined, request)
|
|
656
|
+
if (!outcome.ok) {
|
|
657
|
+
discard()
|
|
658
|
+
return { ...outcome, provenance }
|
|
659
|
+
}
|
|
660
|
+
removeUnnamed(previous, kept.path)
|
|
661
|
+
return {
|
|
662
|
+
...outcome,
|
|
663
|
+
provenance,
|
|
664
|
+
file: kept.path,
|
|
665
|
+
message: `${outcome.message} Commit ${kept.path} with package.json and bun.lock.`,
|
|
666
|
+
}
|
|
602
667
|
},
|
|
603
668
|
|
|
604
669
|
async uninstall(name) {
|
|
605
670
|
if (options.installs === false) return refusedHere(name, 'remove', options.installsElsewhere)
|
|
606
671
|
if (!isValidPackageName(name))
|
|
607
672
|
return { ok: false, message: `'${name}' is not a package name npm would accept.` }
|
|
673
|
+
const previous = await rangeFor(name)
|
|
608
674
|
const result = await install('remove', name, options.siteDir)
|
|
609
675
|
options.extensions.invalidate()
|
|
676
|
+
if (result.ok) removeUnnamed(previous)
|
|
610
677
|
return result.ok
|
|
611
678
|
? {
|
|
612
679
|
ok: true,
|
|
@@ -704,18 +771,19 @@ export function createMarketplace(options: MarketplaceOptions): Marketplace {
|
|
|
704
771
|
/** What a packed bundle on this machine declares, read from its package.json, or why it cannot be installed. */
|
|
705
772
|
async function declaresIn(
|
|
706
773
|
file: string,
|
|
707
|
-
): Promise<{ name: string; server: boolean; permissions: string[] } | string> {
|
|
774
|
+
): Promise<{ name: string; version: string; server: boolean; permissions: string[] } | string> {
|
|
708
775
|
const dir = mkdtempSync(join(tmpdir(), 'crombolo-bundle-file-'))
|
|
709
776
|
try {
|
|
710
777
|
await extractTarball(file, dir)
|
|
711
778
|
const root = existsSync(join(dir, 'package', 'package.json')) ? join(dir, 'package') : dir
|
|
712
779
|
const json = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')) as PackageJson
|
|
713
780
|
const problems = validateBundlePackage(json)
|
|
714
|
-
if (problems.length > 0 || typeof json.name !== 'string')
|
|
781
|
+
if (problems.length > 0 || typeof json.name !== 'string' || typeof json.version !== 'string')
|
|
715
782
|
return `${file} is not a bundle for this site, so it was not installed.`
|
|
716
783
|
const field = json.crombolo as { server?: string; permissions?: string[] }
|
|
717
784
|
return {
|
|
718
785
|
name: json.name,
|
|
786
|
+
version: json.version,
|
|
719
787
|
server: field.server !== undefined,
|
|
720
788
|
permissions: Array.isArray(field.permissions) ? field.permissions : [],
|
|
721
789
|
}
|
package/src/no-nodes.ts
CHANGED
|
@@ -138,7 +138,7 @@ export function noNodesPage(options: { siteName: string; backOfficePath: string
|
|
|
138
138
|
<h2>Configure page metadata</h2>
|
|
139
139
|
<p>A content type says what a kind of page holds: a title, a summary, a body. Add one in the back office under <strong>Settings → Structure</strong>, or from the command line:</p>
|
|
140
140
|
<pre><code>bunx crombolo types new content-type article --at-root
|
|
141
|
-
bunx crombolo types
|
|
141
|
+
bunx crombolo types property add article summary --type textarea</code></pre>
|
|
142
142
|
<p>Either way it is saved as a file, <code>schema/content-types/article.toml</code>, so it travels with your code.</p>
|
|
143
143
|
</li>
|
|
144
144
|
<li>
|
package/src/node-operations.ts
CHANGED
|
@@ -55,6 +55,8 @@ export interface NodeOperationsOptions {
|
|
|
55
55
|
webhooks?: WebhookService
|
|
56
56
|
nudgeEvents?: () => void
|
|
57
57
|
backOfficeUrl?: string
|
|
58
|
+
/** Where a large media branch's write is queued (story 246); made in the request when absent. */
|
|
59
|
+
background?: (queuedBy: string) => { enqueue(name: string, payload: unknown): Promise<string> }
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
export function createNodeOperations(options: NodeOperationsOptions): NodeOperations {
|
|
@@ -117,6 +119,7 @@ export function createNodeOperations(options: NodeOperationsOptions): NodeOperat
|
|
|
117
119
|
// Only the items it touched: a media change leaves the pages alone (story 197).
|
|
118
120
|
onChange: (change) => cache?.media?.apply(change),
|
|
119
121
|
refusalReason,
|
|
122
|
+
background: options.background,
|
|
120
123
|
})
|
|
121
124
|
return { valueIntake: repository.valueIntake, tracker, approvals, documents, media }
|
|
122
125
|
}
|
package/src/owner-jobs.ts
CHANGED
|
@@ -15,6 +15,12 @@ import {
|
|
|
15
15
|
import { type Cron, isTimezone, nextOccurrence, parseCron } from './cron.ts'
|
|
16
16
|
import { logger } from './logging.ts'
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Core's own queued work (story 246). A bundle's id is letters, digits and
|
|
20
|
+
* hyphens, so this can never be one.
|
|
21
|
+
*/
|
|
22
|
+
export const CORE_JOB_OWNER = 'crombolo:core'
|
|
23
|
+
|
|
18
24
|
/** The largest payload a job may carry, as JSON. */
|
|
19
25
|
export const MAX_PAYLOAD_BYTES = 64 * 1024
|
|
20
26
|
/** How many times a job runs before it is failed for good, unless it says otherwise. */
|
package/src/provenance.ts
CHANGED
|
@@ -76,7 +76,11 @@ export interface ProvenanceFile {
|
|
|
76
76
|
links: ProvenanceLinks
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
/**
|
|
80
|
+
* `unchecked`: Sigstore's trusted root could not be had, so the signature was not
|
|
81
|
+
* checked either way (story 244). Refused like `invalid`, and worth trying again.
|
|
82
|
+
*/
|
|
83
|
+
export type ProvenanceState = 'signed' | 'unsigned' | 'invalid' | 'unchecked' | 'local'
|
|
80
84
|
|
|
81
85
|
export interface ProvenanceResult {
|
|
82
86
|
state: ProvenanceState
|
|
@@ -194,6 +198,8 @@ export function describeProvenance(result: ProvenanceResult): string {
|
|
|
194
198
|
return 'Local: from this machine, not a registry'
|
|
195
199
|
case 'invalid':
|
|
196
200
|
return `Signature not accepted: ${result.reason ?? 'it does not check out'}`
|
|
201
|
+
case 'unchecked':
|
|
202
|
+
return `Couldn't be checked right now: ${result.reason ?? 'try again'}`
|
|
197
203
|
}
|
|
198
204
|
}
|
|
199
205
|
|
|
@@ -260,12 +266,20 @@ export async function signPackage(dir: string, options: SignOptions = {}): Promi
|
|
|
260
266
|
export interface VerifyProvenanceOptions {
|
|
261
267
|
/** Sigstore's trusted root as JSON; the public one, refreshed through TUF, by default. */
|
|
262
268
|
trustedRoot?: unknown
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Checks the Sigstore bundle itself, throwing when it does not verify. Only a
|
|
273
|
+
* test passes one, through `verifyProvenanceWith`: a signature in this format is
|
|
274
|
+
* made in GitHub Actions, never offline.
|
|
275
|
+
*/
|
|
276
|
+
export type SignatureCheck = (signature: SerializedBundle) => void | Promise<void>
|
|
277
|
+
|
|
278
|
+
/** What a test replaces in `verifyProvenanceWith`; nothing a host is offered. */
|
|
279
|
+
export interface ProvenanceSeams {
|
|
280
|
+
verifySignature?: SignatureCheck
|
|
281
|
+
/** Stands in for fetching Sigstore's public trusted root. */
|
|
282
|
+
publicRoot?: () => Promise<TrustedRoot>
|
|
269
283
|
}
|
|
270
284
|
|
|
271
285
|
let publicRoot: { at: number; root: Promise<TrustedRoot> } | undefined
|
|
@@ -300,11 +314,21 @@ const invalid = (reason: string, digest?: string): ProvenanceResult => ({
|
|
|
300
314
|
* Checks a package directory's signature: its digest, Sigstore's signature and
|
|
301
315
|
* certificate against the trusted root, that GitHub Actions signed it, and that
|
|
302
316
|
* `provenance.json` claims what the certificate says. Unsigned when there is no
|
|
303
|
-
* `provenance.json`; invalid, with the reason, when anything disagrees
|
|
317
|
+
* `provenance.json`; invalid, with the reason, when anything disagrees;
|
|
318
|
+
* unchecked when the trusted root could not be fetched and none is cached.
|
|
304
319
|
*/
|
|
305
|
-
export
|
|
320
|
+
export function verifyProvenance(
|
|
306
321
|
dir: string,
|
|
307
322
|
options: VerifyProvenanceOptions = {},
|
|
323
|
+
): Promise<ProvenanceResult> {
|
|
324
|
+
return verifyProvenanceWith(dir, options)
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/** `verifyProvenance`, with Sigstore's steps replaced: for tests only. */
|
|
328
|
+
export async function verifyProvenanceWith(
|
|
329
|
+
dir: string,
|
|
330
|
+
options: VerifyProvenanceOptions,
|
|
331
|
+
seams: ProvenanceSeams = {},
|
|
308
332
|
): Promise<ProvenanceResult> {
|
|
309
333
|
const file = join(dir, PROVENANCE_FILE)
|
|
310
334
|
if (!existsSync(file)) return { state: 'unsigned' }
|
|
@@ -320,19 +344,20 @@ export async function verifyProvenance(
|
|
|
320
344
|
if (provenance.digest !== digest)
|
|
321
345
|
return invalid('the bundle has changed since it was signed', digest)
|
|
322
346
|
|
|
323
|
-
let check =
|
|
347
|
+
let check = seams.verifySignature
|
|
324
348
|
if (!check) {
|
|
325
349
|
let root: TrustedRoot
|
|
326
350
|
try {
|
|
327
351
|
root =
|
|
328
352
|
options.trustedRoot !== undefined
|
|
329
353
|
? TrustedRoot.fromJSON(options.trustedRoot)
|
|
330
|
-
: await publicTrustedRoot()
|
|
354
|
+
: await (seams.publicRoot ?? publicTrustedRoot)()
|
|
331
355
|
} catch (error) {
|
|
332
|
-
return
|
|
333
|
-
|
|
356
|
+
return {
|
|
357
|
+
state: 'unchecked',
|
|
358
|
+
reason: `Sigstore's trusted root could not be fetched: ${error instanceof Error ? error.message : String(error)}`,
|
|
334
359
|
digest,
|
|
335
|
-
|
|
360
|
+
}
|
|
336
361
|
}
|
|
337
362
|
check = (signature) => {
|
|
338
363
|
new Verifier(toTrustMaterial(root)).verify(toSignedEntity(bundleFromJSON(signature)), {
|
|
@@ -398,7 +423,8 @@ export function sourceAllowed(source: ProvenanceSource, entry: string): boolean
|
|
|
398
423
|
|
|
399
424
|
/**
|
|
400
425
|
* Why the site will not take this bundle, or undefined when it will. An
|
|
401
|
-
* invalid signature is refused whatever the policy; `local` is the
|
|
426
|
+
* invalid or unchecked signature is refused whatever the policy; `local` is the
|
|
427
|
+
* site's own.
|
|
402
428
|
*/
|
|
403
429
|
export function provenanceProblem(
|
|
404
430
|
result: ProvenanceResult,
|
|
@@ -406,6 +432,8 @@ export function provenanceProblem(
|
|
|
406
432
|
): string | undefined {
|
|
407
433
|
if (result.state === 'invalid')
|
|
408
434
|
return `its signature was not accepted: ${result.reason ?? 'it does not check out'}`
|
|
435
|
+
if (result.state === 'unchecked')
|
|
436
|
+
return `its signature could not be checked right now (${result.reason ?? 'try again'}); try again`
|
|
409
437
|
if (result.state === 'local') return undefined
|
|
410
438
|
if (result.state === 'unsigned')
|
|
411
439
|
return policy.signatures === 'required'
|