@crombolo/server 0.60.0 → 0.62.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.
@@ -10,6 +10,7 @@ import {
10
10
  PublishedContent,
11
11
  PublishedElement,
12
12
  RawHtml,
13
+ sanitiseHtml,
13
14
  } from '@crombolo/render'
14
15
  import type { BundleLog } from './bundles.ts'
15
16
  import type { ExtensionProcess } from './extension-process.ts'
@@ -71,6 +72,8 @@ export function createExtensionComponents(
71
72
  ): ExtensionComponents {
72
73
  const byId = new Map(sources.map((source) => [source.process.id, source]))
73
74
  const warned = new Set<string>()
75
+ /** Components whose removals were logged this boot, by extension and name. */
76
+ const stripped = new Set<string>()
74
77
  const offers = (source: ExtensionComponentSource, name: string) =>
75
78
  source.process.description?.components?.some((component) => component.name === name) ?? false
76
79
 
@@ -102,7 +105,20 @@ export function createExtensionComponents(
102
105
  { ...rest, readSearchParams: () => searchParams },
103
106
  { timeoutMs: options.timeoutMs ?? 10_000, extra: valuesSender() },
104
107
  )
105
- return new RawHtml(typeof value === 'string' ? value : '')
108
+ // Story 330: what can run script, by the Sanitizer API's safe baseline, never reaches the page.
109
+ const removed: string[] = []
110
+ const safe = sanitiseHtml(typeof value === 'string' ? value : '', (_kind, what) => {
111
+ removed.push(what)
112
+ })
113
+ const key = `${id}/${name}`
114
+ if (removed.length > 0 && !stripped.has(key)) {
115
+ stripped.add(key)
116
+ source.log.warn(
117
+ "The extension {id}'s component {name} carried {count} thing(s) a page may not: {names}. They were removed.",
118
+ { id, name, count: removed.length, names: [...new Set(removed)].join(', ') },
119
+ )
120
+ }
121
+ return new RawHtml(safe)
106
122
  } catch (error) {
107
123
  source.log.error('The extension {id} could not render {name}: {error}', {
108
124
  id,
@@ -8,7 +8,12 @@
8
8
  */
9
9
  import { join } from 'node:path'
10
10
  import type { BundlePackage } from '@crombolo/backoffice-host'
11
- import { type ExtensionSetting, readSettings } from '@crombolo/backoffice-host/registry'
11
+ import {
12
+ type ExtensionSetting,
13
+ INSTALLED_AS_DEPENDENCY,
14
+ readSettings,
15
+ USER_DELEGATE,
16
+ } from '@crombolo/backoffice-host/registry'
12
17
  import {
13
18
  type BundleGrant,
14
19
  BundleGrantRepository,
@@ -18,6 +23,7 @@ import {
18
23
  import { declaredOrigins, declaredPermissions, grantGaps } from './bundle-grants.ts'
19
24
  import type { BundleLog, ServerBundle } from './bundles.ts'
20
25
  import type { CromboloConfig, ExtensionEntry } from './config.ts'
26
+ import type { ActivityRecorder } from './extension-activity.ts'
21
27
  import { ExtensionProcess, isolatedBundle, isolationProblems } from './extension-process.ts'
22
28
  import { openSecret } from './secrets.ts'
23
29
 
@@ -52,8 +58,7 @@ export function entryCovers(pkg: BundlePackage, entry: ExtensionEntry | undefine
52
58
  const granted = new Set(entry.grant)
53
59
  if (!declaredPermissions(pkg).every((permission) => granted.has(permission))) return false
54
60
  const origins = new Set(entry.origins ?? [])
55
- if (!declaredOrigins(pkg).every((origin) => origins.has(origin))) return false
56
- return !declaredPermissions(pkg).includes('actAs') || Boolean(entry.actAs)
61
+ return declaredOrigins(pkg).every((origin) => origins.has(origin))
57
62
  }
58
63
 
59
64
  /** Its settings: the manifest's defaults, then what the back office set, then the config's. */
@@ -95,6 +100,12 @@ export function extensionEntryProblems(
95
100
  (id) =>
96
101
  `The config's extensions names "${id}", which no extension the site depends on is: add it to package.json, or take it out.`,
97
102
  )
103
+ // Acting for the person needs a person to have granted it, which a config has not (story 325).
104
+ for (const [id, entry] of Object.entries(entries ?? {}))
105
+ if (entry.grant?.includes(USER_DELEGATE))
106
+ problems.push(
107
+ `The config's extensions grants "${id}" ${USER_DELEGATE}, which only an administrator who is signed in may grant, so a job or an event has someone to act for: take it out of the config, and grant it in Settings, under Extensions, or with \`crombolo extension grant ${id} --delegate-to <user key>\`.`,
108
+ )
98
109
  if (Bun.env.NODE_ENV === 'production')
99
110
  for (const [id, entry] of Object.entries(entries ?? {}))
100
111
  if (entry.dev)
@@ -104,6 +115,10 @@ export function extensionEntryProblems(
104
115
  return problems
105
116
  }
106
117
 
118
+ /** Why a linked extension does not run in production (story 326). */
119
+ export const LINKED_IN_PRODUCTION =
120
+ "it is linked from elsewhere on this machine, which is for a developer's machine only: install it with `crombolo extension install` so it has a root of its own"
121
+
107
122
  /** An extension that could not start, and why: shown where it is listed. */
108
123
  export interface FailedExtension {
109
124
  id: string
@@ -120,6 +135,7 @@ export async function startExtensions(
120
135
  packages: readonly BundlePackage[],
121
136
  recorded: RecordedExtensions,
122
137
  log: (id: string) => BundleLog,
138
+ activity?: ActivityRecorder,
123
139
  ): Promise<{
124
140
  bundles: ServerBundle[]
125
141
  processes: ExtensionProcess[]
@@ -131,6 +147,23 @@ export async function startExtensions(
131
147
  const failed: FailedExtension[] = []
132
148
  for (const pkg of packages) {
133
149
  if (!pkg.carries.server || wired.has(pkg.id)) continue
150
+ // Story 326: an extension runs from a root of its own, never as a dependency of the site.
151
+ if (pkg.linked && Bun.env.NODE_ENV === 'production') {
152
+ failed.push({ id: pkg.id, reason: LINKED_IN_PRODUCTION })
153
+ log(pkg.id).error('{package} is not started: {reason}', {
154
+ package: pkg.packageName,
155
+ reason: LINKED_IN_PRODUCTION,
156
+ })
157
+ continue
158
+ }
159
+ if (pkg.dependency) {
160
+ failed.push({ id: pkg.id, reason: INSTALLED_AS_DEPENDENCY })
161
+ log(pkg.id).error('{package} is not started: {reason}', {
162
+ package: pkg.packageName,
163
+ reason: INSTALLED_AS_DEPENDENCY,
164
+ })
165
+ continue
166
+ }
134
167
  const entry = config.extensions?.[pkg.id]
135
168
  const grant = recorded.grants.get(pkg.id)
136
169
  const byConfig = entryCovers(pkg, entry)
@@ -152,6 +185,7 @@ export async function startExtensions(
152
185
  reads: entry?.dev?.allowRead,
153
186
  timeoutMs: entry?.timeoutMs,
154
187
  log: log(pkg.id),
188
+ activity,
155
189
  })
156
190
  try {
157
191
  const description = await process.start()