@crombolo/server 0.63.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.
@@ -0,0 +1,394 @@
1
+ /**
2
+ * E-mail set up in Settings (story 340): kept in `key_value`, its key sealed by
3
+ * `CROMBOLO_SECRET_KEY`, and used only when the site's configuration sets no
4
+ * e-mail. The configuration wins, because whoever sets e-mail decides where
5
+ * password-reset links go. docs/configuration.md, "E-mail".
6
+ */
7
+ import { isValidEmail } from '@crombolo/core'
8
+ import { type Db, now } from '@crombolo/data'
9
+ import { recordAudit } from './adapters/audit.ts'
10
+ import {
11
+ type EmailAvailability,
12
+ type EmailMessage,
13
+ type EmailPort,
14
+ emailAvailability,
15
+ emailFromEnvironment,
16
+ logEmail,
17
+ resolveEmailPort,
18
+ } from './email.ts'
19
+ import { logger } from './logging.ts'
20
+ import { openSecret, sealSecret, usableSecretKey } from './secrets.ts'
21
+
22
+ const KEY = 'crombolo:email'
23
+ /** How stale another node's copy may be before it reads again. */
24
+ export const EMAIL_SETTINGS_TTL_MS = 30_000
25
+
26
+ export const STORED_PROVIDERS = ['resend', 'postmark', 'ses', 'custom'] as const
27
+ export type StoredProvider = (typeof STORED_PROVIDERS)[number]
28
+
29
+ interface Stored {
30
+ provider: StoredProvider
31
+ from: string
32
+ fromName?: string
33
+ url?: string
34
+ postmarkStream?: string
35
+ sesRegion?: string
36
+ sesAccessKeyId?: string
37
+ /** The API key, or SES's secret access key. */
38
+ keySealed?: string
39
+ /** Where the key was entered for; it goes nowhere else (as story 305's client secret). */
40
+ keyFor?: string
41
+ }
42
+
43
+ /** What an administrator sends; `key` is set only when a new one is entered. */
44
+ export type EmailSettingsInput = Partial<Omit<Stored, 'keySealed' | 'keyFor'>> & { key?: string }
45
+
46
+ interface Site {
47
+ email?: EmailPort | null
48
+ development?: boolean
49
+ secretKey?: string
50
+ }
51
+
52
+ type Env = Record<string, string | undefined>
53
+
54
+ /** `config` when the site's configuration sets e-mail, `off` when it turns it off. */
55
+ export function configuredEmail(config: Site, env: Env = Bun.env): 'config' | 'off' | undefined {
56
+ if (config.email === null) return 'off'
57
+ if (config.email) return 'config'
58
+ const kind = (env.CROMBOLO_EMAIL_PROVIDER ?? '').trim().toLowerCase()
59
+ if (kind === 'none') return 'off'
60
+ return kind ? 'config' : undefined
61
+ }
62
+
63
+ const targetOf = (s: Pick<Stored, 'provider' | 'url' | 'sesAccessKeyId'>) =>
64
+ [s.provider, s.url ?? '', s.sesAccessKeyId ?? ''].join('|')
65
+
66
+ async function read(db: Db): Promise<Stored | undefined> {
67
+ const row = await db.q
68
+ .selectFrom('key_value')
69
+ .select('value')
70
+ .where('key', '=', KEY)
71
+ .executeTakeFirst()
72
+ try {
73
+ return row?.value ? (JSON.parse(row.value) as Stored) : undefined
74
+ } catch {
75
+ return undefined
76
+ }
77
+ }
78
+
79
+ async function write(db: Db, stored: Stored | undefined): Promise<void> {
80
+ if (!stored) {
81
+ await db.q.deleteFrom('key_value').where('key', '=', KEY).execute()
82
+ return
83
+ }
84
+ const value = JSON.stringify(stored)
85
+ const updated = await db.q
86
+ .updateTable('key_value')
87
+ .set({ value, update_date: now(db) })
88
+ .where('key', '=', KEY)
89
+ .returning('key')
90
+ .execute()
91
+ if (updated.length === 0)
92
+ await db.q
93
+ .insertInto('key_value')
94
+ .values({ key: KEY, value, update_date: now(db) })
95
+ .execute()
96
+ }
97
+
98
+ function keyOf(stored: Stored, secretKey: string | undefined): string {
99
+ const key = usableSecretKey(secretKey)
100
+ if (!stored.keySealed || !key || stored.keyFor !== targetOf(stored)) return ''
101
+ try {
102
+ return openSecret(stored.keySealed, key)
103
+ } catch {
104
+ return ''
105
+ }
106
+ }
107
+
108
+ /** The adapter stored settings describe, through the same checks as the environment's. */
109
+ function portOf(
110
+ stored: Stored | undefined,
111
+ secretKey: string | undefined,
112
+ log: { warning(message: string, properties?: Record<string, unknown>): void } = logger('email'),
113
+ ): EmailPort | undefined {
114
+ if (!stored) return undefined
115
+ const key = keyOf(stored, secretKey)
116
+ return emailFromEnvironment(
117
+ {
118
+ CROMBOLO_EMAIL_PROVIDER: stored.provider,
119
+ CROMBOLO_EMAIL_FROM: stored.from,
120
+ CROMBOLO_EMAIL_FROM_NAME: stored.fromName,
121
+ CROMBOLO_EMAIL_URL: stored.url,
122
+ CROMBOLO_EMAIL_POSTMARK_STREAM: stored.postmarkStream,
123
+ CROMBOLO_EMAIL_SES_REGION: stored.sesRegion,
124
+ CROMBOLO_EMAIL_SES_ACCESS_KEY_ID: stored.sesAccessKeyId,
125
+ ...(stored.provider === 'ses'
126
+ ? { CROMBOLO_EMAIL_SES_SECRET_ACCESS_KEY: key }
127
+ : { CROMBOLO_EMAIL_API_KEY: key }),
128
+ },
129
+ log,
130
+ )
131
+ }
132
+
133
+ /** The site's e-mail, read again from Settings as it changes. */
134
+ export interface LiveEmail extends EmailPort {
135
+ /** Reads the settings now, on the node that saved them. */
136
+ refresh(): Promise<void>
137
+ }
138
+
139
+ /**
140
+ * The port a site sends through. The configuration's when it sets e-mail;
141
+ * otherwise one that follows Settings, re-read when older than the TTL, so a
142
+ * change reaches every node without a restart. With nothing set up it reports
143
+ * `none`, or is the console in development.
144
+ */
145
+ export async function siteEmail(
146
+ db: Db,
147
+ config: Site,
148
+ options: { env?: Env; ttlMs?: number } = {},
149
+ ): Promise<EmailPort | undefined> {
150
+ const env = options.env ?? Bun.env
151
+ if (configuredEmail(config, env)) return resolveEmailPort(config, env)
152
+ const ttl = options.ttlMs ?? EMAIL_SETTINGS_TTL_MS
153
+ const fallback = config.development ? logEmail() : undefined
154
+ let current: EmailPort | undefined
155
+ let readAt = 0
156
+ let reading: Promise<void> | undefined
157
+ const load = () => {
158
+ reading ??= read(db)
159
+ .then((stored) => {
160
+ current = portOf(stored, config.secretKey) ?? fallback
161
+ readAt = Date.now()
162
+ })
163
+ .catch(() => {})
164
+ .finally(() => {
165
+ reading = undefined
166
+ })
167
+ return reading
168
+ }
169
+ // A stale copy answers at once while the next read is under way.
170
+ const fresh = () => {
171
+ if (Date.now() - readAt >= ttl) void load()
172
+ return current
173
+ }
174
+ await load()
175
+ const live: LiveEmail = {
176
+ get description() {
177
+ return fresh()?.description ?? 'not set up'
178
+ },
179
+ get provider() {
180
+ return fresh()?.provider ?? 'none'
181
+ },
182
+ async send(message: EmailMessage) {
183
+ if (Date.now() - readAt >= ttl) await load()
184
+ return current
185
+ ? current.send(message)
186
+ : { ok: false as const, error: 'This site has no e-mail set up.' }
187
+ },
188
+ refresh: load,
189
+ }
190
+ return live
191
+ }
192
+
193
+ /** What the card shows: never a key, only whether one is kept. */
194
+ export interface EmailSettingsView {
195
+ /** `config`/`off`: set by the site's configuration, read-only here. */
196
+ source: 'config' | 'off' | 'settings' | 'none'
197
+ provider: string | null
198
+ from: string | null
199
+ fromName: string | null
200
+ url: string | null
201
+ postmarkStream: string | null
202
+ sesRegion: string | null
203
+ sesAccessKeyId: string | null
204
+ keyKept: boolean
205
+ /** Whether a key can be kept at all: the site has a secret key to seal it with. */
206
+ canKeepKeys: boolean
207
+ status: EmailAvailability
208
+ }
209
+
210
+ export interface EmailActor {
211
+ id: string | null
212
+ name: string
213
+ email: string | null
214
+ ipAddress?: string | null
215
+ }
216
+
217
+ export type EmailOutcome = { ok: true } | { ok: false; status: number; message: string }
218
+
219
+ const text = (value: unknown) => (typeof value === 'string' ? value.trim() : '')
220
+
221
+ /** Settings → E-mail, as an administrator uses it. */
222
+ export function createEmailSettings(
223
+ db: Db,
224
+ config: Site,
225
+ options: { port: () => EmailPort | undefined; env?: Env },
226
+ ) {
227
+ const env = options.env ?? Bun.env
228
+ const audit = (actor: EmailActor, action: string, detail: string) =>
229
+ recordAudit(db, {
230
+ category: 'settings',
231
+ action,
232
+ entityType: 'E-mail',
233
+ entityName: 'E-mail',
234
+ detail,
235
+ source: 'request',
236
+ userKey: actor.id,
237
+ userName: actor.name,
238
+ ipAddress: actor.ipAddress ?? null,
239
+ forwardedFor: null,
240
+ })
241
+ const refresh = async () => {
242
+ const port = options.port() as Partial<LiveEmail> | undefined
243
+ await port?.refresh?.()
244
+ }
245
+ const locked = (): EmailOutcome | undefined =>
246
+ configuredEmail(config, env)
247
+ ? {
248
+ ok: false,
249
+ status: 409,
250
+ message: "E-mail is set by the site's configuration, so it can't be changed here.",
251
+ }
252
+ : undefined
253
+
254
+ return {
255
+ async view(): Promise<EmailSettingsView> {
256
+ const status = emailAvailability(options.port())
257
+ const canKeepKeys = Boolean(usableSecretKey(config.secretKey))
258
+ const fixed = configuredEmail(config, env)
259
+ if (fixed) {
260
+ const fromEnv = !config.email && fixed === 'config'
261
+ return {
262
+ source: fixed,
263
+ provider:
264
+ fixed === 'off' ? null : (config.email?.provider ?? text(env.CROMBOLO_EMAIL_PROVIDER)),
265
+ from: fromEnv ? text(env.CROMBOLO_EMAIL_FROM) || null : null,
266
+ fromName: fromEnv ? text(env.CROMBOLO_EMAIL_FROM_NAME) || null : null,
267
+ url: fromEnv ? text(env.CROMBOLO_EMAIL_URL) || null : null,
268
+ postmarkStream: null,
269
+ sesRegion: fromEnv ? text(env.CROMBOLO_EMAIL_SES_REGION) || null : null,
270
+ sesAccessKeyId: null,
271
+ keyKept: false,
272
+ canKeepKeys,
273
+ status,
274
+ }
275
+ }
276
+ const stored = await read(db)
277
+ return {
278
+ source: stored ? 'settings' : 'none',
279
+ provider: stored?.provider ?? null,
280
+ from: stored?.from ?? null,
281
+ fromName: stored?.fromName ?? null,
282
+ url: stored?.url ?? null,
283
+ postmarkStream: stored?.postmarkStream ?? null,
284
+ sesRegion: stored?.sesRegion ?? null,
285
+ sesAccessKeyId: stored?.sesAccessKeyId ?? null,
286
+ keyKept: Boolean(stored && keyOf(stored, config.secretKey)),
287
+ canKeepKeys,
288
+ status,
289
+ }
290
+ },
291
+
292
+ async save(actor: EmailActor, input: EmailSettingsInput): Promise<EmailOutcome> {
293
+ const refused = locked()
294
+ if (refused) return refused
295
+ const provider = text(input.provider) as StoredProvider
296
+ if (!STORED_PROVIDERS.includes(provider))
297
+ return { ok: false, status: 400, message: 'Choose a provider.' }
298
+ const from = text(input.from)
299
+ if (!isValidEmail(from))
300
+ return { ok: false, status: 400, message: 'Enter the address e-mail is sent from.' }
301
+ const next: Stored = {
302
+ provider,
303
+ from,
304
+ ...(text(input.fromName) ? { fromName: text(input.fromName) } : {}),
305
+ }
306
+ if (provider === 'custom' || text(input.url)) {
307
+ const url = text(input.url)
308
+ if (provider === 'custom' && !url)
309
+ return { ok: false, status: 400, message: 'Enter the address messages are sent to.' }
310
+ if (url) next.url = url
311
+ }
312
+ if (provider === 'postmark' && text(input.postmarkStream))
313
+ next.postmarkStream = text(input.postmarkStream)
314
+ if (provider === 'ses') {
315
+ next.sesRegion = text(input.sesRegion)
316
+ next.sesAccessKeyId = text(input.sesAccessKeyId)
317
+ if (!next.sesRegion)
318
+ return { ok: false, status: 400, message: 'Enter the Amazon SES region.' }
319
+ if (!next.sesAccessKeyId)
320
+ return { ok: false, status: 400, message: 'Enter the access key ID.' }
321
+ }
322
+
323
+ const key = text(input.key)
324
+ const secretKey = usableSecretKey(config.secretKey)
325
+ if (key) {
326
+ if (!secretKey)
327
+ return {
328
+ ok: false,
329
+ status: 400,
330
+ message:
331
+ "This site can't keep e-mail keys until whoever hosts it gives it a secret key.",
332
+ }
333
+ next.keySealed = sealSecret(key, secretKey)
334
+ next.keyFor = targetOf(next)
335
+ } else {
336
+ const before = await read(db)
337
+ // A kept key stays only while it is for the same provider and address.
338
+ if (before?.keySealed && before.keyFor === targetOf(next)) {
339
+ next.keySealed = before.keySealed
340
+ next.keyFor = before.keyFor
341
+ } else if (provider !== 'custom')
342
+ return {
343
+ ok: false,
344
+ status: 400,
345
+ message: before?.keySealed
346
+ ? 'Enter the key again: a key is only used with the provider and address it was entered for.'
347
+ : 'Enter the key from your provider.',
348
+ }
349
+ }
350
+
351
+ const problems: string[] = []
352
+ const built = portOf(next, config.secretKey, {
353
+ warning: (_message, properties) => problems.push(String(properties?.detail ?? '')),
354
+ })
355
+ if (!built)
356
+ return {
357
+ ok: false,
358
+ status: 400,
359
+ message: `Those settings can't be used. ${problems.filter(Boolean).join(' ')}`.trim(),
360
+ }
361
+
362
+ await write(db, next)
363
+ await audit(actor, 'Save', `${provider}, from ${from}${key ? ', key changed' : ''}`)
364
+ await refresh()
365
+ return { ok: true }
366
+ },
367
+
368
+ async clear(actor: EmailActor): Promise<EmailOutcome> {
369
+ const refused = locked()
370
+ if (refused) return refused
371
+ await write(db, undefined)
372
+ await audit(actor, 'Clear', 'e-mail settings removed')
373
+ await refresh()
374
+ return { ok: true }
375
+ },
376
+
377
+ /** A message to the administrator, through whatever is in force now. */
378
+ async test(actor: EmailActor): Promise<EmailOutcome> {
379
+ if (!actor.email || !isValidEmail(actor.email))
380
+ return { ok: false, status: 400, message: 'Your account has no e-mail address to send to.' }
381
+ const port = options.port()
382
+ if (!port || port.provider === 'none')
383
+ return { ok: false, status: 409, message: 'Set up e-mail first.' }
384
+ const result = await port.send({
385
+ to: [{ email: actor.email, name: actor.name }],
386
+ subject: 'A test e-mail from your site',
387
+ text: 'This message shows that your site can send e-mail.',
388
+ })
389
+ return result.ok
390
+ ? { ok: true }
391
+ : { ok: false, status: 502, message: `The test e-mail was not sent: ${result.error}` }
392
+ },
393
+ }
394
+ }
package/src/email.ts CHANGED
@@ -52,7 +52,8 @@ export interface EmailMessage {
52
52
  export type EmailResult = { ok: true; id: string | null } | { ok: false; error: string }
53
53
 
54
54
  /** Which adapter is in play; named in logs and in the availability report. */
55
- export type EmailProvider = 'resend' | 'postmark' | 'ses' | 'custom' | 'log'
55
+ /** `none`: a port set up in Settings (story 340) that has nothing set up yet. */
56
+ export type EmailProvider = 'resend' | 'postmark' | 'ses' | 'custom' | 'log' | 'none'
56
57
 
57
58
  export interface EmailPort {
58
59
  /** Named in the boot banner and in logs: `resend`, `postmark (broadcast)`, … */
@@ -224,13 +225,17 @@ export const EMAIL_DEPENDENT_FEATURES = [
224
225
  export const EMAIL_SETUP_HINT =
225
226
  'Set CROMBOLO_EMAIL_PROVIDER to resend, postmark or custom with its key and CROMBOLO_EMAIL_FROM, or pass `email` in crombolo.config.ts. See docs/configuration.md.'
226
227
 
228
+ /** Whether there is a port that would take a message, the console's included. */
229
+ export const emailReady = (port: EmailPort | undefined): port is EmailPort =>
230
+ port !== undefined && port.provider !== 'none'
231
+
227
232
  export function emailAvailability(port: EmailPort | undefined): EmailAvailability {
228
- if (!port)
233
+ if (!emailReady(port))
229
234
  return {
230
235
  available: false,
231
236
  provider: null,
232
237
  description: null,
233
- reason: `No e-mail provider is configured. ${EMAIL_SETUP_HINT}`,
238
+ reason: 'No e-mail provider is configured. Set one up in Settings, under E-mail.',
234
239
  affects: [...EMAIL_DEPENDENT_FEATURES],
235
240
  }
236
241
  if (port.provider === 'log')
@@ -239,7 +244,7 @@ export function emailAvailability(port: EmailPort | undefined): EmailAvailabilit
239
244
  provider: 'log',
240
245
  description: port.description,
241
246
  reason:
242
- 'E-mail is written to the console in development, not sent. Configure a provider before relying on it.',
247
+ "E-mail is written to the server's log in development, not sent. Set up a provider before relying on it.",
243
248
  affects: [],
244
249
  }
245
250
  return {
@@ -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: {
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