@crombolo/server 0.44.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 +20 -14
- package/src/adapters/health.ts +48 -0
- package/src/adapters/media.ts +37 -43
- package/src/bundle-admin.ts +235 -0
- package/src/bundle-build.ts +6 -2
- package/src/bundle-code-install.ts +168 -0
- package/src/bundle-install.ts +80 -2
- package/src/config.ts +20 -1
- package/src/core.ts +11 -0
- package/src/index.ts +4 -0
- package/src/marketplace.ts +342 -62
- 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 +494 -0
- package/src/remote.ts +223 -6
- package/src/restart-pending.ts +52 -0
- 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 +101 -88
- package/src/settings.ts +16 -0
- package/src/webhook-edit.ts +70 -0
package/src/bundle-install.ts
CHANGED
|
@@ -57,6 +57,14 @@ import {
|
|
|
57
57
|
writeResolutions,
|
|
58
58
|
} from '@crombolo/transfer'
|
|
59
59
|
import { type BackupResult, backupBefore } from './backup.ts'
|
|
60
|
+
import {
|
|
61
|
+
type CodeInstall,
|
|
62
|
+
type CodeRevert,
|
|
63
|
+
codeChanges,
|
|
64
|
+
installCode,
|
|
65
|
+
planCode,
|
|
66
|
+
revertCode,
|
|
67
|
+
} from './bundle-code-install.ts'
|
|
60
68
|
import {
|
|
61
69
|
type CarriedSections,
|
|
62
70
|
carriedSections,
|
|
@@ -82,6 +90,7 @@ import { type CromboloConfig, VERSION } from './config.ts'
|
|
|
82
90
|
import { dictionaryToUdt, importDictionaryUdt, writeDictionaryUdt } from './dictionary-transfer.ts'
|
|
83
91
|
import { syncDomainsFile } from './domains.ts'
|
|
84
92
|
import { mediaStoreFor, placeBlobs } from './media-files.ts'
|
|
93
|
+
import { type ProvenanceResult, provenanceProblem, verifyProvenance } from './provenance.ts'
|
|
85
94
|
import { componentAliasesIn, syncSchemaDirectory } from './schema.ts'
|
|
86
95
|
import { publishSchema } from './schema-store.ts'
|
|
87
96
|
import { applySiteData, type SiteDataApplied } from './site-data.ts'
|
|
@@ -282,6 +291,25 @@ export interface TransferInput extends SectionOptions {
|
|
|
282
291
|
passphrase?: string
|
|
283
292
|
/** Leave the file's members, users and their groups out: this site's own are untouched. */
|
|
284
293
|
excludePeople?: boolean
|
|
294
|
+
/**
|
|
295
|
+
* Install the code the bundle carries here (story 241); left alone unless
|
|
296
|
+
* asked, as story 192 had it. Only where runtime installs are on.
|
|
297
|
+
*/
|
|
298
|
+
installCode?: boolean
|
|
299
|
+
/**
|
|
300
|
+
* `local`: the site's own content files, built here, which no one else
|
|
301
|
+
* signed and the site's policy never refuses (story 060).
|
|
302
|
+
*/
|
|
303
|
+
provenance?: 'local'
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** Where the bundle was built, checked before anything is read further (story 060). */
|
|
307
|
+
async function bundleProvenance(
|
|
308
|
+
bundle: ResolvedBundle,
|
|
309
|
+
input: Pick<TransferInput, 'provenance'>,
|
|
310
|
+
): Promise<ProvenanceResult> {
|
|
311
|
+
if (input.provenance === 'local') return { state: 'local' }
|
|
312
|
+
return verifyProvenance(bundle.directory)
|
|
285
313
|
}
|
|
286
314
|
|
|
287
315
|
/**
|
|
@@ -340,6 +368,10 @@ export interface ContentCheckResult {
|
|
|
340
368
|
check: TransferCheck
|
|
341
369
|
/** What the carried sections would do here; undefined for a content-only bundle. */
|
|
342
370
|
sections: SectionPlan | undefined
|
|
371
|
+
/** The code files installing it would change here; empty when it carries none, or the same. */
|
|
372
|
+
code: SectionFile[]
|
|
373
|
+
/** Where it was built, from its signature (story 060). */
|
|
374
|
+
provenance: ProvenanceResult
|
|
343
375
|
/** Nothing outstanding: the bundle would import cleanly. */
|
|
344
376
|
clean: boolean
|
|
345
377
|
/** With `publish`: the pages the import would not publish, and the reason publish gives. */
|
|
@@ -358,6 +390,9 @@ export async function checkBundleContent(
|
|
|
358
390
|
const bundle = readBundle(input.bundle, config.siteDir, input.passphrase, {
|
|
359
391
|
withoutPeople: input.excludePeople,
|
|
360
392
|
})
|
|
393
|
+
const provenance = await bundleProvenance(bundle, input)
|
|
394
|
+
const refused = provenanceProblem(provenance, config.bundlePolicy)
|
|
395
|
+
if (refused) throw new CommandError(`This bundle is refused: ${refused}.`)
|
|
361
396
|
const set = bundle.set
|
|
362
397
|
const prepared = await transferOptions(db, config, bundle, input)
|
|
363
398
|
const check = await checkBundle(db, set, prepared.options)
|
|
@@ -391,6 +426,8 @@ export async function checkBundleContent(
|
|
|
391
426
|
sections: carriesSections(bundle.carried)
|
|
392
427
|
? await planSections(db, config, bundle.carried, input)
|
|
393
428
|
: undefined,
|
|
429
|
+
code: codeChanges(planCode(config, bundle.carried)),
|
|
430
|
+
provenance,
|
|
394
431
|
clean: check.outstanding.length === 0,
|
|
395
432
|
publishRefusals: refusals,
|
|
396
433
|
decisions: {
|
|
@@ -436,6 +473,10 @@ export interface ContentImportResult {
|
|
|
436
473
|
problems: string[]
|
|
437
474
|
/** What the file's site data did here, when it carried any (story 189). */
|
|
438
475
|
siteData?: SiteDataApplied
|
|
476
|
+
/** The code it installed, when asked to and it changed any: live after a restart. */
|
|
477
|
+
code?: CodeInstall
|
|
478
|
+
/** Where it was built, from its signature (story 060); absent when refused before it was read. */
|
|
479
|
+
provenance?: ProvenanceResult
|
|
439
480
|
}
|
|
440
481
|
|
|
441
482
|
/**
|
|
@@ -536,6 +577,10 @@ export async function installBundleContent(
|
|
|
536
577
|
})
|
|
537
578
|
|
|
538
579
|
// What has to be true before anything is backed up or written.
|
|
580
|
+
const provenance = await bundleProvenance(bundle, input)
|
|
581
|
+
const signatureRefused = provenanceProblem(provenance, config.bundlePolicy)
|
|
582
|
+
if (signatureRefused)
|
|
583
|
+
return { ...refuse([`this bundle is refused: ${signatureRefused}`]), provenance }
|
|
539
584
|
if (replace && manifest.scope !== 'site')
|
|
540
585
|
return refuse(['only a whole-site file (crombolo export --site) can replace a site'])
|
|
541
586
|
const missing = requiresProblems(manifest, config.siteDir)
|
|
@@ -600,7 +645,20 @@ export async function installBundleContent(
|
|
|
600
645
|
],
|
|
601
646
|
backup,
|
|
602
647
|
)
|
|
603
|
-
|
|
648
|
+
// The code half (story 241): only when asked, only where installs happen here.
|
|
649
|
+
const code = effective.installCode ? codeChanges(planCode(config, carried)) : []
|
|
650
|
+
if (code.length > 0 && !config.runtimeInstalls)
|
|
651
|
+
return refuse(
|
|
652
|
+
[
|
|
653
|
+
config.installsElsewhere?.message ??
|
|
654
|
+
"this site does not install code while it runs: add the bundle's code to the site and deploy it",
|
|
655
|
+
],
|
|
656
|
+
backup,
|
|
657
|
+
)
|
|
658
|
+
const needingPermission = [
|
|
659
|
+
...(plan ? replacementsNeedingPermission(plan, effective) : []),
|
|
660
|
+
...(effective.replaceFiles ? [] : code.filter((file) => file.action === 'overwrite')),
|
|
661
|
+
]
|
|
604
662
|
if (needingPermission.length > 0)
|
|
605
663
|
return refuse(
|
|
606
664
|
[
|
|
@@ -701,6 +759,15 @@ export async function installBundleContent(
|
|
|
701
759
|
await publishSchema(config.schemaStore, config.schemaDir)
|
|
702
760
|
}
|
|
703
761
|
const kept = promoteStaged(config, runDir, runId)
|
|
762
|
+
const codeInstalled =
|
|
763
|
+
code.length > 0
|
|
764
|
+
? await installCode(
|
|
765
|
+
config,
|
|
766
|
+
carried,
|
|
767
|
+
kept,
|
|
768
|
+
`${bundle.package.packageName}@${bundle.package.version}`,
|
|
769
|
+
)
|
|
770
|
+
: undefined
|
|
704
771
|
// On the owners' own connections, so after crombolo's transaction rather than
|
|
705
772
|
// in it: each owner is replaced in a transaction of its own.
|
|
706
773
|
const siteData = set.siteData ? await applySiteData(db, config, set.siteData) : undefined
|
|
@@ -727,8 +794,11 @@ export async function installBundleContent(
|
|
|
727
794
|
problems: [
|
|
728
795
|
...prepared.problems,
|
|
729
796
|
...(siteData?.failed ?? []).map((failure) => `site data not written for ${failure}`),
|
|
797
|
+
...(codeInstalled?.problems ?? []).map((problem) => `its code: ${problem}`),
|
|
730
798
|
],
|
|
731
799
|
...(siteData ? { siteData } : {}),
|
|
800
|
+
...(codeInstalled ? { code: codeInstalled } : {}),
|
|
801
|
+
provenance,
|
|
732
802
|
sections: staged
|
|
733
803
|
? {
|
|
734
804
|
written: staged.written,
|
|
@@ -746,6 +816,8 @@ export interface RevertedSections extends RestoredFiles {
|
|
|
746
816
|
schema: string | undefined
|
|
747
817
|
/** Whether the dictionary was put back as the run found it. */
|
|
748
818
|
dictionary: boolean
|
|
819
|
+
/** The code the run installed, put back: live after a restart. */
|
|
820
|
+
code?: CodeRevert
|
|
749
821
|
}
|
|
750
822
|
|
|
751
823
|
/**
|
|
@@ -780,5 +852,11 @@ export async function revertSections(
|
|
|
780
852
|
for (const root of await repo.children(null)) await repo.delete(root.key)
|
|
781
853
|
await importDictionaryUdt(tx, kept)
|
|
782
854
|
})
|
|
783
|
-
|
|
855
|
+
const code = await revertCode(config, runId)
|
|
856
|
+
return {
|
|
857
|
+
...files,
|
|
858
|
+
schema,
|
|
859
|
+
dictionary: kept !== undefined,
|
|
860
|
+
...(code.restored.length + code.removed.length > 0 ? { code } : {}),
|
|
861
|
+
}
|
|
784
862
|
}
|
package/src/config.ts
CHANGED
|
@@ -23,6 +23,7 @@ import { checkHost, type HostConfig } from './host-token.ts'
|
|
|
23
23
|
import { checkIdentityProviders, type IdentityProvider } from './identity-providers.ts'
|
|
24
24
|
import type { MediaStore } from './media-store.ts'
|
|
25
25
|
import type { JobSchedule } from './owner-jobs.ts'
|
|
26
|
+
import type { ProvenancePolicy, SignaturePolicy } from './provenance.ts'
|
|
26
27
|
import type { SchemaStore } from './schema-store.ts'
|
|
27
28
|
import { setting } from './settings.ts'
|
|
28
29
|
import type { SiteDatabaseConfig, SiteQueryModules } from './site-queries.ts'
|
|
@@ -516,6 +517,11 @@ export interface CromboloConfig {
|
|
|
516
517
|
* and `CROMBOLO_INSTALLS_ELSEWHERE_URL`.
|
|
517
518
|
*/
|
|
518
519
|
installsElsewhere?: { message: string; url?: string }
|
|
520
|
+
/**
|
|
521
|
+
* What this site takes of a bundle's signature (story 060):
|
|
522
|
+
* `CROMBOLO_BUNDLE_SIGNATURES` and `CROMBOLO_BUNDLE_SOURCES`.
|
|
523
|
+
*/
|
|
524
|
+
bundlePolicy: ProvenancePolicy
|
|
519
525
|
/**
|
|
520
526
|
* Where the Packages section's Marketplace sends someone browsing for
|
|
521
527
|
* extensions. Never framed — npm refuses to be framed — so the native view
|
|
@@ -604,6 +610,12 @@ function roleFromEnvironment(value: string | undefined): ServerRole {
|
|
|
604
610
|
return value
|
|
605
611
|
}
|
|
606
612
|
|
|
613
|
+
function bundleSignatures(value: string | undefined): SignaturePolicy {
|
|
614
|
+
if (value === undefined || value === '' || value === 'optional') return 'optional'
|
|
615
|
+
if (value === 'required') return 'required'
|
|
616
|
+
throw new Error(`CROMBOLO_BUNDLE_SIGNATURES must be optional or required, not '${value}'.`)
|
|
617
|
+
}
|
|
618
|
+
|
|
607
619
|
function jobsFromEnvironment(value: string | undefined): boolean {
|
|
608
620
|
if (value === undefined || value === '' || value === 'on') return true
|
|
609
621
|
if (value === 'off') return false
|
|
@@ -846,6 +858,13 @@ export function loadConfig(
|
|
|
846
858
|
applyBundleContentOnInstall: setting('CROMBOLO_APPLY_BUNDLE_CONTENT') !== 'false',
|
|
847
859
|
// Resolved again below, once it is known whether a store was configured.
|
|
848
860
|
runtimeInstalls: setting('CROMBOLO_RUNTIME_INSTALLS') !== 'false',
|
|
861
|
+
bundlePolicy: {
|
|
862
|
+
signatures: bundleSignatures(setting('CROMBOLO_BUNDLE_SIGNATURES')),
|
|
863
|
+
sources: (setting('CROMBOLO_BUNDLE_SOURCES') ?? '')
|
|
864
|
+
.split(',')
|
|
865
|
+
.map((source) => source.trim())
|
|
866
|
+
.filter(Boolean),
|
|
867
|
+
},
|
|
849
868
|
// Resolved again below, once it is known whether this is development.
|
|
850
869
|
errors: { showDetails: envFlag(setting('CROMBOLO_SHOW_ERROR_DETAILS')) ?? false },
|
|
851
870
|
liveReload: envFlag(setting('CROMBOLO_LIVE_RELOAD')) ?? false,
|
|
@@ -1022,7 +1041,7 @@ export function describeDatabase(
|
|
|
1022
1041
|
}
|
|
1023
1042
|
}
|
|
1024
1043
|
|
|
1025
|
-
export const VERSION = '0.
|
|
1044
|
+
export const VERSION = '0.46.1'
|
|
1026
1045
|
|
|
1027
1046
|
/** A whole number of seconds from the environment; undefined when unset or not one. */
|
|
1028
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
|
@@ -19,6 +19,7 @@ export * from './api-client.ts'
|
|
|
19
19
|
export * from './atomic-write.ts'
|
|
20
20
|
export * from './backup.ts'
|
|
21
21
|
export * from './boot-failure.ts'
|
|
22
|
+
export * from './bundle-admin.ts'
|
|
22
23
|
export * from './bundle-build.ts'
|
|
23
24
|
export * from './bundle-code.ts'
|
|
24
25
|
export * from './bundle-grants.ts'
|
|
@@ -87,12 +88,14 @@ export * from './no-nodes.ts'
|
|
|
87
88
|
export * from './oembed.ts'
|
|
88
89
|
export * from './owner-jobs.ts'
|
|
89
90
|
export * from './ports.ts'
|
|
91
|
+
export * from './provenance.ts'
|
|
90
92
|
export * from './rate-limit.ts'
|
|
91
93
|
export * from './redirects.ts'
|
|
92
94
|
export * from './remote.ts'
|
|
93
95
|
export * from './remote-ci.ts'
|
|
94
96
|
export * from './remote-credentials.ts'
|
|
95
97
|
export * from './remote-media.ts'
|
|
98
|
+
export * from './restart-pending.ts'
|
|
96
99
|
export * from './routes.ts'
|
|
97
100
|
export * from './schema.ts'
|
|
98
101
|
export * from './schema-picks.ts'
|
|
@@ -118,6 +121,7 @@ export * from './udt.ts'
|
|
|
118
121
|
export * from './upgrade-summary.ts'
|
|
119
122
|
export * from './url-settings.ts'
|
|
120
123
|
export * from './view-runtime.ts'
|
|
124
|
+
export * from './webhook-edit.ts'
|
|
121
125
|
export * from './webhook-files.ts'
|
|
122
126
|
export * from './webhooks.ts'
|
|
123
127
|
export * from './worker.ts'
|