@crombolo/server 0.62.0 → 0.64.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/src/ports.ts CHANGED
@@ -78,9 +78,9 @@ import { avatarUrls, createUserPorts, type DeclaredGroups } from './adapters/use
78
78
  import { createWebhookPort } from './adapters/webhooks.ts'
79
79
  import { backOfficeUrl } from './back-office-url.ts'
80
80
  import { COMPONENT_SNIPPETS } from './component-snippets.ts'
81
- import { type CromboloConfig, type UserLinkSender, VERSION } from './config.ts'
81
+ import { type CromboloConfig, contentFilesLocked, type UserLinkSender, VERSION } from './config.ts'
82
82
  import type { ContentNotifier } from './content-notifications.ts'
83
- import { type EmailPort, resolveEmailPort } from './email.ts'
83
+ import { type EmailPort, emailReady, resolveEmailPort } from './email.ts'
84
84
  import { createFileIntake } from './file-intake.ts'
85
85
  import { createLogViewerPort } from './log-viewer.ts'
86
86
  import { logger } from './logging.ts'
@@ -105,14 +105,14 @@ const CULTURES = [
105
105
  { name: 'sv-SE', englishName: 'Swedish (Sweden)' },
106
106
  ]
107
107
 
108
- function createServerPort(config: CromboloConfig, canSendUserLinks: boolean): ServerPort {
108
+ function createServerPort(config: CromboloConfig, canSendUserLinks: () => boolean): ServerPort {
109
109
  return {
110
110
  // Story 080 derives this from migration state; until then the site is always up.
111
111
  status: () => ({ serverStatus: 'Run' }),
112
112
  configuration: () => ({
113
113
  // Reported false when no link could be delivered, so the client does not
114
114
  // offer a reset that goes nowhere. `email.ts` has the reason.
115
- allowPasswordReset: config.allowPasswordReset && canSendUserLinks,
115
+ allowPasswordReset: config.allowPasswordReset && canSendUserLinks(),
116
116
  versionCheckPeriod: config.versionCheckPeriod,
117
117
  allowLocalLogin: config.allowLocalLogin,
118
118
  umbracoCssPath: config.umbracoCssPath,
@@ -122,7 +122,8 @@ function createServerPort(config: CromboloConfig, canSendUserLinks: boolean): Se
122
122
  version: VERSION,
123
123
  assemblyVersion: VERSION,
124
124
  baseUtcOffset: '00:00:00',
125
- runtimeMode: config.development ? 'BackofficeDevelopment' : 'Production',
125
+ // Stories 337, 343: the back office keeps templates read-only in its Production mode, so it follows the content mode.
126
+ runtimeMode: contentFilesLocked(config) ? 'Production' : 'BackofficeDevelopment',
126
127
  }),
127
128
  }
128
129
  }
@@ -349,6 +350,7 @@ export function resolveUserLinkSender(
349
350
  // e-mail must behave that way in development too, or the difference between
350
351
  // environments is only discovered in production.
351
352
  if (config.email === null) return undefined
353
+ if (email?.provider === 'none') return config.development ? logUserLink : undefined
352
354
  if (email?.provider === 'log') return logUserLink
353
355
  if (email) return userLinkViaEmail(email, config.siteName)
354
356
  return config.development ? logUserLink : undefined
@@ -428,9 +430,10 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
428
430
  // `createServer` resolves the port and passes it in; a test calling this
429
431
  // directly gets the same answer from the same config.
430
432
  const email = options.email ?? resolveEmailPort(options.config)
431
- const sendUserLink = resolveUserLinkSender(options.config, email)
433
+ // Asked each time: e-mail set up in Settings starts and stops without a restart (story 340).
434
+ const sendUserLink = () => resolveUserLinkSender(options.config, email)
432
435
  const deps: ManagementApiDeps = {
433
- server: createServerPort(options.config, Boolean(sendUserLink)),
436
+ server: createServerPort(options.config, () => Boolean(sendUserLink())),
434
437
  preview: createPreviewPort(options.config, options.previewInApp),
435
438
  // Without an app to preview in, Preview in app contributes no extension.
436
439
  manifests: createManifestPort(
@@ -476,10 +479,14 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
476
479
  // through the partial-view file API because that one is path-addressed and
477
480
  // already understands folders; the template API is id-addressed and cannot
478
481
  // express a folder at all.
479
- deps.components = createComponentsPort(options.config.componentsDir)
482
+ const readOnly = contentFilesLocked(options.config)
483
+ deps.components = createComponentsPort(options.config.componentsDir, readOnly)
480
484
  deps.componentSnippets = COMPONENT_SNIPPETS
481
- deps.stylesheets = createFileSystemPort(options.config.stylesheetsDir, { extension: '.css' })
482
- deps.scripts = createFileSystemPort(options.config.scriptsDir, { extension: '.js' })
485
+ deps.stylesheets = createFileSystemPort(options.config.stylesheetsDir, {
486
+ extension: '.css',
487
+ readOnly,
488
+ })
489
+ deps.scripts = createFileSystemPort(options.config.scriptsDir, { extension: '.js', readOnly })
483
490
  if (options.db) {
484
491
  const dynamicRoots = new DynamicRootRepository(options.db)
485
492
  deps.dynamicRoots = { resolve: (query) => dynamicRoots.resolve(query) }
@@ -501,10 +508,10 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
501
508
  deps.users = createUserItemPort(options.db)
502
509
  const store = new AuthStore(options.db)
503
510
  const userPorts = createUserPorts(options.db, {
504
- config: {
505
- ...options.config,
506
- sendUserLink,
507
- },
511
+ config: Object.defineProperty({ ...options.config }, 'sendUserLink', {
512
+ get: sendUserLink,
513
+ enumerable: true,
514
+ }),
508
515
  mediaFiles,
509
516
  nodes: createNodeLookup(options.db),
510
517
  declaredGroups: () => declaredGroups(options.config),
@@ -567,7 +574,11 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
567
574
  })
568
575
  deps.contentTypes = createContentTypePort(options.db, schemaFiles(options.config), {
569
576
  nodeState: options.schema?.nodeState,
570
- componentFiles: createTemplateFileStore(options.config.componentsDir, options.onViewsChange),
577
+ componentFiles: createTemplateFileStore(
578
+ options.config.componentsDir,
579
+ options.onViewsChange,
580
+ contentFilesLocked(options.config),
581
+ ),
571
582
  })
572
583
  deps.mediaTypes = createContentTypePort(options.db, schemaFiles(options.config), {
573
584
  nodeState: options.schema?.nodeState,
@@ -580,7 +591,11 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
580
591
  deps.dataTypes = createDataTypePort(options.db, schemaFiles(options.config))
581
592
  deps.templates = createTemplatePort(
582
593
  options.db,
583
- createTemplateFileStore(options.config.componentsDir, options.onViewsChange),
594
+ createTemplateFileStore(
595
+ options.config.componentsDir,
596
+ options.onViewsChange,
597
+ contentFilesLocked(options.config),
598
+ ),
584
599
  )
585
600
  deps.logViewer = createLogViewerPort(options.db, options.config)
586
601
  deps.modelsBuilder = createModelsBuilderPort(options.config)
@@ -625,7 +640,11 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
625
640
  nodeId: options.config.nodeId,
626
641
  marketplaceUrl: options.config.marketplaceUrl,
627
642
  secretKey: options.config.secretKey,
628
- componentFiles: createTemplateFileStore(options.config.componentsDir, options.onViewsChange),
643
+ componentFiles: createTemplateFileStore(
644
+ options.config.componentsDir,
645
+ options.onViewsChange,
646
+ contentFilesLocked(options.config),
647
+ ),
629
648
  mediaStore: mediaFiles.store,
630
649
  components: deps.components,
631
650
  stylesheets: deps.stylesheets,
@@ -668,7 +687,7 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
668
687
  },
669
688
  operations.tracker,
670
689
  options.config.siteDir,
671
- Boolean(email),
690
+ () => emailReady(email),
672
691
  )
673
692
  if (deps.documents && operations) {
674
693
  deps.approvals = operations.approvals
package/src/provenance.ts CHANGED
@@ -122,6 +122,11 @@ export interface ProvenanceResult {
122
122
  package?: { name: string; version: string }
123
123
  /** Why a signature was not accepted, in words a person can act on. */
124
124
  reason?: string
125
+ /**
126
+ * Whether its signer is on this site's Trusted signers list (story 335), set by
127
+ * whoever asked; only a trusted signer vouches for an upper level.
128
+ */
129
+ trusted?: boolean
125
130
  }
126
131
 
127
132
  /** A package's `provenance.json`, when it has one that reads. */
@@ -296,7 +301,14 @@ export function describeProvenance(result: ProvenanceResult): string {
296
301
  ? `signed by ${result.key.comment || 'a key'} (${result.key.fingerprint})`
297
302
  : undefined
298
303
  const said = [built, key].filter(Boolean).join(', and ')
299
- return `Signed: ${said}`
304
+ // Story 335: said only where someone asked this site's list.
305
+ const trust =
306
+ result.trusted === undefined
307
+ ? ''
308
+ : result.trusted
309
+ ? '; this site trusts its signer'
310
+ : "; this site doesn't trust its signer"
311
+ return `Signed: ${said}${trust}`
300
312
  }
301
313
  case 'unsigned':
302
314
  return 'Not signed'
package/src/remote.ts CHANGED
@@ -55,6 +55,7 @@ import {
55
55
  } from './bundle-install.ts'
56
56
  import {
57
57
  carriesSections,
58
+ componentChanges,
58
59
  migrationChanges,
59
60
  type SectionFile,
60
61
  swappedSections,
@@ -524,6 +525,8 @@ export function createRemote(options: RemoteOptions): Remote {
524
525
  backupTaken: !canBackUp,
525
526
  label: `push from ${by}`,
526
527
  by,
528
+ // Whoever pushed was held to InstallCode when the push was sent (story 336).
529
+ installTemplates: true,
527
530
  })
528
531
  if (!result.runId) {
529
532
  const items = [
@@ -712,8 +715,12 @@ export function createRemote(options: RemoteOptions): Remote {
712
715
  try {
713
716
  const carried = readBundle(dir, config.siteDir).carried
714
717
  structural = carriesSections(carried)
715
- // A bundle's value migrations are code too (story 300).
716
- code = [...codeChanges(planCode(config, carried)), ...migrationChanges(config, carried)]
718
+ // A bundle's value migrations are code too (story 300), and so are its templates (336).
719
+ code = [
720
+ ...codeChanges(planCode(config, carried)),
721
+ ...migrationChanges(config, carried),
722
+ ...componentChanges(config, carried),
723
+ ]
717
724
  } catch (error) {
718
725
  return problem(400, {
719
726
  code: 'not-a-bundle',
@@ -745,9 +752,7 @@ export function createRemote(options: RemoteOptions): Remote {
745
752
  return problem(409, {
746
753
  code: 'installs-elsewhere',
747
754
  title: 'This site does not install code while it runs',
748
- detail:
749
- config.installsElsewhere?.message ??
750
- "Add the bundle's code to the site and deploy it the way this site is deployed.",
755
+ detail: 'Installing code while the site runs is turned off on this site.',
751
756
  })
752
757
  if (code.length > 0 && !may(principal, RemotePermissions.InstallCode))
753
758
  return problem(403, {
@@ -1026,9 +1031,9 @@ export function createRemote(options: RemoteOptions): Remote {
1026
1031
  title: "That run brought an extension's content",
1027
1032
  detail: `It is put back by uninstalling ${run.packageName ?? 'the extension'}, with its content reverted.`,
1028
1033
  })
1029
- // A run that installed code changes code back, which needs what it did.
1034
+ // A run that installed code or changed templates changes code back, which needs what it did.
1030
1035
  if (
1031
- installedCode(config, runId) &&
1036
+ (installedCode(config, runId) || swappedSections(config, runId).includes('components')) &&
1032
1037
  (!atLeast('all') ||
1033
1038
  !may(principal, RemotePermissions.ApplyStructure) ||
1034
1039
  !may(principal, RemotePermissions.InstallCode))
@@ -1442,10 +1447,12 @@ export function createRemote(options: RemoteOptions): Remote {
1442
1447
  pull: atLeast('read') && may(principal, RemotePermissions.Pull),
1443
1448
  pullFull: atLeast('read') && may(principal, RemotePermissions.PullFull),
1444
1449
  // A whole-site push changes structure, so it needs that right and the top level.
1450
+ // A push replaces templates too, which are code (story 336).
1445
1451
  push:
1446
1452
  atLeast('all') &&
1447
1453
  mayChange(principal) &&
1448
- may(principal, RemotePermissions.ApplyStructure),
1454
+ may(principal, RemotePermissions.ApplyStructure) &&
1455
+ may(principal, RemotePermissions.InstallCode),
1449
1456
  apply: atLeast('content') && mayChange(principal),
1450
1457
  applyStructure:
1451
1458
  atLeast('all') &&
@@ -1518,6 +1525,14 @@ export function createRemote(options: RemoteOptions): Remote {
1518
1525
  detail:
1519
1526
  "A push replaces the site's content types, views and code, which needs Crombolo.Remote.ApplyStructure.",
1520
1527
  })
1528
+ // Its templates are code, and what a push will change is not known until it is uploaded (story 336).
1529
+ if (pushing && mayChange(principal) && !may(principal, RemotePermissions.InstallCode))
1530
+ return problem(403, {
1531
+ code: 'forbidden-code',
1532
+ title: 'You may not push a whole site here',
1533
+ detail:
1534
+ 'A push replaces the site\'s templates, which are code, so it needs "Install code on this site" (Crombolo.Remote.InstallCode).',
1535
+ })
1521
1536
  if (what === 'bundles' && request.method === 'PUT') return applyBundle(request, principal)
1522
1537
  if (what === 'runs' && request.method === 'GET') return listRuns(url, principal)
1523
1538
  const revert = /^runs\/([0-9a-f-]{36})\/revert$/.exec(what)