@crombolo/server 0.63.0 → 0.65.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.
@@ -29,7 +29,7 @@ import {
29
29
  type NodeSchemaState,
30
30
  } from '@crombolo/data'
31
31
  import type { EmailField, EmailProps, EmailRenderResult } from '@crombolo/render'
32
- import type { EmailAttachment, EmailPort } from './email.ts'
32
+ import { type EmailAttachment, type EmailPort, emailReady } from './email.ts'
33
33
  import { htmlToText } from './email-text.ts'
34
34
  import type { FormWorkflowTypeDefinition } from './form-types.ts'
35
35
  import { logger } from './logging.ts'
@@ -234,7 +234,7 @@ async function sendEmail(
234
234
  context: WorkflowContext,
235
235
  deps: WorkflowDeps,
236
236
  ): Promise<WorkflowResult> {
237
- if (!deps.email)
237
+ if (!emailReady(deps.email))
238
238
  return {
239
239
  ok: false,
240
240
  // Retrying cannot help: this is configuration, not weather.
@@ -638,7 +638,7 @@ async function runBundleWorkflow(
638
638
  attempt: context.attempt ?? 1,
639
639
  fetch: (input, init) => (deps.fetch ?? fetch)(input, { signal, ...init }),
640
640
  sendEmail: async (message) =>
641
- deps.email
641
+ emailReady(deps.email)
642
642
  ? deps.email.send(message)
643
643
  : { ok: false, error: 'This site has no e-mail set up.' },
644
644
  log: {
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Story 335: an extension granted Acts as you or Unrestricted keeps that only
3
3
  * while someone this site trusts vouches for it. Checked at every start, before
4
- * extensions run, so an upgrade, or a signer taken off Trusted signers, switches
5
- * off what no longer qualifies.
4
+ * extensions run, so an upgrade switches off what no longer qualifies; and as a
5
+ * signer is taken off Trusted signers, so what it vouched for stops at once.
6
6
  */
7
7
  import { type ExtensionRegistry, isUpperLevel, levelOf } from '@crombolo/backoffice-host/registry'
8
8
  import type { Db } from '@crombolo/data'
@@ -27,6 +27,8 @@ export async function switchOffUntrusted(
27
27
  config: CromboloConfig,
28
28
  extensions: ExtensionRegistry,
29
29
  grants: Pick<BundleGrants, 'granted' | 'isOn' | 'state' | 'forget'>,
30
+ /** At start, or because a signer was just taken off the list. */
31
+ when: 'start' | 'untrusted' = 'start',
30
32
  ): Promise<string[]> {
31
33
  const marketplace = createMarketplace({
32
34
  registry: config.npmRegistry,
@@ -56,8 +58,8 @@ export async function switchOffUntrusted(
56
58
  action: 'Disable',
57
59
  entityType: 'Bundle',
58
60
  entityName: `${pkg.packageName}@${pkg.version}`,
59
- detail: `switched off at start: it acts as you or runs unrestricted, and is ${why}; it needs granting again`,
60
- source: 'boot',
61
+ detail: `switched off ${when === 'start' ? 'at start' : 'as its signer was taken off Trusted signers'}: it acts as you or runs unrestricted, and is ${why}; it needs granting again`,
62
+ source: when === 'start' ? 'boot' : 'request',
61
63
  userKey: null,
62
64
  userName: SWITCHED_OFF_BY,
63
65
  ipAddress: null,
package/src/index.ts CHANGED
@@ -61,6 +61,7 @@ export * from './email-notice.ts'
61
61
  export * from './email-postmark.ts'
62
62
  export * from './email-resend.ts'
63
63
  export * from './email-ses.ts'
64
+ export * from './email-settings.ts'
64
65
  export * from './email-text.ts'
65
66
  export {
66
67
  activityCsv,
@@ -135,6 +136,7 @@ export * from './routes.ts'
135
136
  export * from './schema.ts'
136
137
  export * from './schema-picks.ts'
137
138
  export * from './schema-store.ts'
139
+ export * from './schema-transfer.ts'
138
140
  export * from './secrets.ts'
139
141
  export * from './seed/index.ts'
140
142
  export * from './seo.ts'
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,8 +122,8 @@ function createServerPort(config: CromboloConfig, canSendUserLinks: boolean): Se
122
122
  version: VERSION,
123
123
  assemblyVersion: VERSION,
124
124
  baseUtcOffset: '00:00:00',
125
- // Story 337: the back office keeps templates read-only in production mode, so the mode follows the switch.
126
- runtimeMode: config.contentFilesReadOnly ? 'Production' : 'BackofficeDevelopment',
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',
127
127
  }),
128
128
  }
129
129
  }
@@ -350,6 +350,7 @@ export function resolveUserLinkSender(
350
350
  // e-mail must behave that way in development too, or the difference between
351
351
  // environments is only discovered in production.
352
352
  if (config.email === null) return undefined
353
+ if (email?.provider === 'none') return config.development ? logUserLink : undefined
353
354
  if (email?.provider === 'log') return logUserLink
354
355
  if (email) return userLinkViaEmail(email, config.siteName)
355
356
  return config.development ? logUserLink : undefined
@@ -429,9 +430,10 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
429
430
  // `createServer` resolves the port and passes it in; a test calling this
430
431
  // directly gets the same answer from the same config.
431
432
  const email = options.email ?? resolveEmailPort(options.config)
432
- 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)
433
435
  const deps: ManagementApiDeps = {
434
- server: createServerPort(options.config, Boolean(sendUserLink)),
436
+ server: createServerPort(options.config, () => Boolean(sendUserLink())),
435
437
  preview: createPreviewPort(options.config, options.previewInApp),
436
438
  // Without an app to preview in, Preview in app contributes no extension.
437
439
  manifests: createManifestPort(
@@ -477,7 +479,7 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
477
479
  // through the partial-view file API because that one is path-addressed and
478
480
  // already understands folders; the template API is id-addressed and cannot
479
481
  // express a folder at all.
480
- const readOnly = options.config.contentFilesReadOnly
482
+ const readOnly = contentFilesLocked(options.config)
481
483
  deps.components = createComponentsPort(options.config.componentsDir, readOnly)
482
484
  deps.componentSnippets = COMPONENT_SNIPPETS
483
485
  deps.stylesheets = createFileSystemPort(options.config.stylesheetsDir, {
@@ -506,10 +508,10 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
506
508
  deps.users = createUserItemPort(options.db)
507
509
  const store = new AuthStore(options.db)
508
510
  const userPorts = createUserPorts(options.db, {
509
- config: {
510
- ...options.config,
511
- sendUserLink,
512
- },
511
+ config: Object.defineProperty({ ...options.config }, 'sendUserLink', {
512
+ get: sendUserLink,
513
+ enumerable: true,
514
+ }),
513
515
  mediaFiles,
514
516
  nodes: createNodeLookup(options.db),
515
517
  declaredGroups: () => declaredGroups(options.config),
@@ -575,7 +577,7 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
575
577
  componentFiles: createTemplateFileStore(
576
578
  options.config.componentsDir,
577
579
  options.onViewsChange,
578
- options.config.contentFilesReadOnly,
580
+ contentFilesLocked(options.config),
579
581
  ),
580
582
  })
581
583
  deps.mediaTypes = createContentTypePort(options.db, schemaFiles(options.config), {
@@ -592,7 +594,7 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
592
594
  createTemplateFileStore(
593
595
  options.config.componentsDir,
594
596
  options.onViewsChange,
595
- options.config.contentFilesReadOnly,
597
+ contentFilesLocked(options.config),
596
598
  ),
597
599
  )
598
600
  deps.logViewer = createLogViewerPort(options.db, options.config)
@@ -641,7 +643,7 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
641
643
  componentFiles: createTemplateFileStore(
642
644
  options.config.componentsDir,
643
645
  options.onViewsChange,
644
- options.config.contentFilesReadOnly,
646
+ contentFilesLocked(options.config),
645
647
  ),
646
648
  mediaStore: mediaFiles.store,
647
649
  components: deps.components,
@@ -685,7 +687,7 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
685
687
  },
686
688
  operations.tracker,
687
689
  options.config.siteDir,
688
- Boolean(email),
690
+ () => emailReady(email),
689
691
  )
690
692
  if (deps.documents && operations) {
691
693
  deps.approvals = operations.approvals
package/src/routes.ts CHANGED
@@ -130,10 +130,12 @@ export function createRoutes<Member extends RouteMember>(
130
130
  declared: readonly DeclaredRoute[],
131
131
  deps: RouteDeps<Member>,
132
132
  ) {
133
- const compiled = declared.map((entry) => ({
133
+ const compile = (entry: DeclaredRoute) => ({
134
134
  ...entry,
135
135
  pattern: new URLPattern({ pathname: entry.route.path }),
136
- }))
136
+ })
137
+ const routes = [...declared]
138
+ const compiled = routes.map(compile)
137
139
  const defaultLimiter =
138
140
  deps.defaultPerMinute > 0
139
141
  ? new RateLimiter({ max: deps.defaultPerMinute, windowMs: MINUTE, now: deps.now })
@@ -433,9 +435,26 @@ export function createRoutes<Member extends RouteMember>(
433
435
  }
434
436
 
435
437
  return {
436
- routes: declared,
438
+ routes: routes as readonly DeclaredRoute[],
437
439
  match,
438
440
  invoke,
441
+ /**
442
+ * Adds routes while the server runs (story 346), checked against those
443
+ * already there; answers why they cannot be, and adds none then.
444
+ */
445
+ add(entries: readonly DeclaredRoute[]): string[] {
446
+ const problems = siteRouteProblems([...routes, ...entries], deps.backOfficePath)
447
+ if (problems.length > 0) return problems
448
+ routes.push(...entries)
449
+ compiled.push(...entries.map(compile))
450
+ return []
451
+ },
452
+ /** Takes out every route one owner declared. */
453
+ remove(owner: string): void {
454
+ for (const list of [routes, compiled])
455
+ for (let at = list.length - 1; at >= 0; at--)
456
+ if (list[at]?.owner === owner) list.splice(at, 1)
457
+ },
439
458
  /** A site request a route answers, or undefined for content finding to have it. */
440
459
  async handle(request: Request, url: URL): Promise<Response | undefined> {
441
460
  const found = match(url.pathname)