@crombolo/server 0.43.1 → 0.45.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 +20 -14
- package/src/adapters/health.ts +48 -0
- 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 +61 -2
- package/src/core.ts +5 -1
- package/src/form-submit.ts +32 -5
- package/src/form-workflows.ts +7 -1
- package/src/index.ts +4 -0
- package/src/marketplace.ts +277 -65
- package/src/no-nodes.ts +1 -1
- package/src/provenance.ts +466 -0
- package/src/remote-ci.ts +334 -0
- package/src/remote.ts +679 -14
- package/src/restart-pending.ts +52 -0
- package/src/schema.ts +7 -0
- package/src/seed/compile.ts +17 -15
- package/src/seed/export.ts +16 -9
- package/src/seed/read.ts +43 -13
- package/src/server.ts +113 -67
- package/src/settings.ts +29 -4
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'
|
|
@@ -46,8 +47,20 @@ export type UserLinkSender = (message: {
|
|
|
46
47
|
message: string | null
|
|
47
48
|
}) => Promise<void>
|
|
48
49
|
|
|
50
|
+
/**
|
|
51
|
+
* How much a site takes from the remote protocol (story 167), each level the
|
|
52
|
+
* ones before it and more: `read` pulls, `content` applies bundles of content,
|
|
53
|
+
* `all` takes whole-site pushes and bundles that change structure and code.
|
|
54
|
+
*/
|
|
55
|
+
export type RemoteAccess = 'off' | 'read' | 'content' | 'all'
|
|
56
|
+
|
|
57
|
+
export const REMOTE_ACCESS_LEVELS: readonly RemoteAccess[] = ['off', 'read', 'content', 'all']
|
|
58
|
+
|
|
49
59
|
export interface RemoteSettings {
|
|
60
|
+
/** Whether the site answers the protocol at all: its access is not `off`. */
|
|
50
61
|
enabled: boolean
|
|
62
|
+
/** `CROMBOLO_REMOTE_ACCESS`; `all` when only `enabled` is given, as a test does. */
|
|
63
|
+
access?: RemoteAccess
|
|
51
64
|
/** The environment this server is, as the remote protocol names it. */
|
|
52
65
|
environment: string
|
|
53
66
|
/** A push here replaces something people rely on: it needs its own permission. */
|
|
@@ -60,6 +73,24 @@ export interface RemoteSettings {
|
|
|
60
73
|
* the server's.
|
|
61
74
|
*/
|
|
62
75
|
maxUploadBytes: number
|
|
76
|
+
/**
|
|
77
|
+
* Issuers of CI identity tokens trusted beside GitHub's and gitlab.com's (story
|
|
78
|
+
* 160): a self-managed GitLab, as `CROMBOLO_REMOTE_OIDC_ISSUERS`, comma separated.
|
|
79
|
+
*/
|
|
80
|
+
oidcIssuers?: string[]
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** `CROMBOLO_REMOTE_ACCESS`, refusing the switch it replaced so a site does not quietly stop being a remote. */
|
|
84
|
+
function remoteAccessSetting(): RemoteAccess {
|
|
85
|
+
// Read directly: it is no longer a setting, only a name to refuse.
|
|
86
|
+
if (Bun.env.CROMBOLO_REMOTE_ENABLED !== undefined)
|
|
87
|
+
throw new Error(
|
|
88
|
+
'CROMBOLO_REMOTE_ENABLED has gone: set CROMBOLO_REMOTE_ACCESS to read, content or all instead (story 167).',
|
|
89
|
+
)
|
|
90
|
+
const value = (setting('CROMBOLO_REMOTE_ACCESS') ?? 'off').trim().toLowerCase()
|
|
91
|
+
if (!REMOTE_ACCESS_LEVELS.includes(value as RemoteAccess))
|
|
92
|
+
throw new Error(`CROMBOLO_REMOTE_ACCESS is "${value}": it is off, read, content or all.`)
|
|
93
|
+
return value as RemoteAccess
|
|
63
94
|
}
|
|
64
95
|
|
|
65
96
|
/** The prefix every API client id carries, as the Management API requires. */
|
|
@@ -486,6 +517,11 @@ export interface CromboloConfig {
|
|
|
486
517
|
* and `CROMBOLO_INSTALLS_ELSEWHERE_URL`.
|
|
487
518
|
*/
|
|
488
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
|
|
489
525
|
/**
|
|
490
526
|
* Where the Packages section's Marketplace sends someone browsing for
|
|
491
527
|
* extensions. Never framed — npm refuses to be framed — so the native view
|
|
@@ -574,6 +610,12 @@ function roleFromEnvironment(value: string | undefined): ServerRole {
|
|
|
574
610
|
return value
|
|
575
611
|
}
|
|
576
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
|
+
|
|
577
619
|
function jobsFromEnvironment(value: string | undefined): boolean {
|
|
578
620
|
if (value === undefined || value === '' || value === 'on') return true
|
|
579
621
|
if (value === 'off') return false
|
|
@@ -800,17 +842,29 @@ export function loadConfig(
|
|
|
800
842
|
memberIdentityProviders: [],
|
|
801
843
|
backofficeIdentityProviders: [],
|
|
802
844
|
remote: {
|
|
803
|
-
enabled:
|
|
845
|
+
enabled: remoteAccessSetting() !== 'off',
|
|
846
|
+
access: remoteAccessSetting(),
|
|
804
847
|
environment: setting('CROMBOLO_REMOTE_ENVIRONMENT') || 'production',
|
|
805
848
|
protected: setting('CROMBOLO_REMOTE_PROTECTED') !== 'false',
|
|
806
849
|
approvals: setting('CROMBOLO_REMOTE_APPROVALS') === 'true',
|
|
807
850
|
maxUploadBytes: Number(setting('CROMBOLO_REMOTE_MAX_UPLOAD_GB') ?? 50) * 1024 ** 3,
|
|
851
|
+
oidcIssuers: (setting('CROMBOLO_REMOTE_OIDC_ISSUERS') ?? '')
|
|
852
|
+
.split(',')
|
|
853
|
+
.map((issuer) => issuer.trim())
|
|
854
|
+
.filter(Boolean),
|
|
808
855
|
},
|
|
809
856
|
redirects: [],
|
|
810
857
|
trackRedirects: setting('CROMBOLO_TRACK_REDIRECTS') !== 'false',
|
|
811
858
|
applyBundleContentOnInstall: setting('CROMBOLO_APPLY_BUNDLE_CONTENT') !== 'false',
|
|
812
859
|
// Resolved again below, once it is known whether a store was configured.
|
|
813
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
|
+
},
|
|
814
868
|
// Resolved again below, once it is known whether this is development.
|
|
815
869
|
errors: { showDetails: envFlag(setting('CROMBOLO_SHOW_ERROR_DETAILS')) ?? false },
|
|
816
870
|
liveReload: envFlag(setting('CROMBOLO_LIVE_RELOAD')) ?? false,
|
|
@@ -866,6 +920,11 @@ export function loadConfig(
|
|
|
866
920
|
// Field by field, so a site setting its title suffix keeps the environment's switches.
|
|
867
921
|
merged.seo = { ...fromEnv.seo, ...stripUndefined(overrides.seo ?? {}) }
|
|
868
922
|
merged.remote = { ...fromEnv.remote, ...stripUndefined(overrides.remote ?? {}) }
|
|
923
|
+
// An override that says only `enabled` means everything, as before story 167.
|
|
924
|
+
if (overrides.remote?.enabled !== undefined && overrides.remote.access === undefined)
|
|
925
|
+
merged.remote.access = overrides.remote.enabled ? 'all' : 'off'
|
|
926
|
+
merged.remote.access ??= merged.remote.enabled ? 'all' : 'off'
|
|
927
|
+
merged.remote.enabled = merged.remote.access !== 'off'
|
|
869
928
|
merged.errors = {
|
|
870
929
|
showDetails:
|
|
871
930
|
overrides.errors?.showDetails ??
|
|
@@ -982,7 +1041,7 @@ export function describeDatabase(
|
|
|
982
1041
|
}
|
|
983
1042
|
}
|
|
984
1043
|
|
|
985
|
-
export const VERSION = '0.
|
|
1044
|
+
export const VERSION = '0.45.0'
|
|
986
1045
|
|
|
987
1046
|
/** A whole number of seconds from the environment; undefined when unset or not one. */
|
|
988
1047
|
/** A positive number from a setting, else the default. */
|
package/src/core.ts
CHANGED
|
@@ -230,7 +230,11 @@ export async function createCore(config: CromboloConfig, hooks: CoreHooks) {
|
|
|
230
230
|
createMediaSource(db, { nodeState: schema.nodeState, nodeId: schema.nodeId }),
|
|
231
231
|
{ budgetBytes: (config.mediaCacheMegabytes ?? DEFAULT_MEDIA_CACHE_MEGABYTES) * 1024 * 1024 },
|
|
232
232
|
)
|
|
233
|
-
const cacheOptions = {
|
|
233
|
+
const cacheOptions = {
|
|
234
|
+
form: (key: string) => forms.byKey(key),
|
|
235
|
+
forms: () => forms.all(),
|
|
236
|
+
media: mediaCache,
|
|
237
|
+
}
|
|
234
238
|
if (config.errors.showDetails) enableComponentStack()
|
|
235
239
|
const cache = new PublishedCache(publishedSource, {
|
|
236
240
|
...cacheOptions,
|
package/src/form-submit.ts
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
BUILT_IN_FORM_TYPES,
|
|
22
22
|
DEFAULT_UPLOAD_SETTINGS,
|
|
23
23
|
FORM_HONEYPOT_FIELD,
|
|
24
|
+
FORM_LIBRARY_FIELD,
|
|
24
25
|
FORM_PAGE_FIELD,
|
|
25
26
|
FORM_RENDERED_FIELD,
|
|
26
27
|
FORM_RESERVED_FIELDS,
|
|
@@ -28,6 +29,7 @@ import {
|
|
|
28
29
|
type FormFieldError,
|
|
29
30
|
type FormSubmissionState,
|
|
30
31
|
type FormTypes,
|
|
32
|
+
formTokenSubject,
|
|
31
33
|
isUploadAllowed,
|
|
32
34
|
type SchemaForm,
|
|
33
35
|
type SubmittedValues,
|
|
@@ -215,6 +217,7 @@ export function readFlash(
|
|
|
215
217
|
if (!parsed) return undefined
|
|
216
218
|
return {
|
|
217
219
|
formKey: parsed.formKey,
|
|
220
|
+
...(parsed.libraryKey ? { libraryKey: parsed.libraryKey } : {}),
|
|
218
221
|
formAlias: parsed.formAlias,
|
|
219
222
|
values: parsed.values ?? {},
|
|
220
223
|
errors: parsed.errors ?? [],
|
|
@@ -238,6 +241,8 @@ export interface FormSubmitDeps {
|
|
|
238
241
|
urlOf?: (key: string) => Promise<string | undefined>
|
|
239
242
|
/** Fills in the options of choices drawn from a source, as the page rendered them. */
|
|
240
243
|
resolveForm?: (form: SchemaForm) => Promise<SchemaForm>
|
|
244
|
+
/** A published Library form's form, with its words (story 239). */
|
|
245
|
+
libraryForm?: (key: string) => Promise<SchemaForm | undefined>
|
|
241
246
|
}
|
|
242
247
|
|
|
243
248
|
export type FormSubmitOutcome =
|
|
@@ -289,9 +294,8 @@ export async function submitForm(
|
|
|
289
294
|
formKey: string,
|
|
290
295
|
options: { ip?: string; now?: number } = {},
|
|
291
296
|
): Promise<FormSubmitOutcome> {
|
|
292
|
-
const
|
|
293
|
-
if (!
|
|
294
|
-
const form = deps.resolveForm ? await deps.resolveForm(definition) : definition
|
|
297
|
+
const file = deps.forms.byKey(formKey)
|
|
298
|
+
if (!file) return { status: 'notFound' }
|
|
295
299
|
|
|
296
300
|
const secret = await formSigningSecret(deps.db)
|
|
297
301
|
const data = await request.formData()
|
|
@@ -299,9 +303,23 @@ export async function submitForm(
|
|
|
299
303
|
|
|
300
304
|
const renderedAt = Number(data.get(FORM_RENDERED_FIELD) ?? 0)
|
|
301
305
|
const token = String(data.get(FORM_TOKEN_FIELD) ?? '')
|
|
306
|
+
const libraryKey = String(data.get(FORM_LIBRARY_FIELD) ?? '').trim() || undefined
|
|
302
307
|
// Always required: the renderer puts a token in every form it draws, so a
|
|
303
308
|
// submission without a good one did not come from a page this site rendered.
|
|
304
|
-
|
|
309
|
+
// It covers the Library form too, so its words cannot be swapped for another's.
|
|
310
|
+
const subject = formTokenSubject(formKey, libraryKey)
|
|
311
|
+
if (!verifyFormToken(secret, subject, renderedAt, token)) return { status: 'badToken' }
|
|
312
|
+
|
|
313
|
+
// Shown through a Library form: its words, which must still be published
|
|
314
|
+
// and still be made from this form.
|
|
315
|
+
let definition = file
|
|
316
|
+
if (libraryKey) {
|
|
317
|
+
const library = await deps.libraryForm?.(libraryKey)
|
|
318
|
+
if (!library || (library.key ?? library.alias) !== (file.key ?? file.alias))
|
|
319
|
+
return { status: 'notFound' }
|
|
320
|
+
definition = library
|
|
321
|
+
}
|
|
322
|
+
const form = deps.resolveForm ? await deps.resolveForm(definition) : definition
|
|
305
323
|
|
|
306
324
|
// A stepped form moving forward: this page's answers checked, and nothing else.
|
|
307
325
|
const checking = data.get(FORM_PAGE_FIELD)
|
|
@@ -365,7 +383,13 @@ export async function submitForm(
|
|
|
365
383
|
return {
|
|
366
384
|
status: 'invalid',
|
|
367
385
|
form,
|
|
368
|
-
state: {
|
|
386
|
+
state: {
|
|
387
|
+
formKey: key,
|
|
388
|
+
...(libraryKey ? { libraryKey } : {}),
|
|
389
|
+
formAlias: form.alias,
|
|
390
|
+
values: submitted,
|
|
391
|
+
errors: result.errors,
|
|
392
|
+
},
|
|
369
393
|
}
|
|
370
394
|
|
|
371
395
|
let entryId: string | undefined
|
|
@@ -375,6 +399,7 @@ export async function submitForm(
|
|
|
375
399
|
formAlias: form.alias,
|
|
376
400
|
culture: null,
|
|
377
401
|
pageKey: null,
|
|
402
|
+
libraryKey: libraryKey ?? null,
|
|
378
403
|
ipHash: hashIp(secret, options.ip),
|
|
379
404
|
userAgent: request.headers.get('user-agent')?.slice(0, 500) ?? null,
|
|
380
405
|
spam,
|
|
@@ -401,6 +426,7 @@ export async function submitForm(
|
|
|
401
426
|
runOn: workflow.on,
|
|
402
427
|
entryId: entryId ?? null,
|
|
403
428
|
payload: result.values,
|
|
429
|
+
...(form.library?.recipients ? { recipients: form.library.recipients } : {}),
|
|
404
430
|
})),
|
|
405
431
|
)
|
|
406
432
|
|
|
@@ -419,6 +445,7 @@ export async function submitForm(
|
|
|
419
445
|
redirectTo,
|
|
420
446
|
state: {
|
|
421
447
|
formKey: key,
|
|
448
|
+
...(libraryKey ? { libraryKey } : {}),
|
|
422
449
|
formAlias: form.alias,
|
|
423
450
|
values: {},
|
|
424
451
|
errors: [],
|
package/src/form-workflows.ts
CHANGED
|
@@ -45,6 +45,8 @@ export interface WorkflowContext {
|
|
|
45
45
|
form: SchemaForm
|
|
46
46
|
values: readonly FormValueToStore[]
|
|
47
47
|
entryId: string | null
|
|
48
|
+
/** In place of a send-e-mail workflow's `to`: a Library form's recipients (story 239). */
|
|
49
|
+
recipients?: readonly string[]
|
|
48
50
|
/** Which attempt this is, from 1. */
|
|
49
51
|
attempt?: number
|
|
50
52
|
/** When the run was queued; now when absent. */
|
|
@@ -232,7 +234,10 @@ async function sendEmail(
|
|
|
232
234
|
// asks for them: an inbox is not covered by the sensitive-data permission.
|
|
233
235
|
const leftOut = leftOutFields(context.form, workflow)
|
|
234
236
|
const values = withoutLeftOut(context.values, leftOut)
|
|
235
|
-
const to =
|
|
237
|
+
const to =
|
|
238
|
+
context.recipients && context.recipients.length > 0
|
|
239
|
+
? [...context.recipients]
|
|
240
|
+
: asList(substitute(asString(settings.to) ?? '', values))
|
|
236
241
|
if (to.length === 0) return { ok: false, retry: false, error: 'The workflow has no recipient.' }
|
|
237
242
|
const subject = substitute(asString(settings.subject) ?? context.form.name, values).trim()
|
|
238
243
|
|
|
@@ -589,6 +594,7 @@ export function createWorkflowRunner(
|
|
|
589
594
|
form,
|
|
590
595
|
values: run.payload,
|
|
591
596
|
entryId: run.entryId,
|
|
597
|
+
...(run.recipients ? { recipients: run.recipients } : {}),
|
|
592
598
|
attempt: run.attempts,
|
|
593
599
|
submittedAt: run.createDate,
|
|
594
600
|
}
|
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,11 +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'
|
|
95
|
+
export * from './remote-ci.ts'
|
|
93
96
|
export * from './remote-credentials.ts'
|
|
94
97
|
export * from './remote-media.ts'
|
|
98
|
+
export * from './restart-pending.ts'
|
|
95
99
|
export * from './routes.ts'
|
|
96
100
|
export * from './schema.ts'
|
|
97
101
|
export * from './schema-picks.ts'
|