@crombolo/server 0.59.0 → 0.61.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.
@@ -5,16 +5,21 @@
5
5
  * disable it.
6
6
  * docs/bundles.md, "Permissions".
7
7
  */
8
+
9
+ import { hasSection, type Principal } from '@crombolo/api-management/domain'
8
10
  import {
11
+ AREA_PERMISSIONS,
9
12
  askedPermissions,
10
13
  type BundlePackage,
11
14
  type BundlePermission,
12
15
  type DeclaredPermission,
13
16
  describePermissions,
14
17
  isSchema3Field,
18
+ USER_DELEGATE,
15
19
  } from '@crombolo/backoffice-host/registry'
16
- import { type BundleGrant, BundleGrantRepository, type Db } from '@crombolo/data'
17
- import { API_PERMISSIONS } from './bundle-api.ts'
20
+ import { type ActivityKind, type BundleGrant, BundleGrantRepository, type Db } from '@crombolo/data'
21
+ import { API_PERMISSIONS, sectionOfPermission } from './bundle-api.ts'
22
+ import { type ActivityPerson, type ActivityRecorder, timed } from './extension-activity.ts'
18
23
 
19
24
  /** The permissions each capability serves; `log` needs none. */
20
25
  export const CAPABILITY_PERMISSIONS: Record<string, readonly BundlePermission[]> = {
@@ -32,11 +37,14 @@ export const CAPABILITY_PERMISSIONS: Record<string, readonly BundlePermission[]>
32
37
  const DECLARATION_PERMISSIONS: ReadonlySet<string> = new Set([
33
38
  'events.content',
34
39
  'routes.public',
35
- 'actAs',
40
+ // Every area, as the person using it: checked per call, not by a capability (story 325).
41
+ USER_DELEGATE,
36
42
  'templates',
37
43
  'member.delegate',
38
44
  // What the screens need, not the server half (story 320).
39
45
  'backoffice.code',
46
+ // Checked against the tables it declares, not a capability (story 321).
47
+ 'data.tables',
40
48
  ])
41
49
 
42
50
  /** The permission each capability method needs. */
@@ -106,7 +114,9 @@ export function permissionProblems(
106
114
  const serves = CAPABILITY_PERMISSIONS[capability]
107
115
  if (!serves || serves.length === 0) continue
108
116
  const writes = serves.filter((p) => p !== 'member.delegate')
109
- if (!writes.some((p) => has.has(p)))
117
+ // Acting for the person covers every area's capability, not a request out (story 325).
118
+ const delegated = has.has(USER_DELEGATE) && capability !== 'fetch'
119
+ if (!writes.some((p) => has.has(p)) && !delegated)
110
120
  problems.push(
111
121
  `Bundle "${label}" uses "${capability}" but declares none of its permissions (${writes.join(', ')}) in "crombolo.permissions".`,
112
122
  )
@@ -127,6 +137,28 @@ export function permissionProblems(
127
137
  return problems
128
138
  }
129
139
 
140
+ /**
141
+ * What a capability may use for this caller (story 325): its grant, and under
142
+ * `user.delegate` each area whose section the back-office person using it holds.
143
+ * A job, an event or a visitor adds nothing: they reach the site only through
144
+ * `api`, as whoever granted it. Pure.
145
+ */
146
+ export function delegatedPermissions(
147
+ granted: readonly string[],
148
+ person: Principal | undefined,
149
+ ): string[] {
150
+ if (!granted.includes(USER_DELEGATE) || !person) return [...granted]
151
+ const reached = AREA_PERMISSIONS.filter((permission) => {
152
+ if (person.isAdmin) return true
153
+ const section = sectionOfPermission(permission)
154
+ return section !== undefined && hasSection(person, section)
155
+ })
156
+ return [...new Set([...granted, ...reached])]
157
+ }
158
+
159
+ /** Why `user.delegate` cannot be granted without a person to act for (story 325). */
160
+ export const DELEGATE_NEEDS_PERSON = `${USER_DELEGATE} acts for whoever granted it when nobody is using it, and nobody is named: grant it signed in to the back office, or name the user with --delegate-to <user key>`
161
+
130
162
  /** A capability call the bundle was not given the permission for. */
131
163
  export class PermissionRefusedError extends Error {
132
164
  constructor(
@@ -146,6 +178,8 @@ export function gated<T extends object>(
146
178
  capability: string,
147
179
  host: T,
148
180
  declared: readonly string[],
181
+ /** Records each call for the activity view (story 327), for the person it is made for. */
182
+ activity?: { recorder: ActivityRecorder; person: ActivityPerson },
149
183
  ): T {
150
184
  const methods = METHOD_PERMISSIONS[capability]
151
185
  if (!methods) return host
@@ -153,13 +187,32 @@ export function gated<T extends object>(
153
187
  const out: Record<string, unknown> = {}
154
188
  for (const [name, value] of Object.entries(host)) {
155
189
  const needs = methods[name]
190
+ const event = {
191
+ extensionId: bundle,
192
+ ...(activity?.person ?? { personKey: null, personName: null }),
193
+ kind: (needs?.endsWith('.read') ? 'read' : 'write') as ActivityKind,
194
+ area: capability,
195
+ verb: name,
196
+ }
156
197
  out[name] =
157
198
  typeof value === 'function' && needs && !has.has(needs)
158
199
  ? () => {
200
+ activity?.recorder.record({
201
+ ...event,
202
+ kind: 'refused',
203
+ verb: `${name} (${needs})`,
204
+ outcome: 'refused',
205
+ })
159
206
  throw new PermissionRefusedError(bundle, needs)
160
207
  }
161
208
  : typeof value === 'function'
162
- ? (value as (...args: unknown[]) => unknown).bind(host)
209
+ ? // A request out is recorded where its origin is known, as a request (story 327).
210
+ activity && needs && capability !== 'fetch'
211
+ ? (...args: unknown[]) =>
212
+ timed(activity.recorder, event, () =>
213
+ (value as (...args: unknown[]) => unknown).apply(host, args),
214
+ )
215
+ : (value as (...args: unknown[]) => unknown).bind(host)
163
216
  : value
164
217
  }
165
218
  return Object.freeze(out) as T
@@ -187,7 +240,7 @@ export interface BundleGrantState {
187
240
 
188
241
  /**
189
242
  * What the installed version asks for that a grant does not cover (story 309):
190
- * permissions, `http.outbound` origins, and whom `actAs` acts for. Empty when it
243
+ * permissions, `http.outbound` origins, and who granted `user.delegate`. Empty when it
191
244
  * covers it all. Pure.
192
245
  */
193
246
  export function grantGaps(pkg: BundlePackage, grant: BundleGrant | undefined): string[] {
@@ -197,8 +250,12 @@ export function grantGaps(pkg: BundlePackage, grant: BundleGrant | undefined): s
197
250
  const gaps = declaredPermissions(pkg).filter((permission) => !has.has(permission))
198
251
  for (const origin of declaredOrigins(pkg))
199
252
  if (!grant.origins.includes(origin)) gaps.push(`http.outbound ${origin}`)
200
- if (declaredPermissions(pkg).includes('actAs') && !grant.actAs && !gaps.includes('actAs'))
201
- gaps.push('actAs: whom it acts for')
253
+ if (
254
+ declaredPermissions(pkg).includes(USER_DELEGATE) &&
255
+ !grant.delegateKey &&
256
+ !gaps.includes(USER_DELEGATE)
257
+ )
258
+ gaps.push(`${USER_DELEGATE}: who granted it, for when nobody is using it`)
202
259
  return gaps
203
260
  }
204
261
 
@@ -217,22 +274,24 @@ export interface BundleGrants {
217
274
  state(pkg: BundlePackage): BundleGrantState
218
275
  /**
219
276
  * Records what a bundle is approved for, and by whom; true when that changed.
220
- * `actAs` is whom it acts for, when it asks to act for a user (story 308).
277
+ * `delegateKey` is who granted `user.delegate`, whom a job or an event acts for (story 325).
221
278
  */
222
279
  grant(
223
280
  pkg: BundlePackage,
224
281
  by: string | null,
225
- options?: { actAs?: string | null },
282
+ options?: { delegateKey?: string | null },
226
283
  ): Promise<boolean>
227
284
  disable(pkg: BundlePackage, by: string | null): Promise<BundleGrantState>
228
285
  enable(pkg: BundlePackage): Promise<BundleGrantState>
286
+ /** Forgets its grant entirely, as removing it does (story 328). */
287
+ forget(bundleId: string): Promise<void>
229
288
  }
230
289
 
231
290
  /** Whether a recorded approval already holds this version and list. */
232
291
  export function approvalHolds(
233
292
  pkg: BundlePackage,
234
293
  grant: BundleGrant | undefined,
235
- actAs?: string | null,
294
+ delegateKey?: string | null,
236
295
  ): boolean {
237
296
  if (!grant || grant.version !== pkg.version) return false
238
297
  const same = (a: readonly string[], b: readonly string[]) =>
@@ -240,7 +299,7 @@ export function approvalHolds(
240
299
  return (
241
300
  same(grant.permissions, declaredPermissions(pkg)) &&
242
301
  same(grant.origins, declaredOrigins(pkg)) &&
243
- (actAs === undefined || grant.actAs === actAs)
302
+ (delegateKey === undefined || grant.delegateKey === delegateKey)
244
303
  )
245
304
  }
246
305
 
@@ -312,7 +371,7 @@ export function createBundleGrants(options: {
312
371
  version: pkg.version,
313
372
  permissions: declaredPermissions(pkg),
314
373
  origins: declaredOrigins(pkg),
315
- actAs: declaredPermissions(pkg).includes('actAs') ? grant.actAs : null,
374
+ delegateKey: declaredPermissions(pkg).includes(USER_DELEGATE) ? grant.delegateKey : null,
316
375
  grantedBy: grant.grantedBy,
317
376
  })
318
377
  await read()
@@ -323,7 +382,7 @@ export function createBundleGrants(options: {
323
382
  return stateOf(pkg)
324
383
  },
325
384
  async grant(pkg, by, options = {}) {
326
- if (approvalHolds(pkg, grants.get(pkg.id), options.actAs)) return false
385
+ if (approvalHolds(pkg, grants.get(pkg.id), options.delegateKey)) return false
327
386
  const asks = declaredPermissions(pkg)
328
387
  await repository.grant({
329
388
  bundleId: pkg.id,
@@ -331,12 +390,18 @@ export function createBundleGrants(options: {
331
390
  version: pkg.version,
332
391
  permissions: asks,
333
392
  origins: declaredOrigins(pkg),
334
- actAs: asks.includes('actAs') ? (options.actAs ?? grants.get(pkg.id)?.actAs ?? null) : null,
393
+ delegateKey: asks.includes(USER_DELEGATE)
394
+ ? (options.delegateKey ?? grants.get(pkg.id)?.delegateKey ?? null)
395
+ : null,
335
396
  grantedBy: by,
336
397
  })
337
398
  await read()
338
399
  return true
339
400
  },
401
+ async forget(bundleId) {
402
+ await repository.forget(bundleId)
403
+ await read()
404
+ },
340
405
  async disable(pkg, by) {
341
406
  await repository.disable(
342
407
  { bundleId: pkg.id, packageName: pkg.packageName, version: pkg.version },
package/src/bundles.ts CHANGED
@@ -74,6 +74,7 @@ import {
74
74
  SITE_OWNER,
75
75
  type TablesDatabase,
76
76
  } from '@crombolo/data'
77
+ import type { ScreenAnswer } from '@crombolo/extension/screens'
77
78
  import {
78
79
  normaliseRedirectPath,
79
80
  type PublishedCache,
@@ -85,6 +86,7 @@ import { anonymiseProblems } from './anonymise-rules.ts'
85
86
  import type { BundleApi } from './bundle-api.ts'
86
87
  import {
87
88
  declaredPermissions,
89
+ delegatedPermissions,
88
90
  disabledResponse,
89
91
  gated,
90
92
  isSchema3,
@@ -92,6 +94,8 @@ import {
92
94
  permissionProblems,
93
95
  } from './bundle-grants.ts'
94
96
  import type { BundleMedia, BundleMediaDeclaration } from './bundle-media.ts'
97
+ import { type ActivityRecorder, personOf } from './extension-activity.ts'
98
+ import { normaliseScreenResult } from './extension-screens.ts'
95
99
  import type { BundleForms } from './form-types.ts'
96
100
  import type { BundleIdentityProviders } from './identity-provider-overrides.ts'
97
101
  import { type JobInfo, type JobSchedule, jobProblems, type OwnerJobs } from './owner-jobs.ts'
@@ -344,6 +348,37 @@ export interface ServerBundle<
344
348
  jobs?: Record<string, BundleJob<C, T>>
345
349
  /** When its jobs run by themselves: cron expressions in a timezone. */
346
350
  schedules?: readonly JobSchedule[]
351
+ /**
352
+ * Screens the back office draws from what they return (story 323), by id:
353
+ * each a `view` and the `actions` its buttons name. docs/extensions.md, "Screens".
354
+ */
355
+ screens?: Readonly<Record<string, BundleScreen<C, T>>>
356
+ }
357
+
358
+ /** What a screen's view or action is given: a back-office route's context, and the screen's state. */
359
+ export interface BundleScreenContext<
360
+ C extends BundleCapability = BundleCapability,
361
+ T extends BundleTables = BundleTables,
362
+ > extends BundleRouteContext<C, T> {
363
+ principal: Principal
364
+ /** What the last answer asked the back office to keep, sent back as it was. */
365
+ state: Record<string, unknown>
366
+ /** What the button sent, and a form's values under `values` when it submits. */
367
+ input: Record<string, unknown>
368
+ signal?: AbortSignal
369
+ }
370
+
371
+ export type BundleScreenHandler<
372
+ C extends BundleCapability = BundleCapability,
373
+ T extends BundleTables = BundleTables,
374
+ > = (context: BundleScreenContext<C, T>) => ScreenAnswer | Promise<ScreenAnswer>
375
+
376
+ export interface BundleScreen<
377
+ C extends BundleCapability = BundleCapability,
378
+ T extends BundleTables = BundleTables,
379
+ > {
380
+ view: BundleScreenHandler<C, T>
381
+ actions?: Readonly<Record<string, BundleScreenHandler<C, T>>>
347
382
  }
348
383
 
349
384
  /** A bundle's background job (story 187). */
@@ -423,6 +458,8 @@ export function validateServerBundles(
423
458
  problems.push(
424
459
  `Bundle "${label}" declares tables under the id "${SITE_OWNER}", which names the site's own tables.`,
425
460
  )
461
+ for (const problem of screenProblems(bundle.screens))
462
+ problems.push(`Bundle "${label}" screens: ${problem}.`)
426
463
  if (bundle.tables) {
427
464
  if (bundle.tables.id !== bundle.id)
428
465
  problems.push(
@@ -478,6 +515,14 @@ export function validateServerBundles(
478
515
  problems.push(
479
516
  `Bundle "${label}" answers routes on the site, and so needs "routes.public" in "crombolo.permissions".`,
480
517
  )
518
+ if (bundle.tables && !declared.includes('data.tables'))
519
+ problems.push(
520
+ `Bundle "${label}" declares tables, and so needs "data.tables" in "crombolo.permissions".`,
521
+ )
522
+ if (!bundle.tables && declared.includes('data.tables'))
523
+ problems.push(
524
+ `Bundle "${label}" declares "data.tables" but no tables; take it out of "crombolo.permissions".`,
525
+ )
481
526
  }
482
527
  }
483
528
  }
@@ -727,6 +772,8 @@ export type CallerCapabilities = {
727
772
 
728
773
  export interface ServerBundlesOptions {
729
774
  bundles: readonly ServerBundle[]
775
+ /** Where each capability call is recorded for the activity view (story 327). */
776
+ activity?: ActivityRecorder
730
777
  /** The bundle packages the site depends on, from discovery. */
731
778
  packages: readonly BundlePackage[]
732
779
  /** The running release, which every bundle's peer range must admit. */
@@ -855,9 +902,10 @@ export function createServerBundles(options: ServerBundlesOptions): ServerBundle
855
902
  ): Pick<BundleHost, BundleCapability> => {
856
903
  const host: Record<string, unknown> = {}
857
904
  // What it was granted, not what it declares (story 309).
858
- const declared = options.granted
859
- ? options.granted(bundle.id)
860
- : declaredPermissions(owners.get(bundle.id))
905
+ const declared = delegatedPermissions(
906
+ options.granted ? options.granted(bundle.id) : declaredPermissions(owners.get(bundle.id)),
907
+ caller.kind === 'backoffice' ? caller.principal : undefined,
908
+ )
861
909
  for (const capability of bundle.capabilities) {
862
910
  // Acting for a member needs `member.delegate`, on every call (story 309).
863
911
  if (
@@ -875,7 +923,15 @@ export function createServerBundles(options: ServerBundlesOptions): ServerBundle
875
923
  ? (logs.get(bundle.id) as BundleLog)
876
924
  : (options.host as Partial<BundleHost>)[capability]
877
925
  // Only what its declared permissions allow (story 222).
878
- host[capability] = given ? gated(bundle.id, capability, given, declared) : given
926
+ host[capability] = given
927
+ ? gated(
928
+ bundle.id,
929
+ capability,
930
+ given,
931
+ declared,
932
+ options.activity ? { recorder: options.activity, person: personOf(caller) } : undefined,
933
+ )
934
+ : given
879
935
  }
880
936
  const database = databaseOf(bundle)
881
937
  if (database) host.database = database
@@ -899,6 +955,64 @@ export function createServerBundles(options: ServerBundlesOptions): ServerBundle
899
955
  ),
900
956
  )
901
957
 
958
+ /**
959
+ * A screen's view, or one of its actions (story 323): `POST _screen/<id>` with
960
+ * `{ action?, input?, state? }`, answered with the screen held to the
961
+ * catalogue. A handler that throws, a refused capability included, answers
962
+ * `{ problem }`, so the back office keeps the last screen and says why.
963
+ */
964
+ const screenCall = async (
965
+ bundle: ServerBundle,
966
+ id: string,
967
+ request: Request,
968
+ principal: Principal,
969
+ ): Promise<Response> => {
970
+ if (request.method !== 'POST')
971
+ return new Response('Method Not Allowed', { status: 405, headers: { allow: 'POST' } })
972
+ const screen = Object.hasOwn(bundle.screens ?? {}, id) ? bundle.screens?.[id] : undefined
973
+ if (!screen) return new Response('Not Found', { status: 404 })
974
+ if (options.isOn && !options.isOn(bundle.id)) return disabledResponse(bundle.id)
975
+ let body: Record<string, unknown>
976
+ try {
977
+ const parsed = await request.json()
978
+ body = parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {}
979
+ } catch {
980
+ body = {}
981
+ }
982
+ const action = typeof body.action === 'string' ? body.action : undefined
983
+ const handler = action
984
+ ? Object.hasOwn(screen.actions ?? {}, action)
985
+ ? screen.actions?.[action]
986
+ : undefined
987
+ : screen.view
988
+ if (!handler) return new Response('Not Found', { status: 404 })
989
+ const caller: BundleCaller = Object.freeze({ kind: 'backoffice', principal })
990
+ const log = logs.get(bundle.id)
991
+ try {
992
+ const answer = await handler({
993
+ bundle: contextFor(bundle, caller) as BundleScreenContext['bundle'],
994
+ caller,
995
+ principal,
996
+ state: plainObject(body.state),
997
+ input: plainObject(body.input),
998
+ signal: request.signal,
999
+ })
1000
+ const { result, dropped } = normaliseScreenResult(answer)
1001
+ if (dropped.length > 0)
1002
+ log?.warn('Its screen {screen} answered what the back office does not draw: {dropped}', {
1003
+ screen: id,
1004
+ dropped: dropped.join(', '),
1005
+ })
1006
+ return Response.json(result)
1007
+ } catch (error) {
1008
+ // A refusal may cross the channel as an outcome rather than an Error: its message is what to say.
1009
+ const said = (error as { message?: unknown } | null)?.message
1010
+ const message = typeof said === 'string' && said.length > 0 ? said : 'It could not answer.'
1011
+ log?.error('Its screen {screen} failed: {error}', { screen: id, error: message })
1012
+ return Response.json({ problem: message })
1013
+ }
1014
+ }
1015
+
902
1016
  /** A site route that answers as waiting while its bundle is off. */
903
1017
  const whileOn = (bundleId: string, route: SiteRoute): SiteRoute => {
904
1018
  const isOn = options.isOn
@@ -950,6 +1064,9 @@ export function createServerBundles(options: ServerBundlesOptions): ServerBundle
950
1064
  // the declared section, and a bundle has no way to opt a route out.
951
1065
  if (!hasSection(principal, bundle.section)) return new Response('Forbidden', { status: 403 })
952
1066
 
1067
+ if (requested.startsWith(SCREEN_SEGMENT))
1068
+ return screenCall(bundle, requested.slice(SCREEN_SEGMENT.length), request, principal)
1069
+
953
1070
  for (const route of (bundle.routes ?? []).filter((candidate) => !onSite(candidate))) {
954
1071
  const params = matchRoute(route.path, requested)
955
1072
  if (!params) continue
@@ -973,6 +1090,36 @@ export function createServerBundles(options: ServerBundlesOptions): ServerBundle
973
1090
 
974
1091
  const PUBLIC_CALLER: BundleCaller = Object.freeze({ kind: 'public' })
975
1092
 
1093
+ const SCREEN_ID = /^[a-z][a-z0-9-]{0,39}$/
1094
+
1095
+ /** Why a bundle's `screens` cannot be mounted: a bad id, or a view or action that is not a function. */
1096
+ export function screenProblems(screens: ServerBundle['screens']): string[] {
1097
+ if (screens === undefined) return []
1098
+ if (!screens || typeof screens !== 'object') return ['"screens" is an object of screens by id']
1099
+ const problems: string[] = []
1100
+ for (const [id, screen] of Object.entries(screens)) {
1101
+ if (!SCREEN_ID.test(id))
1102
+ problems.push(`"${id}" is not a screen id: lower case letters, digits and dashes`)
1103
+ if (typeof screen?.view !== 'function') problems.push(`"${id}" has no view function`)
1104
+ for (const [name, action] of Object.entries(screen?.actions ?? {}))
1105
+ if (typeof action !== 'function')
1106
+ problems.push(`"${id}"'s action "${name}" is not a function`)
1107
+ }
1108
+ return problems
1109
+ }
1110
+
1111
+ /** Below a bundle's back-office namespace, where its screens answer (story 323). */
1112
+ const SCREEN_SEGMENT = '_screen/'
1113
+
1114
+ const plainObject = (value: unknown): Record<string, unknown> => {
1115
+ if (!value || typeof value !== 'object' || Array.isArray(value)) return {}
1116
+ try {
1117
+ return JSON.parse(JSON.stringify(value)) as Record<string, unknown>
1118
+ } catch {
1119
+ return {}
1120
+ }
1121
+ }
1122
+
976
1123
  /** `BundleMedia`'s methods, refused one by one without `member.delegate`. */
977
1124
  const MEDIA_METHODS: readonly (keyof BundleMedia)[] = [
978
1125
  'create',
@@ -58,8 +58,8 @@ export async function handleComponentTemplates(
58
58
  return Response.json({ items: componentTemplates(onDisk, await repo.all(), extensions) })
59
59
 
60
60
  if (request.method === 'POST') {
61
- // As changing which templates a type allows: Structure, which Settings brings.
62
- if (!hasSection(principal, 'structure') && !hasSection(principal, 'settings'))
61
+ // As changing which templates a type allows: Settings.
62
+ if (!hasSection(principal, 'settings'))
63
63
  return Response.json(
64
64
  { message: 'Making a component a template needs access to Structure.' },
65
65
  { status: 403 },
package/src/config.ts CHANGED
@@ -23,6 +23,7 @@ import {
23
23
  import type { ServerBundle } from './bundles.ts'
24
24
  import type { EmailPort } from './email.ts'
25
25
  import type { GitConfig } from './git-routes.ts'
26
+ import { type UnrestrictedFrom, unrestrictedFrom } from './grant-policy.ts'
26
27
  import { checkHost, type HostConfig } from './host-token.ts'
27
28
  import { checkIdentityProviders, type IdentityProvider } from './identity-providers.ts'
28
29
  import type { MediaStore } from './media-store.ts'
@@ -343,6 +344,11 @@ export interface CromboloConfig {
343
344
  }
344
345
  /** How many days the audit log keeps an entry; 0 keeps them forever. docs/audit-log.md. */
345
346
  auditRetentionDays: number
347
+ /**
348
+ * How many days what each extension did is kept for its Activity view (story
349
+ * 327); 0 keeps none. `CROMBOLO_EXTENSION_ACTIVITY_DAYS`.
350
+ */
351
+ extensionActivityDays: number
346
352
  /**
347
353
  * How many days delivered webhooks, their log and dispatched content events
348
354
  * are kept; 0 keeps them forever. Failed work stays until retried. docs/webhooks.md.
@@ -593,6 +599,13 @@ export interface CromboloConfig {
593
599
  * `CROMBOLO_BUNDLE_SIGNATURES` and `CROMBOLO_BUNDLE_SOURCES`.
594
600
  */
595
601
  bundlePolicy: ProvenancePolicy
602
+ /**
603
+ * Where an Unrestricted extension may be granted from (story 324): the back
604
+ * office, by an administrator, or only the site's config, so a commit someone
605
+ * reviews is the only way. `CROMBOLO_UNRESTRICTED_EXTENSIONS`, `backoffice`
606
+ * unless it says `config`.
607
+ */
608
+ unrestrictedExtensions: UnrestrictedFrom
596
609
  /**
597
610
  * Where the Packages section's Marketplace sends someone browsing for
598
611
  * extensions. Never framed — npm refuses to be framed — so the native view
@@ -623,8 +636,6 @@ export interface ExtensionEntry {
623
636
  grant?: readonly string[]
624
637
  /** The origins its `http.outbound` may reach, when it asks for any. */
625
638
  origins?: readonly string[]
626
- /** Whom `actAs` acts for: `caller`, or `user:<key>`. */
627
- actAs?: string
628
639
  /** Its settings' values, locked in the back office. */
629
640
  settings?: Readonly<Record<string, unknown>>
630
641
  /**
@@ -679,6 +690,7 @@ export const DEFAULTS = {
679
690
  keepAllVersionsNewerThanDays: 7,
680
691
  keepLatestVersionPerDayForDays: 90,
681
692
  auditRetentionDays: 365,
693
+ extensionActivityDays: 14,
682
694
  eventRetentionDays: 30,
683
695
  memberRegistrationType: 'Member',
684
696
  memberSessionMinutes: 60 * 24 * 14,
@@ -893,6 +905,10 @@ export function loadConfig(
893
905
  setting('CROMBOLO_AUDIT_RETENTION_DAYS'),
894
906
  DEFAULTS.auditRetentionDays,
895
907
  ),
908
+ extensionActivityDays: nonNegative(
909
+ setting('CROMBOLO_EXTENSION_ACTIVITY_DAYS'),
910
+ DEFAULTS.extensionActivityDays,
911
+ ),
896
912
  eventRetentionDays: nonNegative(
897
913
  setting('CROMBOLO_EVENT_RETENTION_DAYS'),
898
914
  DEFAULTS.eventRetentionDays,
@@ -951,6 +967,7 @@ export function loadConfig(
951
967
  applyBundleContentOnInstall: setting('CROMBOLO_APPLY_BUNDLE_CONTENT') !== 'false',
952
968
  // Resolved again below, once it is known whether a store was configured.
953
969
  runtimeInstalls: setting('CROMBOLO_RUNTIME_INSTALLS') !== 'false',
970
+ unrestrictedExtensions: unrestrictedFrom(setting('CROMBOLO_UNRESTRICTED_EXTENSIONS')),
954
971
  bundlePolicy: {
955
972
  signatures: bundleSignatures(setting('CROMBOLO_BUNDLE_SIGNATURES')),
956
973
  sources: (setting('CROMBOLO_BUNDLE_SOURCES') ?? '')
@@ -1144,7 +1161,7 @@ export function describeDatabase(
1144
1161
  }
1145
1162
  }
1146
1163
 
1147
- export const VERSION = '0.59.0'
1164
+ export const VERSION = '0.61.0'
1148
1165
 
1149
1166
  /** A whole number of seconds from the environment; undefined when unset or not one. */
1150
1167
  /** A positive number from a setting, else the default. */