@crombolo/server 0.36.2 → 0.38.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 +15 -13
- package/src/access.ts +29 -27
- package/src/adapters/audit.ts +1 -1
- package/src/adapters/blueprints.ts +22 -13
- package/src/adapters/content.ts +1 -1
- package/src/adapters/dictionary.ts +1 -1
- package/src/adapters/documents.ts +17 -10
- package/src/adapters/elements.ts +47 -37
- package/src/adapters/file-system.ts +1 -1
- package/src/adapters/health.ts +33 -5
- package/src/adapters/media.ts +12 -8
- package/src/adapters/member-groups.ts +8 -6
- package/src/adapters/members.ts +6 -4
- package/src/adapters/public-access.ts +7 -5
- package/src/adapters/redirects.ts +1 -1
- package/src/adapters/references.ts +1 -1
- package/src/adapters/relations.ts +1 -1
- package/src/adapters/schema-files.ts +33 -1
- package/src/adapters/search-index.ts +1 -1
- package/src/adapters/template-files.ts +6 -1
- package/src/adapters/template-query.ts +1 -1
- package/src/adapters/users.ts +13 -13
- package/src/adapters/webhooks.ts +1 -1
- package/src/anonymise-rules.ts +83 -0
- package/src/approvals-api.ts +1 -1
- package/src/approvals.ts +75 -38
- package/src/back-office-url.ts +20 -0
- package/src/backup.ts +26 -2
- package/src/bundle-code.ts +1 -1
- package/src/bundle-grants.ts +265 -0
- package/src/bundle-install.ts +13 -2
- package/src/bundle-media.ts +12 -11
- package/src/bundles.ts +258 -444
- package/src/component-snippets.ts +1 -1
- package/src/components.ts +48 -7
- package/src/config.ts +141 -4
- package/src/content-notifications.ts +13 -9
- package/src/content-operations.ts +23 -65
- package/src/content-query.ts +1 -1
- package/src/core.ts +663 -0
- package/src/cron.ts +139 -0
- package/src/custom-tables.ts +274 -0
- package/src/database.ts +22 -14
- package/src/dictionary-transfer.ts +1 -1
- package/src/git-routes.ts +1 -1
- package/src/identity-provider-overrides.ts +18 -16
- package/src/imaging.ts +65 -15
- package/src/index.ts +14 -1
- package/src/islands.ts +197 -0
- package/src/job-wake.ts +23 -0
- package/src/live-reload.ts +195 -0
- package/src/log-viewer.ts +6 -1
- package/src/marketplace.ts +82 -10
- package/src/media-access.ts +12 -9
- package/src/member-auth.ts +6 -4
- package/src/middleware.ts +236 -0
- package/src/models-builder.ts +1 -1
- package/src/node-operations.ts +122 -0
- package/src/owner-jobs.ts +428 -0
- package/src/ports.ts +39 -154
- package/src/preview-tokens.ts +6 -12
- package/src/remote.ts +3 -1
- package/src/routes.ts +420 -0
- package/src/schema.ts +8 -3
- package/src/seed/compile.ts +7 -5
- package/src/seed/export.ts +6 -4
- package/src/seo.ts +2 -2
- package/src/server.ts +866 -483
- package/src/settings.ts +49 -2
- package/src/site-data.ts +195 -0
- package/src/site-file.ts +30 -4
- package/src/site-queries.ts +140 -0
- package/src/site-replace.ts +25 -19
- package/src/site-sections.ts +1 -1
- package/src/site-services.ts +116 -0
- package/src/status-pages.ts +142 -0
- package/src/status.ts +11 -9
- package/src/url-settings.ts +1 -2
- package/src/webhook-files.ts +18 -1
- package/src/webhooks.ts +83 -15
- package/src/worker-watch.ts +73 -0
- package/src/worker.ts +138 -0
- package/src/bundle-tables.ts +0 -161
package/src/ports.ts
CHANGED
|
@@ -22,15 +22,7 @@ import {
|
|
|
22
22
|
type ExtensionRegistry,
|
|
23
23
|
toResponseModels,
|
|
24
24
|
} from '@crombolo/backoffice-host'
|
|
25
|
-
import {
|
|
26
|
-
type ApprovalsGate,
|
|
27
|
-
type ContentPrincipal,
|
|
28
|
-
createDocumentOperations,
|
|
29
|
-
createMediaOperations,
|
|
30
|
-
type DocumentOperations,
|
|
31
|
-
type EventSink,
|
|
32
|
-
SILENT,
|
|
33
|
-
} from '@crombolo/content'
|
|
25
|
+
import type { EventSink } from '@crombolo/content'
|
|
34
26
|
import {
|
|
35
27
|
CORE_SECTION_ALIASES,
|
|
36
28
|
DEFAULT_UPLOAD_SETTINGS,
|
|
@@ -39,13 +31,11 @@ import {
|
|
|
39
31
|
permissionsForPath,
|
|
40
32
|
} from '@crombolo/core'
|
|
41
33
|
import {
|
|
42
|
-
appendCacheInstruction,
|
|
43
34
|
ContentEventRepository,
|
|
44
35
|
ContentTypeRepository,
|
|
45
36
|
type Db,
|
|
46
37
|
DynamicRootRepository,
|
|
47
38
|
LanguageRepository,
|
|
48
|
-
RedirectRepository,
|
|
49
39
|
TagRepository,
|
|
50
40
|
UserRepository,
|
|
51
41
|
} from '@crombolo/data'
|
|
@@ -74,31 +64,27 @@ import { createReferencePort } from './adapters/references.ts'
|
|
|
74
64
|
import { createRelationPort } from './adapters/relations.ts'
|
|
75
65
|
import {
|
|
76
66
|
createSchemaFileWriter,
|
|
77
|
-
type SchemaFiles,
|
|
78
67
|
type SchemaFileWriter,
|
|
68
|
+
schemaFiles,
|
|
79
69
|
} from './adapters/schema-files.ts'
|
|
80
70
|
import { createSearchIndexPort } from './adapters/search-index.ts'
|
|
81
71
|
import { createTemplateFileStore } from './adapters/template-files.ts'
|
|
82
72
|
import { createTemplateQueryPort } from './adapters/template-query.ts'
|
|
83
73
|
import { avatarUrls, createUserPorts } from './adapters/users.ts'
|
|
84
74
|
import { createWebhookPort } from './adapters/webhooks.ts'
|
|
85
|
-
import {
|
|
75
|
+
import { backOfficeUrl } from './back-office-url.ts'
|
|
86
76
|
import { COMPONENT_SNIPPETS } from './component-snippets.ts'
|
|
87
77
|
import { type CromboloConfig, type UserLinkSender, VERSION } from './config.ts'
|
|
88
|
-
import { createMediaEventSink } from './content-events.ts'
|
|
89
78
|
import type { ContentNotifier } from './content-notifications.ts'
|
|
90
|
-
import { writeDomainsFor } from './domains.ts'
|
|
91
79
|
import { type EmailPort, resolveEmailPort } from './email.ts'
|
|
92
|
-
import { createFileIntake
|
|
93
|
-
import { formTypesFor } from './form-types.ts'
|
|
80
|
+
import { createFileIntake } from './file-intake.ts'
|
|
94
81
|
import { createLogViewerPort } from './log-viewer.ts'
|
|
95
82
|
import { logger } from './logging.ts'
|
|
96
83
|
import { MediaFileStore } from './media-files.ts'
|
|
97
84
|
import { createModelsBuilderPort } from './models-builder.ts'
|
|
85
|
+
import { createNodeOperations, type NodeOperations } from './node-operations.ts'
|
|
98
86
|
import { createOEmbedService } from './oembed.ts'
|
|
99
|
-
import {
|
|
100
|
-
import { componentAliasesIn, type SchemaBoot } from './schema.ts'
|
|
101
|
-
import { publishSchema } from './schema-store.ts'
|
|
87
|
+
import type { SchemaBoot } from './schema.ts'
|
|
102
88
|
import { TwoFactorService, USER_TWO_FACTOR_PROVIDER } from './two-factor.ts'
|
|
103
89
|
import { createWebhookService, type WebhookService } from './webhooks.ts'
|
|
104
90
|
|
|
@@ -364,35 +350,9 @@ export function resolveUserLinkSender(
|
|
|
364
350
|
return config.development ? logUserLink : undefined
|
|
365
351
|
}
|
|
366
352
|
|
|
367
|
-
/** Where the backoffice writes schema files, and whether it may. */
|
|
368
|
-
export function schemaFiles(config: CromboloConfig): SchemaFiles {
|
|
369
|
-
const store = config.schemaStore
|
|
370
|
-
return {
|
|
371
|
-
schemaDir: config.schemaDir,
|
|
372
|
-
writable: config.schemaWritable,
|
|
373
|
-
componentAliases: () => componentAliasesIn(config.componentsDir),
|
|
374
|
-
formTypes: formTypesFor(config),
|
|
375
|
-
// Only when a store is configured: a schema directory in a repository is
|
|
376
|
-
// already where the files durably live.
|
|
377
|
-
onChanged: store
|
|
378
|
-
? async () => {
|
|
379
|
-
const report = await publishSchema(store, config.schemaDir)
|
|
380
|
-
if (report.written.length > 0 || report.removed.length > 0) {
|
|
381
|
-
logger('schema').info(
|
|
382
|
-
'Published schema to {store}: {written} written, {removed} removed',
|
|
383
|
-
{
|
|
384
|
-
store: store.description,
|
|
385
|
-
written: report.written.length,
|
|
386
|
-
removed: report.removed.length,
|
|
387
|
-
},
|
|
388
|
-
)
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
: undefined,
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
|
|
395
353
|
export interface DepsOptions {
|
|
354
|
+
/** Published pages a site route answers in place of, for the health check (story 211). */
|
|
355
|
+
hiddenByRoutes?: () => Promise<Array<{ route: string; owner: string; page: string; url: string }>>
|
|
396
356
|
config: CromboloConfig
|
|
397
357
|
paths: BackOfficePaths
|
|
398
358
|
/** The site's installed npm extensions, which contribute their manifests. */
|
|
@@ -428,24 +388,8 @@ export interface DepsOptions {
|
|
|
428
388
|
onSearchQueued?: () => void
|
|
429
389
|
/** Queues content notifications for changes made outside the router (story 045). */
|
|
430
390
|
notifier?: ContentNotifier
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
/** The back office's address, e.g. `https://site.example/crombolo`; undefined when the site's own is not set. */
|
|
434
|
-
export function backOfficeUrl(
|
|
435
|
-
config: Pick<CromboloConfig, 'applicationUrl' | 'backOfficePath'>,
|
|
436
|
-
): string | undefined {
|
|
437
|
-
return config.applicationUrl
|
|
438
|
-
? `${config.applicationUrl.replace(/\/$/, '')}${config.backOfficePath}`
|
|
439
|
-
: undefined
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
/** A page's address in the back office, for a link in an e-mail. */
|
|
443
|
-
export function documentEditUrl(
|
|
444
|
-
config: Pick<CromboloConfig, 'applicationUrl' | 'backOfficePath'>,
|
|
445
|
-
key: string,
|
|
446
|
-
): string | undefined {
|
|
447
|
-
const base = backOfficeUrl(config)
|
|
448
|
-
return base ? `${base}/section/content/workspace/document/edit/${key}` : undefined
|
|
391
|
+
/** The node's document and media operations, when it has built them already. */
|
|
392
|
+
operations?: NodeOperations
|
|
449
393
|
}
|
|
450
394
|
|
|
451
395
|
function createTemporaryFilePort(files: MediaFileStore): TemporaryFilePort {
|
|
@@ -494,7 +438,25 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
|
|
|
494
438
|
const mediaFiles =
|
|
495
439
|
options.mediaFiles ?? new MediaFileStore(options.config.mediaStore ?? options.config.mediaDir)
|
|
496
440
|
deps.temporaryFiles = createTemporaryFilePort(mediaFiles)
|
|
497
|
-
const
|
|
441
|
+
const operations =
|
|
442
|
+
options.operations ??
|
|
443
|
+
(options.db
|
|
444
|
+
? createNodeOperations({
|
|
445
|
+
db: options.db,
|
|
446
|
+
config: options.config,
|
|
447
|
+
cache: options.cache,
|
|
448
|
+
nodeState: options.schema?.nodeState,
|
|
449
|
+
nodeId: options.schema?.nodeId,
|
|
450
|
+
mediaFiles,
|
|
451
|
+
email,
|
|
452
|
+
notifier: options.notifier,
|
|
453
|
+
contentEvents: options.contentEvents,
|
|
454
|
+
webhooks: options.webhooks,
|
|
455
|
+
nudgeEvents: options.nudgeEvents,
|
|
456
|
+
backOfficeUrl: backOfficeUrl(options.config),
|
|
457
|
+
})
|
|
458
|
+
: undefined)
|
|
459
|
+
const valueIntake = operations?.valueIntake ?? createFileIntake(mediaFiles)
|
|
498
460
|
deps.oembed = createOEmbedService(options.fetch)
|
|
499
461
|
// The whole components tree, which is one root with folders rather than
|
|
500
462
|
// Umbraco's split of ~/Views and ~/Views/Partials. The backoffice reaches it
|
|
@@ -518,6 +480,7 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
|
|
|
518
480
|
email,
|
|
519
481
|
nodeState: options.schema?.nodeState,
|
|
520
482
|
fetch: options.fetch,
|
|
483
|
+
hiddenByRoutes: options.hiddenByRoutes,
|
|
521
484
|
})
|
|
522
485
|
const tags = new TagRepository(options.db)
|
|
523
486
|
deps.tags = { list: (filter) => tags.all(filter) }
|
|
@@ -582,20 +545,7 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
|
|
|
582
545
|
valueIntake,
|
|
583
546
|
})
|
|
584
547
|
// Every media write, whoever starts it (story 165).
|
|
585
|
-
deps.mediaOperations =
|
|
586
|
-
db: options.db,
|
|
587
|
-
repository: {
|
|
588
|
-
nodeState: options.schema?.nodeState,
|
|
589
|
-
nodeId: options.schema?.nodeId,
|
|
590
|
-
valueIntake,
|
|
591
|
-
},
|
|
592
|
-
events: createMediaEventSink({ webhooks: options.webhooks, nudge: options.nudgeEvents }),
|
|
593
|
-
files: mediaFiles,
|
|
594
|
-
// Only the items it touched: a media change leaves the pages alone (story 197).
|
|
595
|
-
onChange: (change) => options.cache?.media?.apply(change),
|
|
596
|
-
refusalReason: (error) =>
|
|
597
|
-
error instanceof TemporaryFileMissingError ? error.message : undefined,
|
|
598
|
-
})
|
|
548
|
+
deps.mediaOperations = operations?.media
|
|
599
549
|
deps.blueprints = createBlueprintPort(options.db, {
|
|
600
550
|
nodeState: options.schema?.nodeState,
|
|
601
551
|
valueIntake,
|
|
@@ -680,7 +630,7 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
|
|
|
680
630
|
rebuild: async () => {
|
|
681
631
|
cache.invalidate()
|
|
682
632
|
cache.media?.clear()
|
|
683
|
-
await cache.
|
|
633
|
+
await cache.fresh()
|
|
684
634
|
},
|
|
685
635
|
isRebuilding: () => false,
|
|
686
636
|
}
|
|
@@ -689,21 +639,7 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
|
|
|
689
639
|
onChange: () => options.cache?.invalidate(),
|
|
690
640
|
nodeId: options.schema?.nodeId,
|
|
691
641
|
})
|
|
692
|
-
|
|
693
|
-
const tracker = options.cache
|
|
694
|
-
? createRedirectTracker({
|
|
695
|
-
cache: options.cache,
|
|
696
|
-
redirects: new RedirectRepository(db),
|
|
697
|
-
enabled: options.config.trackRedirects,
|
|
698
|
-
instruct: () =>
|
|
699
|
-
appendCacheInstruction(db, {
|
|
700
|
-
kind: 'content',
|
|
701
|
-
payload: { redirects: true },
|
|
702
|
-
by: options.schema?.nodeId,
|
|
703
|
-
}),
|
|
704
|
-
})
|
|
705
|
-
: undefined
|
|
706
|
-
if (options.cache)
|
|
642
|
+
if (operations && options.cache)
|
|
707
643
|
deps.documents = createDocumentPort(
|
|
708
644
|
options.db,
|
|
709
645
|
options.cache,
|
|
@@ -712,50 +648,13 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
|
|
|
712
648
|
nodeId: options.schema?.nodeId,
|
|
713
649
|
valueIntake,
|
|
714
650
|
},
|
|
715
|
-
tracker,
|
|
651
|
+
operations.tracker,
|
|
716
652
|
options.config.siteDir,
|
|
717
653
|
Boolean(email),
|
|
718
654
|
)
|
|
719
|
-
if (deps.documents) {
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
// through it too, so what an approval publishes is cached, tracked and
|
|
723
|
-
// announced as any publish is.
|
|
724
|
-
let operations: DocumentOperations | undefined
|
|
725
|
-
const approvals = createApprovals({
|
|
726
|
-
db,
|
|
727
|
-
nodeState: options.schema?.nodeState,
|
|
728
|
-
email,
|
|
729
|
-
backOfficeUrl: backOfficeUrl(options.config),
|
|
730
|
-
notifier: options.notifier,
|
|
731
|
-
publisher: {
|
|
732
|
-
publish: (key, cultures, actor, approvedHead) =>
|
|
733
|
-
(operations as DocumentOperations).publish(actor, key, {
|
|
734
|
-
cultures,
|
|
735
|
-
expectedHead: approvedHead,
|
|
736
|
-
}),
|
|
737
|
-
unpublish: (key, cultures, actor) =>
|
|
738
|
-
(operations as DocumentOperations).unpublish(actor, key, cultures),
|
|
739
|
-
},
|
|
740
|
-
})
|
|
741
|
-
deps.approvals = approvals
|
|
742
|
-
operations = createDocumentOperations({
|
|
743
|
-
db,
|
|
744
|
-
repository: {
|
|
745
|
-
nodeState: options.schema?.nodeState,
|
|
746
|
-
nodeId: options.schema?.nodeId,
|
|
747
|
-
valueIntake,
|
|
748
|
-
},
|
|
749
|
-
events: options.contentEvents ?? SILENT,
|
|
750
|
-
approvals: approvalsGate(approvals),
|
|
751
|
-
redirects: tracker,
|
|
752
|
-
onChange: () => options.cache?.invalidate(),
|
|
753
|
-
afterDomains: (node, assignment) =>
|
|
754
|
-
writeDomainsFor(db, options.config.siteDir, node, assignment),
|
|
755
|
-
refusalReason: (error) =>
|
|
756
|
-
error instanceof TemporaryFileMissingError ? error.message : undefined,
|
|
757
|
-
})
|
|
758
|
-
deps.documentOperations = operations
|
|
655
|
+
if (deps.documents && operations) {
|
|
656
|
+
deps.approvals = operations.approvals
|
|
657
|
+
deps.documentOperations = operations.documents
|
|
759
658
|
}
|
|
760
659
|
}
|
|
761
660
|
return deps
|
|
@@ -802,19 +701,5 @@ function userTwoFactorPort(service: TwoFactorService): UserTwoFactorPort {
|
|
|
802
701
|
}
|
|
803
702
|
}
|
|
804
703
|
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
* is the backoffice's own, passed straight through; a local operator has none.
|
|
808
|
-
*/
|
|
809
|
-
export function approvalsGate(approvals: Approvals): ApprovalsGate {
|
|
810
|
-
const as = (who: ContentPrincipal | undefined) => who as Principal | undefined
|
|
811
|
-
return {
|
|
812
|
-
publishRefusal: (who, key, action) => approvals.publishRefusal(as(who), key, action),
|
|
813
|
-
branchRefusal: (who, key) => approvals.branchRefusal(as(who), key),
|
|
814
|
-
newPageRefusal: (who, parentKey, typeKey) =>
|
|
815
|
-
approvals.newPageRefusal(as(who), parentKey, typeKey),
|
|
816
|
-
beforeSave: (who, key) => approvals.beforeSave(as(who), key),
|
|
817
|
-
afterSave: (who, key) => approvals.afterSave(as(who), key),
|
|
818
|
-
afterDirectPublish: (who, key, what) => approvals.afterDirectPublish(as(who), key, what),
|
|
819
|
-
}
|
|
820
|
-
}
|
|
704
|
+
export { schemaFiles } from './adapters/schema-files.ts'
|
|
705
|
+
export { backOfficeUrl, documentEditUrl } from './back-office-url.ts'
|
package/src/preview-tokens.ts
CHANGED
|
@@ -78,18 +78,12 @@ export async function previewUser(
|
|
|
78
78
|
db: Db,
|
|
79
79
|
where: { id: number } | { key: string },
|
|
80
80
|
): Promise<{ id: number; stamp: string } | undefined> {
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
security_stamp
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
`SELECT id, security_stamp, is_locked_out, is_approved FROM user_account WHERE ${
|
|
88
|
-
'id' in where ? 'id' : 'key'
|
|
89
|
-
} = ?`,
|
|
90
|
-
['id' in where ? where.id : where.key],
|
|
91
|
-
)
|
|
92
|
-
const row = rows[0]
|
|
81
|
+
const row = await db.q
|
|
82
|
+
.selectFrom('user_account')
|
|
83
|
+
.select(['id', 'security_stamp', 'is_locked_out', 'is_approved'])
|
|
84
|
+
.$if('id' in where, (q) => q.where('id', '=', (where as { id: number }).id))
|
|
85
|
+
.$if(!('id' in where), (q) => q.where('key', '=', (where as { key: string }).key))
|
|
86
|
+
.executeTakeFirst()
|
|
93
87
|
if (!row || fromDbBool(row.is_locked_out) || !fromDbBool(row.is_approved)) return undefined
|
|
94
88
|
return { id: Number(row.id), stamp: stampDigest(row.security_stamp) }
|
|
95
89
|
}
|
package/src/remote.ts
CHANGED
|
@@ -15,7 +15,7 @@ import { createWriteStream } from 'node:fs'
|
|
|
15
15
|
import { mkdir, rm } from 'node:fs/promises'
|
|
16
16
|
import { tmpdir } from 'node:os'
|
|
17
17
|
import { join, sep } from 'node:path'
|
|
18
|
-
import { hasSection, type Principal } from '@crombolo/api-management'
|
|
18
|
+
import { hasSection, type Principal } from '@crombolo/api-management/domain'
|
|
19
19
|
import { DEVICE_CODE_GRANT, REMOTE_CLIENT_ID } from '@crombolo/auth'
|
|
20
20
|
import { managementApiPath, RemotePermissions, type RemoteVerb } from '@crombolo/core'
|
|
21
21
|
import { AuditLog, auditRecord, type Db, type RemoteJob, RemoteJobRepository } from '@crombolo/data'
|
|
@@ -255,6 +255,8 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
255
255
|
anonymise: !full,
|
|
256
256
|
withMembers: full,
|
|
257
257
|
withUsers: full,
|
|
258
|
+
// Anonymised, it carries what the owners' rules allow.
|
|
259
|
+
withSiteData: true,
|
|
258
260
|
sealContent: true,
|
|
259
261
|
passphrase,
|
|
260
262
|
})
|