@crombolo/server 0.44.0 → 0.46.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.
@@ -17,8 +17,9 @@
17
17
  * browser cannot reach npm, and the backoffice keeps making same-origin
18
18
  * requests only.
19
19
  */
20
- import { readFileSync } from 'node:fs'
21
- import { join } from 'node:path'
20
+ import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync } from 'node:fs'
21
+ import { tmpdir } from 'node:os'
22
+ import { join, resolve } from 'node:path'
22
23
  import {
23
24
  type BundlePackage,
24
25
  describePermissions,
@@ -27,11 +28,31 @@ import {
27
28
  type PackageJson,
28
29
  validateBundlePackage,
29
30
  } from '@crombolo/backoffice-host'
31
+ import {
32
+ LOCAL_BUNDLES_DIR,
33
+ localBundleFileName,
34
+ localBundlePath,
35
+ localBundlesNamed,
36
+ } from '@crombolo/transfer'
30
37
  import { type BundleGrants, declaredPermissions } from './bundle-grants.ts'
31
38
  import { logger } from './logging.ts'
39
+ import {
40
+ type ProvenancePolicy,
41
+ type ProvenanceResult,
42
+ provenanceProblem,
43
+ verifyPackage,
44
+ verifyProvenance,
45
+ } from './provenance.ts'
46
+ import { extractTarball } from './tar.ts'
32
47
 
33
48
  const log = logger('packages')
34
49
 
50
+ /** Where a registry version's tarball is, and what it hashes to. */
51
+ interface Dist {
52
+ tarball?: string
53
+ integrity?: string
54
+ }
55
+
35
56
  /** How long a search is reused. Long enough to page a list, short enough to stay fresh. */
36
57
  const CACHE_MS = 5 * 60 * 1000
37
58
 
@@ -72,6 +93,8 @@ export interface InstalledListing {
72
93
  disabledBy: string | null
73
94
  /** Who approved it, and when: an administrator at install, or the site's code. */
74
95
  granted?: { by: string | null; at: string; version: string }
96
+ /** Where it was built, from its signature (story 060); `local` for a workspace or linked one. */
97
+ provenance: ProvenanceResult
75
98
  }
76
99
 
77
100
  /** What became of the content half of an install. */
@@ -112,6 +135,10 @@ export interface MarketplaceOptions {
112
135
  installs?: boolean
113
136
  /** A host's own word on where installs happen, said in place of a deploy (story 181). */
114
137
  installsElsewhere?: { message: string; url?: string }
138
+ /** What the site takes of a bundle's signature (story 060); anything signed or not, when absent. */
139
+ policy?: ProvenancePolicy
140
+ /** Checks a package directory's signature; `verifyProvenance`, unless a test stands in. */
141
+ verify?: (dir: string) => Promise<ProvenanceResult>
115
142
  }
116
143
 
117
144
  export interface InstallOutcome {
@@ -132,6 +159,12 @@ export interface InstallOutcome {
132
159
  needsServerConsent?: boolean
133
160
  /** With `needsServerConsent`: what it asks to do with the site, to grant as a whole (story 222). */
134
161
  permissions?: { permission: string; allows: string }[]
162
+ /** It changed the code the server loads, which runs once the site restarts (story 241). */
163
+ restartPending?: boolean
164
+ /** Where the version checked was built, from its signature (story 060). */
165
+ provenance?: ProvenanceResult
166
+ /** The file an install from a file keeps in the site, to commit: `bundles/acme-crm-1.2.0.tgz` (story 245). */
167
+ file?: string
135
168
  }
136
169
 
137
170
  export type PackageInstaller = (
@@ -183,6 +216,32 @@ export interface Marketplace {
183
216
  by?: string | null
184
217
  },
185
218
  ): Promise<InstallOutcome>
219
+ /** What a version would bring, read from the registry and nothing installed: for a dry run. */
220
+ inspect(
221
+ name: string,
222
+ version?: string,
223
+ ): Promise<
224
+ | {
225
+ ok: true
226
+ server: boolean
227
+ content: boolean
228
+ extensions: boolean
229
+ permissions: string[]
230
+ version: string
231
+ provenance: ProvenanceResult
232
+ }
233
+ | { ok: false; message: string }
234
+ >
235
+ /** A packed bundle on this machine (a `.tgz`), installed as `install` installs one from the registry. */
236
+ installFile(
237
+ file: string,
238
+ options?: {
239
+ applyContent?: boolean
240
+ acceptServerCode?: boolean
241
+ grant?: readonly string[]
242
+ by?: string | null
243
+ },
244
+ ): Promise<InstallOutcome>
186
245
  uninstall(name: string): Promise<InstallOutcome>
187
246
  }
188
247
 
@@ -245,6 +304,36 @@ export function createMarketplace(options: MarketplaceOptions): Marketplace {
245
304
  }
246
305
  let cached: { at: number; query: string; listings: MarketplaceListing[] } | undefined
247
306
 
307
+ /**
308
+ * A bundle's file at `bundles/<name>-<version>.tgz`: used in place when it is
309
+ * there already, copied there otherwise. Another file under that name is
310
+ * refused, since one version is one file.
311
+ */
312
+ const keepInSite = (
313
+ file: string,
314
+ declared: { name: string; version: string },
315
+ ): { path: string; copied: boolean } | string => {
316
+ const path = `${LOCAL_BUNDLES_DIR}/${localBundleFileName(declared.name, declared.version)}`
317
+ const target = join(options.siteDir, path)
318
+ if (resolve(file) === resolve(target)) return { path, copied: false }
319
+ const bytes = readFileSync(file)
320
+ if (existsSync(target)) {
321
+ if (readFileSync(target).equals(bytes)) return { path, copied: false }
322
+ return `${path} already holds a different ${declared.name}@${declared.version} than ${file}, so it was not installed: one version is one file. Remove ${path} first if ${file} is the one to keep.`
323
+ }
324
+ mkdirSync(join(options.siteDir, LOCAL_BUNDLES_DIR), { recursive: true })
325
+ copyFileSync(file, target)
326
+ return { path, copied: true }
327
+ }
328
+
329
+ /** The `bundles/` file a dependency used to name, removed once nothing names it. */
330
+ const removeUnnamed = (previousRange: string | undefined, keep?: string) => {
331
+ const path = localBundlePath(previousRange)
332
+ if (!path || path === keep) return
333
+ if (localBundlesNamed(options.siteDir).includes(path)) return
334
+ rmSync(join(options.siteDir, path), { force: true })
335
+ }
336
+
248
337
  const installedVersion = (name: string): string | null =>
249
338
  options.extensions.bundles().bundles.find((bundle) => bundle.packageName === name)?.version ??
250
339
  null
@@ -258,7 +347,9 @@ export function createMarketplace(options: MarketplaceOptions): Marketplace {
258
347
  name: string,
259
348
  wanted?: string,
260
349
  ): Promise<
261
- (BundlePackage['carries'] & { permissions: string[] }) | 'not-a-bundle' | 'unreachable'
350
+ | (BundlePackage['carries'] & { permissions: string[]; version: string; dist?: Dist })
351
+ | 'not-a-bundle'
352
+ | 'unreachable'
262
353
  > => {
263
354
  try {
264
355
  const response = await call(`${options.registry}/${encodeURIComponent(name)}`, {
@@ -281,7 +372,8 @@ export function createMarketplace(options: MarketplaceOptions): Marketplace {
281
372
  .sort(Bun.semver.order)
282
373
  .at(-1))
283
374
  const version = resolved ? versions[resolved] : undefined
284
- if (!version || validateBundlePackage(version).length > 0) return 'not-a-bundle'
375
+ if (!resolved || !version || validateBundlePackage(version).length > 0) return 'not-a-bundle'
376
+ const dist = (version as { dist?: Dist }).dist
285
377
  const field = version.crombolo as {
286
378
  extensions?: unknown[]
287
379
  content?: boolean
@@ -293,17 +385,92 @@ export function createMarketplace(options: MarketplaceOptions): Marketplace {
293
385
  content: field.content === true,
294
386
  server: field.server !== undefined,
295
387
  permissions: Array.isArray(field.permissions) ? field.permissions : [],
388
+ version: resolved,
389
+ ...(dist ? { dist } : {}),
296
390
  }
297
391
  } catch {
298
392
  return 'unreachable'
299
393
  }
300
394
  }
301
395
 
396
+ const verify = options.verify ?? ((dir: string) => verifyProvenance(dir))
397
+
398
+ /**
399
+ * Where a registry version was built (story 060): its exact tarball fetched,
400
+ * held to the registry's integrity, and its signature checked, so the bytes
401
+ * checked are the bytes `bun add` then installs. A registry that gives no
402
+ * tarball leaves nothing to check; one that cannot be fetched is not unsigned.
403
+ */
404
+ const provenanceAt = async (name: string, dist: Dist | undefined): Promise<ProvenanceResult> => {
405
+ if (!dist?.tarball) return { state: 'unsigned' }
406
+ const dir = mkdtempSync(join(tmpdir(), 'crombolo-bundle-check-'))
407
+ try {
408
+ const response = await call(dist.tarball)
409
+ if (!response.ok)
410
+ return {
411
+ state: 'unchecked',
412
+ reason: `${name} could not be fetched to check its signature (the registry answered ${response.status})`,
413
+ }
414
+ const bytes = new Uint8Array(await response.arrayBuffer())
415
+ if (dist.integrity?.startsWith('sha512-')) {
416
+ const got = `sha512-${new Bun.CryptoHasher('sha512').update(bytes).digest('base64')}`
417
+ if (got !== dist.integrity)
418
+ return { state: 'invalid', reason: `${name} is not the package the registry describes` }
419
+ }
420
+ const file = join(dir, 'bundle.tgz')
421
+ await Bun.write(file, bytes)
422
+ const unpacked = join(dir, 'package')
423
+ await extractTarball(file, unpacked)
424
+ return await verify(unpacked)
425
+ } catch (error) {
426
+ return {
427
+ state: 'unchecked',
428
+ reason: `${name} could not be checked: ${error instanceof Error ? error.message : String(error)}`,
429
+ }
430
+ } finally {
431
+ rmSync(dir, { recursive: true, force: true })
432
+ }
433
+ }
434
+
435
+ /** Why the site's policy refuses a version, as an outcome, or undefined when it may be installed. */
436
+ const refusedBySignature = (
437
+ label: string,
438
+ provenance: ProvenanceResult,
439
+ ): InstallOutcome | undefined => {
440
+ const problem = provenanceProblem(
441
+ provenance,
442
+ options.policy ?? { signatures: 'optional', sources: [] },
443
+ )
444
+ return problem
445
+ ? { ok: false, message: `${label} was not installed: ${problem}.`, provenance }
446
+ : undefined
447
+ }
448
+
449
+ /** Each installed version's signature, checked once: a version's files do not change. */
450
+ const installedProvenance = new Map<string, Promise<ProvenanceResult>>()
451
+ const provenanceOfInstalled = async (bundle: BundlePackage): Promise<ProvenanceResult> => {
452
+ const range = await rangeFor(bundle.packageName)
453
+ if (range && /^(workspace|link|file|portal):/.test(range)) return { state: 'local' }
454
+ const key = `${bundle.packageName}@${bundle.version}`
455
+ let found = installedProvenance.get(key)
456
+ if (!found) {
457
+ found = verify(bundle.directory).catch((error: unknown) => ({
458
+ state: 'unchecked' as const,
459
+ reason: error instanceof Error ? error.message : String(error),
460
+ }))
461
+ installedProvenance.set(key, found)
462
+ }
463
+ const result = await found
464
+ // Not kept: the next look may be able to check it.
465
+ if (result.state === 'unchecked') installedProvenance.delete(key)
466
+ return result
467
+ }
468
+
302
469
  /** What the registry says this package's latest version carries, when it is a valid bundle. */
303
470
  const declares = async (name: string): Promise<BundlePackage['carries'] | undefined> => {
304
471
  const declared = await declaresAt(name)
305
472
  if (typeof declared === 'string') return undefined
306
- const { permissions: _, ...carries } = declared
473
+ const { permissions: _, version: _version, dist: _dist, ...carries } = declared
307
474
  return carries
308
475
  }
309
476
 
@@ -406,6 +573,7 @@ export function createMarketplace(options: MarketplaceOptions): Marketplace {
406
573
  description: descriptionOf(bundle.directory),
407
574
  peerRange: bundle.peerRange,
408
575
  ...grantOf(bundle),
576
+ provenance: await provenanceOfInstalled(bundle),
409
577
  })),
410
578
  )
411
579
  },
@@ -433,68 +601,68 @@ export function createMarketplace(options: MarketplaceOptions): Marketplace {
433
601
  }
434
602
  if (declared.server && !consented(request, declared.permissions))
435
603
  return serverConsentNeeded(name, declared.permissions)
604
+ const provenance = await provenanceAt(name, declared.dist)
605
+ const refused = refusedBySignature(`${name}@${declared.version}`, provenance)
606
+ if (refused) return refused
607
+ // Pinned to the version whose tarball was checked, when one was.
608
+ const outcome = await added(
609
+ name,
610
+ version ? `${name}@${version}` : name,
611
+ version,
612
+ request,
613
+ declared.dist?.tarball ? { version: declared.version } : undefined,
614
+ )
615
+ return { ...outcome, provenance }
616
+ },
436
617
 
437
- const specifier = version ? `${name}@${version}` : name
438
- const result = await install('add', specifier, options.siteDir)
439
- options.extensions.invalidate()
440
- if (!result.ok)
441
- return {
442
- ok: false,
443
- message: result.output || `Installing ${specifier} failed.`,
444
- }
618
+ async inspect(name, version) {
619
+ if (!isValidPackageName(name))
620
+ return { ok: false, message: `'${name}' is not a package name npm would accept.` }
621
+ const declared = await declaresAt(name, version)
622
+ if (declared === 'unreachable')
623
+ return { ok: false, message: `The package registry could not say what ${name} contains.` }
624
+ if (declared === 'not-a-bundle')
625
+ return { ok: false, message: `${name} is not a bundle for this site.` }
626
+ const { dist, ...carries } = declared
627
+ return { ok: true, ...carries, provenance: await provenanceAt(name, dist) }
628
+ },
445
629
 
446
- const range = (await rangeFor(name)) ?? version ?? 'latest'
447
- const found = options.extensions
448
- .bundles()
449
- .bundles.find((bundle) => bundle.packageName === name)
450
- if (!found)
451
- return {
452
- ok: true,
453
- dependency: { name, range, version: version ?? range },
454
- message: `${name} was installed, but it is not a valid bundle, so nothing was added to the backoffice.`,
455
- }
456
- // The version that landed is what counts: a release published between
457
- // reading the registry and installing may have brought server code.
458
- if (found.carries.server && !consented(request, declaredPermissions(found))) {
459
- await install('remove', name, options.siteDir)
460
- options.extensions.invalidate()
461
- return serverConsentNeeded(
462
- name,
463
- declaredPermissions(found),
464
- `${name}@${found.version} turned out to run code on the server, or to ask for more than was granted, so it was removed again.`,
465
- )
630
+ async installFile(file, request = {}) {
631
+ if (options.installs === false) return refusedHere(file, 'add', options.installsElsewhere)
632
+ const declared = await declaresIn(file)
633
+ if (typeof declared === 'string') return { ok: false, message: declared }
634
+ if (declared.server && !consented(request, declared.permissions))
635
+ return serverConsentNeeded(declared.name, declared.permissions)
636
+ // Kept in the site's bundles/ (story 245), so it is committed and every
637
+ // node, checkout and CI build installs the same file.
638
+ const kept = keepInSite(file, declared)
639
+ if (typeof kept === 'string') return { ok: false, message: kept }
640
+ const discard = () => {
641
+ if (kept.copied) rmSync(join(options.siteDir, kept.path), { force: true })
466
642
  }
467
- // What was granted is recorded against the version that landed.
468
- if (found.carries.server) await options.grants?.grant(found, request.by ?? null)
469
-
470
- // The content half lands after the dependency, so a refused check leaves
471
- // the package installed and says why, rather than undoing an install that
472
- // succeeded.
473
- let content: ContentOutcome | undefined
474
- if (found.carries.content) {
475
- const declined = request.applyContent === false || options.applyContentOnInstall === false
476
- content =
477
- declined || !options.applyContent
478
- ? {
479
- applied: false,
480
- message: `Its content was not applied. Run \`crombolo bundle install ${name}\` to apply it.`,
481
- }
482
- : await options.applyContent(name).catch((error: unknown) => ({
483
- applied: false,
484
- message: `Its content could not be applied: ${error instanceof Error ? error.message : String(error)}`,
485
- }))
643
+ const provenance = await verifyPackage(join(options.siteDir, kept.path)).catch(
644
+ (error: unknown) => ({
645
+ state: 'unchecked' as const,
646
+ reason: error instanceof Error ? error.message : String(error),
647
+ }),
648
+ )
649
+ const refused = refusedBySignature(declared.name, provenance)
650
+ if (refused) {
651
+ discard()
652
+ return refused
653
+ }
654
+ const previous = await rangeFor(declared.name)
655
+ const outcome = await added(declared.name, `./${kept.path}`, undefined, request)
656
+ if (!outcome.ok) {
657
+ discard()
658
+ return { ...outcome, provenance }
486
659
  }
660
+ removeUnnamed(previous, kept.path)
487
661
  return {
488
- ok: true,
489
- dependency: { name, range, version: found.version },
490
- // The install lives in this node's node_modules until the dependency is
491
- // committed; saying so is the difference between a surprise and a plan.
492
- message: `${name}@${found.version} is installed. Commit the changed package.json and bun.lock to keep it across deployments.${
493
- found.carries.server
494
- ? " Its server code runs only once your site's developers turn it on and deploy the site."
495
- : ''
496
- }${found.carries.extensions ? ` ${SCREENS_NOTICE}` : ''}`,
497
- ...(content ? { content } : {}),
662
+ ...outcome,
663
+ provenance,
664
+ file: kept.path,
665
+ message: `${outcome.message} Commit ${kept.path} with package.json and bun.lock.`,
498
666
  }
499
667
  },
500
668
 
@@ -502,8 +670,10 @@ export function createMarketplace(options: MarketplaceOptions): Marketplace {
502
670
  if (options.installs === false) return refusedHere(name, 'remove', options.installsElsewhere)
503
671
  if (!isValidPackageName(name))
504
672
  return { ok: false, message: `'${name}' is not a package name npm would accept.` }
673
+ const previous = await rangeFor(name)
505
674
  const result = await install('remove', name, options.siteDir)
506
675
  options.extensions.invalidate()
676
+ if (result.ok) removeUnnamed(previous)
507
677
  return result.ok
508
678
  ? {
509
679
  ok: true,
@@ -512,6 +682,116 @@ export function createMarketplace(options: MarketplaceOptions): Marketplace {
512
682
  : { ok: false, message: result.output || `Removing ${name} failed.` }
513
683
  },
514
684
  }
685
+
686
+ /** `bun add`, then the checks on what landed, the grant, and the content half. */
687
+ async function added(
688
+ name: string,
689
+ specifier: string,
690
+ version: string | undefined,
691
+ request: {
692
+ applyContent?: boolean
693
+ acceptServerCode?: boolean
694
+ grant?: readonly string[]
695
+ by?: string | null
696
+ },
697
+ checked?: { version: string },
698
+ ): Promise<InstallOutcome> {
699
+ const result = await install('add', specifier, options.siteDir)
700
+ options.extensions.invalidate()
701
+ if (!result.ok)
702
+ return {
703
+ ok: false,
704
+ message: result.output || `Installing ${specifier} failed.`,
705
+ }
706
+
707
+ const range = (await rangeFor(name)) ?? version ?? 'latest'
708
+ const found = options.extensions.bundles().bundles.find((bundle) => bundle.packageName === name)
709
+ if (!found)
710
+ return {
711
+ ok: true,
712
+ dependency: { name, range, version: version ?? range },
713
+ message: `${name} was installed, but it is not a valid bundle, so nothing was added to the backoffice.`,
714
+ }
715
+ // The version whose signature was checked is the one that has to land
716
+ // (story 060): one published in between was never checked.
717
+ if (checked && found.version !== checked.version) {
718
+ await install('remove', name, options.siteDir)
719
+ options.extensions.invalidate()
720
+ return {
721
+ ok: false,
722
+ message: `${name}@${found.version} was published while ${checked.version} was being checked, so it was removed again. Try the install again.`,
723
+ }
724
+ }
725
+ // The version that landed is what counts: a release published between
726
+ // reading the registry and installing may have brought server code.
727
+ if (found.carries.server && !consented(request, declaredPermissions(found))) {
728
+ await install('remove', name, options.siteDir)
729
+ options.extensions.invalidate()
730
+ return serverConsentNeeded(
731
+ name,
732
+ declaredPermissions(found),
733
+ `${name}@${found.version} turned out to run code on the server, or to ask for more than was granted, so it was removed again.`,
734
+ )
735
+ }
736
+ // What was granted is recorded against the version that landed.
737
+ if (found.carries.server) await options.grants?.grant(found, request.by ?? null)
738
+
739
+ // The content half lands after the dependency, so a refused check leaves
740
+ // the package installed and says why, rather than undoing an install that
741
+ // succeeded.
742
+ let content: ContentOutcome | undefined
743
+ if (found.carries.content) {
744
+ const declined = request.applyContent === false || options.applyContentOnInstall === false
745
+ content =
746
+ declined || !options.applyContent
747
+ ? {
748
+ applied: false,
749
+ message: `Its content was not applied. Run \`crombolo bundle install ${name}\` to apply it.`,
750
+ }
751
+ : await options.applyContent(name).catch((error: unknown) => ({
752
+ applied: false,
753
+ message: `Its content could not be applied: ${error instanceof Error ? error.message : String(error)}`,
754
+ }))
755
+ }
756
+ return {
757
+ ok: true,
758
+ dependency: { name, range, version: found.version },
759
+ // The install lives in this node's node_modules until the dependency is
760
+ // committed; saying so is the difference between a surprise and a plan.
761
+ message: `${name}@${found.version} is installed. Commit the changed package.json and bun.lock to keep it across deployments.${
762
+ found.carries.server
763
+ ? " Its server code runs only once your site's developers turn it on and deploy the site."
764
+ : ''
765
+ }${found.carries.extensions ? ` ${SCREENS_NOTICE}` : ''}`,
766
+ ...(content ? { content } : {}),
767
+ }
768
+ }
769
+ }
770
+
771
+ /** What a packed bundle on this machine declares, read from its package.json, or why it cannot be installed. */
772
+ async function declaresIn(
773
+ file: string,
774
+ ): Promise<{ name: string; version: string; server: boolean; permissions: string[] } | string> {
775
+ const dir = mkdtempSync(join(tmpdir(), 'crombolo-bundle-file-'))
776
+ try {
777
+ await extractTarball(file, dir)
778
+ const root = existsSync(join(dir, 'package', 'package.json')) ? join(dir, 'package') : dir
779
+ const json = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')) as PackageJson
780
+ const problems = validateBundlePackage(json)
781
+ if (problems.length > 0 || typeof json.name !== 'string' || typeof json.version !== 'string')
782
+ return `${file} is not a bundle for this site, so it was not installed.`
783
+ const field = json.crombolo as { server?: string; permissions?: string[] }
784
+ return {
785
+ name: json.name,
786
+ version: json.version,
787
+ server: field.server !== undefined,
788
+ permissions: Array.isArray(field.permissions) ? field.permissions : [],
789
+ }
790
+ } catch {
791
+ return `${file} could not be read as a packed bundle, so it was not installed.`
792
+ } finally {
793
+ rmSync(dir, { recursive: true, force: true })
794
+ }
515
795
  }
516
796
 
517
797
  /** A package's own description, read leniently: anything unreadable is none. */
package/src/no-nodes.ts CHANGED
@@ -138,7 +138,7 @@ export function noNodesPage(options: { siteName: string; backOfficePath: string
138
138
  <h2>Configure page metadata</h2>
139
139
  <p>A content type says what a kind of page holds: a title, a summary, a body. Add one in the back office under <strong>Settings → Structure</strong>, or from the command line:</p>
140
140
  <pre><code>bunx crombolo types new content-type article --at-root
141
- bunx crombolo types add-property article summary --type textarea</code></pre>
141
+ bunx crombolo types property add article summary --type textarea</code></pre>
142
142
  <p>Either way it is saved as a file, <code>schema/content-types/article.toml</code>, so it travels with your code.</p>
143
143
  </li>
144
144
  <li>
@@ -55,6 +55,8 @@ export interface NodeOperationsOptions {
55
55
  webhooks?: WebhookService
56
56
  nudgeEvents?: () => void
57
57
  backOfficeUrl?: string
58
+ /** Where a large media branch's write is queued (story 246); made in the request when absent. */
59
+ background?: (queuedBy: string) => { enqueue(name: string, payload: unknown): Promise<string> }
58
60
  }
59
61
 
60
62
  export function createNodeOperations(options: NodeOperationsOptions): NodeOperations {
@@ -117,6 +119,7 @@ export function createNodeOperations(options: NodeOperationsOptions): NodeOperat
117
119
  // Only the items it touched: a media change leaves the pages alone (story 197).
118
120
  onChange: (change) => cache?.media?.apply(change),
119
121
  refusalReason,
122
+ background: options.background,
120
123
  })
121
124
  return { valueIntake: repository.valueIntake, tracker, approvals, documents, media }
122
125
  }
package/src/owner-jobs.ts CHANGED
@@ -15,6 +15,12 @@ import {
15
15
  import { type Cron, isTimezone, nextOccurrence, parseCron } from './cron.ts'
16
16
  import { logger } from './logging.ts'
17
17
 
18
+ /**
19
+ * Core's own queued work (story 246). A bundle's id is letters, digits and
20
+ * hyphens, so this can never be one.
21
+ */
22
+ export const CORE_JOB_OWNER = 'crombolo:core'
23
+
18
24
  /** The largest payload a job may carry, as JSON. */
19
25
  export const MAX_PAYLOAD_BYTES = 64 * 1024
20
26
  /** How many times a job runs before it is failed for good, unless it says otherwise. */