@crombolo/server 0.40.0 → 0.42.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/server",
3
- "version": "0.40.0",
3
+ "version": "0.42.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.40.0",
35
- "@crombolo/api-management": "0.40.0",
36
- "@crombolo/auth": "0.40.0",
37
- "@crombolo/backoffice-host": "0.40.0",
38
- "@crombolo/common": "0.40.0",
39
- "@crombolo/content": "0.40.0",
40
- "@crombolo/contracts": "0.40.0",
41
- "@crombolo/core": "0.40.0",
42
- "@crombolo/data": "0.40.0",
43
- "@crombolo/render": "0.40.0",
44
- "@crombolo/schema": "0.40.0",
45
- "@crombolo/transfer": "0.40.0",
34
+ "@crombolo/api-delivery": "0.42.1",
35
+ "@crombolo/api-management": "0.42.1",
36
+ "@crombolo/auth": "0.42.1",
37
+ "@crombolo/backoffice-host": "0.42.1",
38
+ "@crombolo/common": "0.42.1",
39
+ "@crombolo/content": "0.42.1",
40
+ "@crombolo/contracts": "0.42.1",
41
+ "@crombolo/core": "0.42.1",
42
+ "@crombolo/data": "0.42.1",
43
+ "@crombolo/render": "0.42.1",
44
+ "@crombolo/schema": "0.42.1",
45
+ "@crombolo/transfer": "0.42.1",
46
46
  "@logtape/logtape": "^2.3.8",
47
47
  "jose": "^6.2.12"
48
48
  }
@@ -21,11 +21,13 @@ import { ObjectTypes, type Page } from '@crombolo/core'
21
21
  import {
22
22
  type Bundle,
23
23
  BundleRepository,
24
+ type BundleSchemaPicks,
24
25
  type ComponentFileStore,
25
26
  type Db,
26
27
  type NodeRow,
27
28
  resolveNodeRef,
28
29
  } from '@crombolo/data'
30
+ import { loadSchemaDirectory, type SchemaSet } from '@crombolo/schema'
29
31
  import {
30
32
  type BundleBlob,
31
33
  type BundleDependency,
@@ -43,6 +45,7 @@ import {
43
45
  import { VERSION } from '../config.ts'
44
46
  import { readBlobs } from '../media-files.ts'
45
47
  import type { MediaStore } from '../media-store.ts'
48
+ import { carriedPicks, schemaPickFiles } from '../schema-picks.ts'
46
49
  import { siteSections } from '../site-sections.ts'
47
50
  import { writeNpmTarball } from '../tar.ts'
48
51
 
@@ -67,6 +70,8 @@ export interface PackagePortOptions {
67
70
  components?: FileSystemPort
68
71
  stylesheets?: FileSystemPort
69
72
  scripts?: FileSystemPort
73
+ /** Where the site's forms, workflows and user groups are read from (story 226). */
74
+ schemaDir?: string
70
75
  }
71
76
 
72
77
  const definition = (row: Bundle): PackageDefinition => ({
@@ -278,6 +283,13 @@ export function createPackagePort(db: Db, options: PackagePortOptions): PackageP
278
283
  if (!row) return undefined
279
284
  const from = definition(row)
280
285
  const pkg = bundlePackageOf(row)
286
+ const declared = options.schemaDir
287
+ ? loadSchemaDirectory(options.schemaDir)
288
+ : { set: undefined, files: new Map<string, string>() }
289
+ const carried = declared.set ? carriedPicks(declared.set, await bundles.schemaPicks(id)) : []
290
+ const broughtTypes = carried
291
+ .filter((pick) => pick.kind === 'documentType' && !pick.excluded)
292
+ .map((pick) => pick.alias)
281
293
 
282
294
  const sections = await siteSections(
283
295
  {
@@ -288,7 +300,7 @@ export function createPackagePort(db: Db, options: PackagePortOptions): PackageP
288
300
  scripts: options.scripts,
289
301
  },
290
302
  {
291
- contentTypes: from.contentTypes,
303
+ contentTypes: [...from.contentTypes, ...broughtTypes],
292
304
  mediaTypes: from.mediaTypes,
293
305
  dataTypes: from.dataTypes,
294
306
  languages: from.languages,
@@ -299,6 +311,17 @@ export function createPackagePort(db: Db, options: PackagePortOptions): PackageP
299
311
  },
300
312
  )
301
313
 
314
+ // Document types go through the picked-type path above; the rest are the
315
+ // site's own files, which the database does not hold.
316
+ if (options.schemaDir)
317
+ sections.push(
318
+ ...schemaPickFiles(
319
+ declared,
320
+ options.schemaDir,
321
+ carried.filter((pick) => pick.kind !== 'documentType'),
322
+ ),
323
+ )
324
+
302
325
  const content = await contentEntries(from, buildOptions.withMedia === true)
303
326
  // A package with nothing picked is still a bundle: an empty selection
304
327
  // produces an empty set rather than throwing, which is what gives a
@@ -388,3 +411,58 @@ export async function writeCreatedBundlePackage(
388
411
  await bundles.setPackage(id, { name: name || null, version: version || null })
389
412
  return { ok: true, package: (await readCreatedBundlePackage(db, id)) as CreatedBundlePackage }
390
413
  }
414
+
415
+ /** The forms, workflows and user groups a created bundle can pick: the site's files. */
416
+ export interface SchemaPickChoices {
417
+ forms: { alias: string; name: string }[]
418
+ workflows: { alias: string; name: string }[]
419
+ userGroups: { alias: string; name: string }[]
420
+ }
421
+
422
+ const declaredSet = (schemaDir: string): SchemaSet => loadSchemaDirectory(schemaDir).set
423
+
424
+ export function schemaPickChoices(schemaDir: string): SchemaPickChoices {
425
+ const set = declaredSet(schemaDir)
426
+ const named = (list: readonly { alias: string; name: string }[] | undefined) =>
427
+ (list ?? []).map(({ alias, name }) => ({ alias, name }))
428
+ return {
429
+ forms: named(set.forms),
430
+ workflows: named(set.workflows),
431
+ userGroups: named(set.userGroups),
432
+ }
433
+ }
434
+
435
+ const aliases = (value: unknown): string[] =>
436
+ Array.isArray(value)
437
+ ? [...new Set(value.filter((v): v is string => typeof v === 'string' && v.trim() !== ''))]
438
+ : []
439
+
440
+ /** Picks as a request sends them, keeping only lists of names. */
441
+ export function schemaPicksOf(body: Record<string, unknown>): BundleSchemaPicks {
442
+ return {
443
+ forms: aliases(body.forms),
444
+ workflows: aliases(body.workflows),
445
+ userGroups: aliases(body.userGroups),
446
+ excluded: aliases(body.excluded),
447
+ }
448
+ }
449
+
450
+ /** What a set of picks carries, against the site's files as they stand. */
451
+ export function carriedSchemaPicks(schemaDir: string, picks: BundleSchemaPicks) {
452
+ return carriedPicks(declaredSet(schemaDir), picks)
453
+ }
454
+
455
+ /** A created bundle's forms, workflows and user groups, or undefined when it is gone. */
456
+ export async function readSchemaPicks(db: Db, id: string): Promise<BundleSchemaPicks | undefined> {
457
+ const bundles = new BundleRepository(db)
458
+ return (await bundles.byId(id)) ? bundles.schemaPicks(id) : undefined
459
+ }
460
+
461
+ export async function writeSchemaPicks(
462
+ db: Db,
463
+ id: string,
464
+ body: Record<string, unknown>,
465
+ ): Promise<BundleSchemaPicks | undefined> {
466
+ const picks = schemaPicksOf(body)
467
+ return (await new BundleRepository(db).setSchemaPicks(id, picks)) ? picks : undefined
468
+ }
@@ -4,6 +4,7 @@
4
4
  * a non-admin may only hand out groups and start nodes they hold themselves,
5
5
  * and nobody deletes or disables their own account.
6
6
  */
7
+
7
8
  import type {
8
9
  NodeLookup,
9
10
  Principal,
@@ -51,6 +52,7 @@ import {
51
52
  UserRepository,
52
53
  userState,
53
54
  } from '@crombolo/data'
55
+ import type { SchemaUserGroup } from '@crombolo/schema'
54
56
  import { loadAccess } from '../access.ts'
55
57
  import type { CromboloConfig } from '../config.ts'
56
58
  import type { MediaFileStore } from '../media-files.ts'
@@ -117,6 +119,8 @@ export interface UserPortOptions {
117
119
  >
118
120
  mediaFiles: MediaFileStore
119
121
  nodes: NodeLookup
122
+ /** The groups the site's files declare (story 228). */
123
+ declaredGroups?: () => DeclaredGroups
120
124
  /** Signs a user out everywhere, as a password change set by someone else does. */
121
125
  endSessions: (userId: number) => Promise<void>
122
126
  /** A group save changed what it may do on these pages (story 045: the "rights" notification). */
@@ -665,6 +669,7 @@ export function createUserPorts(
665
669
  adminKey,
666
670
  nodes,
667
671
  onPagePermissionsChanged: options.onPagePermissionsChanged,
672
+ declared: options.declaredGroups,
668
673
  }),
669
674
  userData: createUserDataPort(db),
670
675
  }
@@ -765,21 +770,63 @@ function fromPermissions(permissions: UserGroupInput['permissions']): GranularPe
765
770
  return rows
766
771
  }
767
772
 
773
+ /** The user groups the site's files declare (story 228), and whether a save may write one back. */
774
+ export interface DeclaredGroups {
775
+ /** By lower-case alias. */
776
+ groups: ReadonlyMap<string, SchemaUserGroup>
777
+ /** Development: a save writes the file. Elsewhere the files' fields are read-only. */
778
+ writable: boolean
779
+ write(group: SchemaUserGroup): void
780
+ }
781
+
782
+ /** What a group's file holds, from what the Users section sent. */
783
+ function fileFieldsOf(input: UserGroupInput): SchemaUserGroup {
784
+ return {
785
+ alias: input.alias,
786
+ name: input.name,
787
+ ...(input.description ? { description: input.description } : {}),
788
+ ...(input.icon ? { icon: input.icon } : {}),
789
+ sections: input.sections.map(sectionAppAlias),
790
+ permissions: [...input.fallbackPermissions],
791
+ languages: input.hasAccessToAllLanguages ? 'all' : [...input.languages],
792
+ }
793
+ }
794
+
795
+ const sameMembers = (a: readonly string[], b: readonly string[]) =>
796
+ a.length === b.length && a.every((item) => b.includes(item))
797
+
798
+ /** Whether two groups' file-owned fields agree. */
799
+ function sameFileFields(a: SchemaUserGroup, b: SchemaUserGroup): boolean {
800
+ return (
801
+ a.name === b.name &&
802
+ (a.description ?? '') === (b.description ?? '') &&
803
+ (a.icon ?? '') === (b.icon ?? '') &&
804
+ sameMembers(a.sections, b.sections) &&
805
+ sameMembers(a.permissions, b.permissions) &&
806
+ (a.languages === 'all' || b.languages === 'all'
807
+ ? a.languages === b.languages
808
+ : sameMembers(a.languages, b.languages))
809
+ )
810
+ }
811
+
768
812
  function createUserGroupPort(
769
813
  db: Db,
770
814
  deps: {
771
815
  adminKey: () => Promise<string | undefined>
772
816
  nodes: NodeLookup
773
817
  onPagePermissionsChanged?: UserPortOptions['onPagePermissionsChanged']
818
+ declared?: () => DeclaredGroups
774
819
  },
775
820
  ): UserGroupPort {
821
+ const fileOf = (alias: string) => deps.declared?.().groups.get(alias.toLowerCase())
776
822
  const groups = new UserGroupRepository(db)
777
823
  const users = new UserRepository(db)
778
824
 
779
825
  const toResponse = async (group: Awaited<ReturnType<UserGroupRepository['byKey']>> & object) => ({
780
826
  id: group.key,
781
- isDeletable: !SYSTEM_GROUPS.has(group.alias),
782
- aliasCanBeChanged: !SYSTEM_GROUPS.has(group.alias),
827
+ // A group from the site's files is the files' to rename or remove (story 228).
828
+ isDeletable: !SYSTEM_GROUPS.has(group.alias) && !fileOf(group.alias),
829
+ aliasCanBeChanged: !SYSTEM_GROUPS.has(group.alias) && !fileOf(group.alias),
783
830
  name: group.name,
784
831
  alias: group.alias,
785
832
  description: group.description,
@@ -954,9 +1001,18 @@ function createUserGroupPort(
954
1001
  if (!isMember(principal, group.key)) return 'Forbidden'
955
1002
  const valid = await validate(principal, input, group)
956
1003
  if (valid !== 'Success') return valid
1004
+ // Story 228: its file owns what it is; where it starts is this environment's.
1005
+ const file = fileOf(group.alias)
1006
+ const owned = fileFieldsOf(input)
1007
+ const rewrite = file !== undefined && !sameFileFields(owned, file)
1008
+ if (file && (input.alias !== group.alias || (rewrite && !deps.declared?.().writable)))
1009
+ return 'DeclaredInFiles'
957
1010
  const before = pageVerbs(group)
958
1011
  const saved = await save(input, group.key)
959
- if (saved === 'Success') await announcePermissions(principal, before, group.key)
1012
+ if (saved === 'Success') {
1013
+ if (rewrite) deps.declared?.().write(owned)
1014
+ await announcePermissions(principal, before, group.key)
1015
+ }
960
1016
  return saved
961
1017
  },
962
1018
 
@@ -965,6 +1021,7 @@ function createUserGroupPort(
965
1021
  if (found.length !== new Set(keys.map(normaliseUuid)).size) return 'NotFound'
966
1022
  if (!found.every((g) => isMember(principal, g.key))) return 'Forbidden'
967
1023
  if (found.some((g) => SYSTEM_GROUPS.has(g.alias))) return 'IsSystemUserGroup'
1024
+ if (found.some((g) => fileOf(g.alias))) return 'DeclaredInFiles'
968
1025
  for (const group of found) await groups.delete(group.key)
969
1026
  return 'Success'
970
1027
  },
package/src/config.ts CHANGED
@@ -982,7 +982,7 @@ export function describeDatabase(
982
982
  }
983
983
  }
984
984
 
985
- export const VERSION = '0.40.0'
985
+ export const VERSION = '0.42.1'
986
986
 
987
987
  /** A whole number of seconds from the environment; undefined when unset or not one. */
988
988
  /** A positive number from a setting, else the default. */
package/src/index.ts CHANGED
@@ -94,6 +94,7 @@ export * from './remote-credentials.ts'
94
94
  export * from './remote-media.ts'
95
95
  export * from './routes.ts'
96
96
  export * from './schema.ts'
97
+ export * from './schema-picks.ts'
97
98
  export * from './schema-store.ts'
98
99
  export * from './secrets.ts'
99
100
  export * from './seed/index.ts'
package/src/ports.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  /** Implementations of the Management API ports. */
2
2
 
3
+ import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
4
+ import { join } from 'node:path'
3
5
  import { resolveDeliveryApiSettings } from '@crombolo/api-delivery'
4
6
  import type {
5
7
  CurrentUserPort,
@@ -40,6 +42,7 @@ import {
40
42
  UserRepository,
41
43
  } from '@crombolo/data'
42
44
  import type { PublishedCache } from '@crombolo/render'
45
+ import { fileNameFor, parseUserGroup, type SchemaUserGroup, writeUserGroup } from '@crombolo/schema'
43
46
  import { createNodeLookup } from './access.ts'
44
47
  import { createAuditHistory } from './adapters/audit.ts'
45
48
  import { createBlueprintPort } from './adapters/blueprints.ts'
@@ -70,7 +73,7 @@ import {
70
73
  import { createSearchIndexPort } from './adapters/search-index.ts'
71
74
  import { createTemplateFileStore } from './adapters/template-files.ts'
72
75
  import { createTemplateQueryPort } from './adapters/template-query.ts'
73
- import { avatarUrls, createUserPorts } from './adapters/users.ts'
76
+ import { avatarUrls, createUserPorts, type DeclaredGroups } from './adapters/users.ts'
74
77
  import { createWebhookPort } from './adapters/webhooks.ts'
75
78
  import { backOfficeUrl } from './back-office-url.ts'
76
79
  import { COMPONENT_SNIPPETS } from './component-snippets.ts'
@@ -497,6 +500,7 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
497
500
  },
498
501
  mediaFiles,
499
502
  nodes: createNodeLookup(options.db),
503
+ declaredGroups: () => declaredGroups(options.config),
500
504
  endSessions: async (userId) => {
501
505
  await store.endAllSessionsForUser(userId)
502
506
  },
@@ -617,6 +621,7 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
617
621
  components: deps.components,
618
622
  stylesheets: deps.stylesheets,
619
623
  scripts: deps.scripts,
624
+ schemaDir: options.config.schemaDir,
620
625
  })
621
626
  deps.auditHistory = createAuditHistory(options.db, options.config.auditRetentionDays)
622
627
  if (options.cache) {
@@ -707,3 +712,32 @@ function userTwoFactorPort(service: TwoFactorService): UserTwoFactorPort {
707
712
 
708
713
  export { schemaFiles } from './adapters/schema-files.ts'
709
714
  export { backOfficeUrl, documentEditUrl } from './back-office-url.ts'
715
+
716
+ /**
717
+ * The user groups `schema/user-groups/` declares (story 228), read when a group
718
+ * is saved, and written back where the schema files are writable.
719
+ */
720
+ function declaredGroups(
721
+ config: Pick<CromboloConfig, 'schemaDir' | 'schemaWritable'>,
722
+ ): DeclaredGroups {
723
+ const dir = join(config.schemaDir, 'user-groups')
724
+ const groups = new Map<string, SchemaUserGroup>()
725
+ const fileOf = new Map<string, string>()
726
+ if (existsSync(dir))
727
+ for (const name of readdirSync(dir).filter((file) => file.endsWith('.toml'))) {
728
+ const parsed = parseUserGroup(name, readFileSync(join(dir, name), 'utf8'))
729
+ if (!parsed.value) continue
730
+ groups.set(parsed.value.alias.toLowerCase(), parsed.value)
731
+ fileOf.set(parsed.value.alias.toLowerCase(), name)
732
+ }
733
+ return {
734
+ groups,
735
+ writable: config.schemaWritable,
736
+ write(group) {
737
+ mkdirSync(dir, { recursive: true })
738
+ // Back into the file it came from, whatever that file is called.
739
+ const name = fileOf.get(group.alias.toLowerCase()) ?? fileNameFor(group.alias)
740
+ writeFileSync(join(dir, name), writeUserGroup(group))
741
+ },
742
+ }
743
+ }
@@ -0,0 +1,87 @@
1
+ /**
2
+ * What a created bundle carries of the site's forms, approval workflows and
3
+ * user groups (story 226): what its author picked, and what those bring. A
4
+ * workflow brings the document types it covers and the groups its stages
5
+ * name; a form brings the document type its "save as content" step creates.
6
+ * What its author unticked stays out. docs/bundles.md, "The Bundle Editor".
7
+ */
8
+ import { readFileSync } from 'node:fs'
9
+ import { relative, sep } from 'node:path'
10
+ import type { BundleSchemaPicks } from '@crombolo/data'
11
+ import type { LoadedSchema, SchemaSet } from '@crombolo/schema'
12
+ import type { BundleFile } from '@crombolo/transfer'
13
+
14
+ export type SchemaPickKind = 'form' | 'workflow' | 'userGroup' | 'documentType'
15
+
16
+ /** One thing a bundle carries, and why: picked, or brought by a pick. */
17
+ export interface CarriedPick {
18
+ kind: SchemaPickKind
19
+ alias: string
20
+ /** Absent for what was picked; the pick that brought it, otherwise. */
21
+ for?: { kind: SchemaPickKind; alias: string; name: string }
22
+ /** Brought by a pick and unticked: it is not carried. */
23
+ excluded?: boolean
24
+ }
25
+
26
+ const id = (kind: SchemaPickKind, alias: string) => `${kind}:${alias}`.toLowerCase()
27
+
28
+ /** Everything the picks carry, and what they would have brought and were unticked. Pure. */
29
+ export function carriedPicks(set: SchemaSet, picks: BundleSchemaPicks): CarriedPick[] {
30
+ const out: CarriedPick[] = []
31
+ const seen = new Set<string>()
32
+ const excluded = new Set(picks.excluded.map((entry) => entry.toLowerCase()))
33
+ const add = (pick: CarriedPick) => {
34
+ const key = id(pick.kind, pick.alias)
35
+ if (seen.has(key)) return
36
+ seen.add(key)
37
+ out.push(pick.for && excluded.has(key) ? { ...pick, excluded: true } : pick)
38
+ }
39
+ for (const alias of picks.forms) add({ kind: 'form', alias })
40
+ for (const alias of picks.workflows) add({ kind: 'workflow', alias })
41
+ for (const alias of picks.userGroups) add({ kind: 'userGroup', alias })
42
+ for (const alias of picks.workflows) {
43
+ const workflow = (set.workflows ?? []).find(
44
+ (w) => w.alias.toLowerCase() === alias.toLowerCase(),
45
+ )
46
+ if (!workflow) continue
47
+ const by = { kind: 'workflow' as const, alias: workflow.alias, name: workflow.name }
48
+ for (const type of workflow.appliesTo.contentTypes)
49
+ add({ kind: 'documentType', alias: type, for: by })
50
+ for (const stage of workflow.stages)
51
+ for (const group of stage.approvers) add({ kind: 'userGroup', alias: group, for: by })
52
+ }
53
+ for (const alias of picks.forms) {
54
+ const form = (set.forms ?? []).find((f) => f.alias.toLowerCase() === alias.toLowerCase())
55
+ if (!form) continue
56
+ const by = { kind: 'form' as const, alias: form.alias, name: form.name }
57
+ for (const step of form.workflows)
58
+ if (step.type === 'saveAsContent' && typeof step.settings['content-type'] === 'string')
59
+ add({ kind: 'documentType', alias: step.settings['content-type'], for: by })
60
+ }
61
+ return out
62
+ }
63
+
64
+ const FILE_KEY: Record<SchemaPickKind, (alias: string) => string> = {
65
+ form: (alias) => `form:${alias}`,
66
+ workflow: (alias) => `workflow:${alias}`,
67
+ userGroup: (alias) => `user-group:${alias}`,
68
+ documentType: (alias) => alias,
69
+ }
70
+
71
+ /** The site's own files for what is carried, at their `schema/` paths. */
72
+ export function schemaPickFiles(
73
+ loaded: Pick<LoadedSchema, 'files'>,
74
+ schemaDir: string,
75
+ carried: readonly CarriedPick[],
76
+ read: (file: string) => string = (file) => readFileSync(file, 'utf8'),
77
+ ): BundleFile[] {
78
+ const files: BundleFile[] = []
79
+ for (const pick of carried) {
80
+ if (pick.excluded) continue
81
+ const file = loaded.files.get(FILE_KEY[pick.kind](pick.alias))
82
+ if (!file?.startsWith(schemaDir)) continue
83
+ const rel = relative(schemaDir, file).split(sep).join('/')
84
+ files.push({ path: `schema/${rel}`, text: read(file) })
85
+ }
86
+ return files
87
+ }
@@ -321,11 +321,30 @@ export async function compileSeed(db: Db, config: CromboloConfig): Promise<SeedB
321
321
  case 'Umbraco.Slider':
322
322
  return typeof raw === 'number' ? { ok: true, value: raw } : fail('a number is a number')
323
323
  case 'Umbraco.DateTime':
324
- case 'Umbraco.DateTimeWithTimeZone':
325
- if (raw instanceof Date) return { ok: true, value: raw.toISOString() }
326
- return typeof raw === 'string' && !Number.isNaN(new Date(raw).getTime())
327
- ? { ok: true, value: raw }
328
- : fail('a date is a TOML date or an ISO 8601 string')
324
+ case 'Umbraco.DateTimeWithTimeZone': {
325
+ // Bun's TOML gives a Temporal value (a PlainDate, an Instant) for a TOML
326
+ // date, which writes itself as ISO 8601.
327
+ const text =
328
+ raw instanceof Date
329
+ ? raw.toISOString()
330
+ : isTemporalDate(raw)
331
+ ? String(raw)
332
+ : typeof raw === 'string'
333
+ ? raw
334
+ : undefined
335
+ const at = text === undefined ? Number.NaN : new Date(text).getTime()
336
+ if (text === undefined || Number.isNaN(at))
337
+ return fail('a date is a TOML date or an ISO 8601 string')
338
+ // A date picker stores Umbraco's wall clock, as a save does, so a seed
339
+ // exported and applied again is unchanged; one with a zone keeps ISO.
340
+ return {
341
+ ok: true,
342
+ value:
343
+ editor === 'Umbraco.DateTime'
344
+ ? new Date(at).toISOString().slice(0, 19).replace('T', ' ')
345
+ : text,
346
+ }
347
+ }
329
348
  case 'Umbraco.Tags':
330
349
  return list(raw).every((tag) => typeof tag === 'string')
331
350
  ? { ok: true, value: list(raw) }
@@ -746,3 +765,10 @@ export async function compileSeed(db: Db, config: CromboloConfig): Promise<SeedB
746
765
  })
747
766
  return { findings, set, blobs, files, counts }
748
767
  }
768
+
769
+ /** A TOML date as Bun's parser gives it: a Temporal value whose ISO form is a date. */
770
+ function isTemporalDate(raw: unknown): boolean {
771
+ if (typeof raw !== 'object' || raw === null || raw instanceof Date) return false
772
+ const text = String(raw)
773
+ return /^\d{4}-\d{2}-\d{2}/.test(text) && !Number.isNaN(new Date(text).getTime())
774
+ }
package/src/server.ts CHANGED
@@ -130,7 +130,15 @@ import type { Server } from 'bun'
130
130
  import { createNodeLookup, loadAccess } from './access.ts'
131
131
  import { ACTION_FLASH_COOKIE, actionRegistry, actionRoutes } from './actions.ts'
132
132
  import { createAuditHost, createAuditSink, pluginAuditPlan, recordAudit } from './adapters/audit.ts'
133
- import { readCreatedBundlePackage, writeCreatedBundlePackage } from './adapters/bundles.ts'
133
+ import {
134
+ carriedSchemaPicks,
135
+ readCreatedBundlePackage,
136
+ readSchemaPicks,
137
+ schemaPickChoices,
138
+ schemaPicksOf,
139
+ writeCreatedBundlePackage,
140
+ writeSchemaPicks,
141
+ } from './adapters/bundles.ts'
134
142
  import { createPublishedContentSource, loadDraftNode } from './adapters/documents.ts'
135
143
  import type { Approvals } from './approvals.ts'
136
144
  import { handleApprovalsApi } from './approvals-api.ts'
@@ -1729,6 +1737,28 @@ export async function createServer(config: CromboloConfig = loadConfig()): Promi
1729
1737
  }
1730
1738
  }
1731
1739
 
1740
+ // A created bundle's forms, workflows and user groups (story 226): the
1741
+ // site's files to choose from, what a choice brings, and the choice.
1742
+ if (action === 'schema' && request.method === 'GET')
1743
+ return Response.json(schemaPickChoices(config.schemaDir))
1744
+ if (action === 'schema/carried' && request.method === 'POST') {
1745
+ const body = (await request.json().catch(() => ({}))) as Record<string, unknown>
1746
+ return Response.json({ carried: carriedSchemaPicks(config.schemaDir, schemaPicksOf(body)) })
1747
+ }
1748
+ const picked = /^created\/([0-9a-f-]{36})\/schema$/i.exec(action)
1749
+ if (picked) {
1750
+ const id = picked[1] as string
1751
+ if (request.method === 'GET') {
1752
+ const found = await readSchemaPicks(db, id)
1753
+ return found ? Response.json(found) : new Response('Not Found', { status: 404 })
1754
+ }
1755
+ if (request.method === 'PUT') {
1756
+ const body = (await request.json().catch(() => ({}))) as Record<string, unknown>
1757
+ const saved = await writeSchemaPicks(db, id, body)
1758
+ return saved ? Response.json(saved) : new Response('Not Found', { status: 404 })
1759
+ }
1760
+ }
1761
+
1732
1762
  if (action === 'installed' && request.method === 'GET') {
1733
1763
  return Response.json({
1734
1764
  installs: config.runtimeInstalls,
package/src/status.ts CHANGED
@@ -113,13 +113,13 @@ async function contentCounts(db: Db): Promise<SiteStatus['content']> {
113
113
  }
114
114
  }
115
115
 
116
- /** The vendored client's version, which is a fact about this deployment too. */
116
+ /** The Umbraco release the vendored client was built from, which is a fact about this deployment too. */
117
117
  export function backofficeVersion(): string | undefined {
118
118
  for (const base of [join(import.meta.dir, '..', '..'), process.cwd()]) {
119
- const file = join(base, 'backoffice-dist', 'package.json')
119
+ const file = join(base, 'backoffice-dist', 'dist', 'VERSION')
120
120
  if (!existsSync(file)) continue
121
121
  try {
122
- return (JSON.parse(readFileSync(file, 'utf8')) as { version?: string }).version
122
+ return readFileSync(file, 'utf8').trim().split('@').pop() || undefined
123
123
  } catch {
124
124
  return undefined
125
125
  }