@crombolo/server 0.61.0 → 0.63.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.
- package/package.json +14 -14
- package/src/access.ts +5 -5
- package/src/adapters/content.ts +13 -1
- package/src/adapters/file-system.ts +27 -3
- package/src/adapters/template-files.ts +10 -0
- package/src/adapters/users.ts +55 -84
- package/src/bundle-admin.ts +21 -1
- package/src/bundle-api.ts +1 -3
- package/src/bundle-code.ts +93 -5
- package/src/bundle-install.ts +28 -5
- package/src/bundle-sections.ts +10 -0
- package/src/config.ts +46 -7
- package/src/content-query.ts +2 -4
- package/src/core.ts +83 -25
- package/src/extension-install.ts +631 -0
- package/src/extension-process.ts +30 -7
- package/src/external-sign-in.ts +10 -0
- package/src/form-workflows.ts +110 -12
- package/src/grant-policy.ts +23 -3
- package/src/grant-trust.ts +73 -0
- package/src/identity-provider-overrides.ts +186 -36
- package/src/identity-providers.ts +23 -0
- package/src/index.ts +7 -0
- package/src/marketplace.ts +54 -338
- package/src/member-auth.ts +5 -1
- package/src/outbound-address.ts +1 -1
- package/src/ports.ts +24 -7
- package/src/provenance.ts +13 -1
- package/src/remote.ts +23 -8
- package/src/server.ts +87 -3
- package/src/settings.ts +22 -0
- package/src/site-trust.ts +16 -0
- package/src/transfer-dashboard.ts +3 -0
package/src/marketplace.ts
CHANGED
|
@@ -17,12 +17,10 @@
|
|
|
17
17
|
* browser cannot reach npm, and the backoffice keeps making same-origin
|
|
18
18
|
* requests only.
|
|
19
19
|
*/
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import { join, relative, resolve, sep } from 'node:path'
|
|
20
|
+
import { readFileSync, rmSync } from 'node:fs'
|
|
21
|
+
import { join } from 'node:path'
|
|
23
22
|
import {
|
|
24
23
|
type AccessLevel,
|
|
25
|
-
askedPermissions,
|
|
26
24
|
type BundlePackage,
|
|
27
25
|
type DeclaredPermission,
|
|
28
26
|
describePermissions,
|
|
@@ -30,31 +28,19 @@ import {
|
|
|
30
28
|
type ExtensionRegistry,
|
|
31
29
|
forgetExtension,
|
|
32
30
|
groupsOf,
|
|
33
|
-
isSchema3Field,
|
|
34
31
|
LEGACY_EXTENSION_KEYWORD,
|
|
35
32
|
levelOf,
|
|
36
|
-
type PackageJson,
|
|
37
33
|
type PermissionGroups,
|
|
38
|
-
packageInRoot,
|
|
39
|
-
prepareRoot,
|
|
40
34
|
RECORD_FILE,
|
|
41
35
|
ROOTS_DIR,
|
|
42
36
|
readPackageJson,
|
|
43
37
|
readRecord,
|
|
44
|
-
readSettings,
|
|
45
|
-
recordExtension,
|
|
46
38
|
rootOf,
|
|
47
39
|
SCHEMA_3_NOT_INSTALLED,
|
|
48
40
|
SITE_PACKAGE_NOT_INSTALLED,
|
|
49
41
|
USER_DELEGATE,
|
|
50
|
-
validateBundlePackage,
|
|
51
42
|
} from '@crombolo/backoffice-host'
|
|
52
|
-
import {
|
|
53
|
-
LOCAL_BUNDLES_DIR,
|
|
54
|
-
localBundleFileName,
|
|
55
|
-
localBundlePath,
|
|
56
|
-
localBundlesNamed,
|
|
57
|
-
} from '@crombolo/transfer'
|
|
43
|
+
import { localBundlePath, localBundlesNamed } from '@crombolo/transfer'
|
|
58
44
|
import {
|
|
59
45
|
type BundleGrants,
|
|
60
46
|
DELEGATE_NEEDS_PERSON,
|
|
@@ -63,24 +49,40 @@ import {
|
|
|
63
49
|
isSchema3,
|
|
64
50
|
} from './bundle-grants.ts'
|
|
65
51
|
import { siteLayouts } from './components.ts'
|
|
52
|
+
import {
|
|
53
|
+
type AskedLayout,
|
|
54
|
+
bunInstaller,
|
|
55
|
+
declaresAt as declaresAtRegistry,
|
|
56
|
+
declaresIn,
|
|
57
|
+
installIntoRoot,
|
|
58
|
+
isValidPackageName,
|
|
59
|
+
isValidVersion,
|
|
60
|
+
keepInSite,
|
|
61
|
+
layoutAsked,
|
|
62
|
+
type PackageInstaller,
|
|
63
|
+
provenanceAt as provenanceAtRegistry,
|
|
64
|
+
screensOf,
|
|
65
|
+
signatureRefusal,
|
|
66
|
+
sitePackageRefused,
|
|
67
|
+
} from './extension-install.ts'
|
|
66
68
|
import { grantRefusal, type UnrestrictedFrom } from './grant-policy.ts'
|
|
67
69
|
import { logger } from './logging.ts'
|
|
68
70
|
import {
|
|
69
71
|
type ProvenancePolicy,
|
|
70
72
|
type ProvenanceResult,
|
|
71
|
-
provenanceProblem,
|
|
72
73
|
verifyPackage,
|
|
73
74
|
verifyProvenance,
|
|
74
75
|
} from './provenance.ts'
|
|
75
|
-
import { extractTarball } from './tar.ts'
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
export {
|
|
78
|
+
bunInstaller,
|
|
79
|
+
installCommand,
|
|
80
|
+
isValidPackageName,
|
|
81
|
+
isValidVersion,
|
|
82
|
+
type PackageInstaller,
|
|
83
|
+
} from './extension-install.ts'
|
|
78
84
|
|
|
79
|
-
|
|
80
|
-
interface Dist {
|
|
81
|
-
tarball?: string
|
|
82
|
-
integrity?: string
|
|
83
|
-
}
|
|
85
|
+
const log = logger('packages')
|
|
84
86
|
|
|
85
87
|
/** How long a search is reused. Long enough to page a list, short enough to stay fresh. */
|
|
86
88
|
const CACHE_MS = 5 * 60 * 1000
|
|
@@ -174,6 +176,8 @@ export interface MarketplaceOptions {
|
|
|
174
176
|
policy?: ProvenancePolicy
|
|
175
177
|
/** Checks a package directory's signature; `verifyProvenance`, unless a test stands in. */
|
|
176
178
|
verify?: (dir: string) => Promise<ProvenanceResult>
|
|
179
|
+
/** Whether a signature's signer is on this site's Trusted signers list (story 335). */
|
|
180
|
+
trustSigner?: (provenance: ProvenanceResult) => Promise<boolean>
|
|
177
181
|
}
|
|
178
182
|
|
|
179
183
|
export interface InstallOutcome {
|
|
@@ -224,12 +228,6 @@ export interface InstallOutcome {
|
|
|
224
228
|
file?: string
|
|
225
229
|
}
|
|
226
230
|
|
|
227
|
-
export type PackageInstaller = (
|
|
228
|
-
action: 'add' | 'remove',
|
|
229
|
-
specifier: string,
|
|
230
|
-
siteDir: string,
|
|
231
|
-
) => Promise<{ ok: boolean; output: string }>
|
|
232
|
-
|
|
233
231
|
interface SearchObject {
|
|
234
232
|
package?: {
|
|
235
233
|
name?: string
|
|
@@ -240,22 +238,6 @@ interface SearchObject {
|
|
|
240
238
|
}
|
|
241
239
|
}
|
|
242
240
|
|
|
243
|
-
/** A name npm would accept, so nothing shell-ish or path-ish reaches `bun add`. */
|
|
244
|
-
export function isValidPackageName(name: string): boolean {
|
|
245
|
-
return /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/.test(name) && name.length <= 214
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* A version or range that cannot be mistaken for another argument.
|
|
250
|
-
*
|
|
251
|
-
* Ranges start with an operator — `^2.1`, `>=1 <2` — so those lead; `-` never
|
|
252
|
-
* does, because `bun add` would read it as a flag. No shell is involved
|
|
253
|
-
* (`Bun.spawn` takes an argv), so the space in a range is harmless.
|
|
254
|
-
*/
|
|
255
|
-
export function isValidVersion(version: string): boolean {
|
|
256
|
-
return /^[A-Za-z0-9^~>=<*][A-Za-z0-9.^~>=<| *+-]*$/.test(version) && version.length <= 64
|
|
257
|
-
}
|
|
258
|
-
|
|
259
241
|
export interface Marketplace {
|
|
260
242
|
/** Where someone browsing should be sent, when they want more than this list. */
|
|
261
243
|
url(): string
|
|
@@ -307,63 +289,6 @@ export interface Marketplace {
|
|
|
307
289
|
uninstall(name: string): Promise<InstallOutcome>
|
|
308
290
|
}
|
|
309
291
|
|
|
310
|
-
/**
|
|
311
|
-
* The argv an install runs. `add` never runs a package's install scripts,
|
|
312
|
-
* whatever Bun's own list of trusted packages says (story 194).
|
|
313
|
-
*/
|
|
314
|
-
export function installCommand(action: 'add' | 'remove', specifier: string): string[] {
|
|
315
|
-
return action === 'add'
|
|
316
|
-
? ['bun', 'add', '--ignore-scripts', specifier]
|
|
317
|
-
: ['bun', action, specifier]
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* `bun add` in the site directory: Bun owns resolution and writes the lockfile.
|
|
322
|
-
*
|
|
323
|
-
* The spawn itself can fail rather than the command — an unreadable site
|
|
324
|
-
* directory or a `bun` that is not on the path both throw out of `Bun.spawn` —
|
|
325
|
-
* and that has to come back as a failed install with a reason, not as an
|
|
326
|
-
* exception the route turns into a 500.
|
|
327
|
-
*/
|
|
328
|
-
export const bunInstaller: PackageInstaller = async (action, specifier, siteDir) => {
|
|
329
|
-
try {
|
|
330
|
-
const proc = Bun.spawn(installCommand(action, specifier), {
|
|
331
|
-
cwd: siteDir,
|
|
332
|
-
stdout: 'pipe',
|
|
333
|
-
stderr: 'pipe',
|
|
334
|
-
})
|
|
335
|
-
const [stdout, stderr, code] = await Promise.all([
|
|
336
|
-
new Response(proc.stdout).text(),
|
|
337
|
-
new Response(proc.stderr).text(),
|
|
338
|
-
proc.exited,
|
|
339
|
-
])
|
|
340
|
-
return { ok: code === 0, output: `${stdout}${stderr}`.trim() }
|
|
341
|
-
} catch (error) {
|
|
342
|
-
return {
|
|
343
|
-
ok: false,
|
|
344
|
-
output: `bun ${action} could not be run in ${siteDir}: ${
|
|
345
|
-
error instanceof Error ? error.message : String(error)
|
|
346
|
-
}`,
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/** The layout setting a version declares, if it has page templates to place (story 312). */
|
|
352
|
-
type AskedLayout = { key: string; label: string; suggested?: string }
|
|
353
|
-
|
|
354
|
-
function layoutAsked(field: { settings?: unknown } | undefined): AskedLayout | undefined {
|
|
355
|
-
const read = readSettings(field?.settings)
|
|
356
|
-
if (!('settings' in read)) return undefined
|
|
357
|
-
const found = Object.entries(read.settings).find(([, setting]) => setting.type === 'layout')
|
|
358
|
-
if (!found) return undefined
|
|
359
|
-
const [key, setting] = found
|
|
360
|
-
return {
|
|
361
|
-
key,
|
|
362
|
-
label: setting.label,
|
|
363
|
-
...(typeof setting.default === 'string' ? { suggested: setting.default } : {}),
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
|
|
367
292
|
export function createMarketplace(options: MarketplaceOptions): Marketplace {
|
|
368
293
|
/** The site's layouts to pick from, the suggestion kept only when the site has it. */
|
|
369
294
|
const layoutChoice = (asked: AskedLayout | undefined): InstallOutcome['layout'] => {
|
|
@@ -399,28 +324,6 @@ export function createMarketplace(options: MarketplaceOptions): Marketplace {
|
|
|
399
324
|
}
|
|
400
325
|
let cached: { at: number; query: string; listings: MarketplaceListing[] } | undefined
|
|
401
326
|
|
|
402
|
-
/**
|
|
403
|
-
* A bundle's file at `bundles/<name>-<version>.tgz`: used in place when it is
|
|
404
|
-
* there already, copied there otherwise. Another file under that name is
|
|
405
|
-
* refused, since one version is one file.
|
|
406
|
-
*/
|
|
407
|
-
const keepInSite = (
|
|
408
|
-
file: string,
|
|
409
|
-
declared: { name: string; version: string },
|
|
410
|
-
): { path: string; copied: boolean } | string => {
|
|
411
|
-
const path = `${LOCAL_BUNDLES_DIR}/${localBundleFileName(declared.name, declared.version)}`
|
|
412
|
-
const target = join(options.siteDir, path)
|
|
413
|
-
if (resolve(file) === resolve(target)) return { path, copied: false }
|
|
414
|
-
const bytes = readFileSync(file)
|
|
415
|
-
if (existsSync(target)) {
|
|
416
|
-
if (readFileSync(target).equals(bytes)) return { path, copied: false }
|
|
417
|
-
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.`
|
|
418
|
-
}
|
|
419
|
-
mkdirSync(join(options.siteDir, LOCAL_BUNDLES_DIR), { recursive: true })
|
|
420
|
-
copyFileSync(file, target)
|
|
421
|
-
return { path, copied: true }
|
|
422
|
-
}
|
|
423
|
-
|
|
424
327
|
/** The `bundles/` file a dependency used to name, removed once nothing names it. */
|
|
425
328
|
const removeUnnamed = (previousRange: string | undefined, keep?: string) => {
|
|
426
329
|
const path = localBundlePath(previousRange)
|
|
@@ -433,135 +336,25 @@ export function createMarketplace(options: MarketplaceOptions): Marketplace {
|
|
|
433
336
|
options.extensions.bundles().bundles.find((bundle) => bundle.packageName === name)?.version ??
|
|
434
337
|
null
|
|
435
338
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
layout?: AskedLayout
|
|
448
|
-
version: string
|
|
449
|
-
dist?: Dist
|
|
450
|
-
id?: string
|
|
451
|
-
screens?: number
|
|
452
|
-
})
|
|
453
|
-
| 'not-a-bundle'
|
|
454
|
-
| { refused: string[] }
|
|
455
|
-
| 'site-package'
|
|
456
|
-
| 'schema-3'
|
|
457
|
-
| 'unreachable'
|
|
458
|
-
> => {
|
|
459
|
-
try {
|
|
460
|
-
const response = await call(`${options.registry}/${encodeURIComponent(name)}`, {
|
|
461
|
-
headers: { accept: 'application/json' },
|
|
462
|
-
})
|
|
463
|
-
if (!response.ok) return response.status === 404 ? 'not-a-bundle' : 'unreachable'
|
|
464
|
-
const packument = (await response.json()) as {
|
|
465
|
-
'dist-tags'?: Record<string, string>
|
|
466
|
-
versions?: Record<string, PackageJson>
|
|
467
|
-
}
|
|
468
|
-
const versions = packument.versions ?? {}
|
|
469
|
-
const resolved =
|
|
470
|
-
wanted === undefined
|
|
471
|
-
? packument['dist-tags']?.latest
|
|
472
|
-
: wanted in versions
|
|
473
|
-
? wanted
|
|
474
|
-
: (packument['dist-tags']?.[wanted] ??
|
|
475
|
-
Object.keys(versions)
|
|
476
|
-
.filter((v) => Bun.semver.satisfies(v, wanted))
|
|
477
|
-
.sort(Bun.semver.order)
|
|
478
|
-
.at(-1))
|
|
479
|
-
const version = resolved ? versions[resolved] : undefined
|
|
480
|
-
// A site package is never installed, whatever a registry offers (story 306).
|
|
481
|
-
if ((version?.crombolo as { bundleType?: unknown } | undefined)?.bundleType === 'site')
|
|
482
|
-
return 'site-package'
|
|
483
|
-
if (!resolved || !version) return 'not-a-bundle'
|
|
484
|
-
// Why it is not one, so its author knows what to change: a layout before 0.59 among them (story 320).
|
|
485
|
-
const problems = validateBundlePackage(version)
|
|
486
|
-
if (problems.length > 0) return { refused: problems }
|
|
487
|
-
const dist = (version as { dist?: Dist }).dist
|
|
488
|
-
const field = version.crombolo as {
|
|
489
|
-
extensions?: unknown[]
|
|
490
|
-
content?: boolean
|
|
491
|
-
id?: string
|
|
492
|
-
server?: string
|
|
493
|
-
permissions?: unknown
|
|
494
|
-
settings?: unknown
|
|
495
|
-
}
|
|
496
|
-
// Story 308: a version that says nothing of why it asks is not installed.
|
|
497
|
-
if (isSchema3Field(field)) return 'schema-3'
|
|
498
|
-
return {
|
|
499
|
-
extensions: Array.isArray(field.extensions) && field.extensions.length > 0,
|
|
500
|
-
content: field.content === true,
|
|
501
|
-
server: field.server !== undefined,
|
|
502
|
-
permissions: askedPermissions(field),
|
|
503
|
-
layout: layoutAsked(field),
|
|
504
|
-
version: resolved,
|
|
505
|
-
...(typeof field.id === 'string' ? { id: field.id } : {}),
|
|
506
|
-
screens: screensOf(field),
|
|
507
|
-
...(dist ? { dist } : {}),
|
|
508
|
-
}
|
|
509
|
-
} catch {
|
|
510
|
-
return 'unreachable'
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
const verify = options.verify ?? ((dir: string) => verifyProvenance(dir))
|
|
515
|
-
|
|
516
|
-
/**
|
|
517
|
-
* Where a registry version was built (story 060): its exact tarball fetched,
|
|
518
|
-
* held to the registry's integrity, and its signature checked, so the bytes
|
|
519
|
-
* checked are the bytes `bun add` then installs. A registry that gives no
|
|
520
|
-
* tarball leaves nothing to check; one that cannot be fetched is not unsigned.
|
|
521
|
-
*/
|
|
522
|
-
const provenanceAt = async (name: string, dist: Dist | undefined): Promise<ProvenanceResult> => {
|
|
523
|
-
if (!dist?.tarball) return { state: 'unsigned' }
|
|
524
|
-
const dir = mkdtempSync(join(tmpdir(), 'crombolo-bundle-check-'))
|
|
525
|
-
try {
|
|
526
|
-
const response = await call(dist.tarball)
|
|
527
|
-
if (!response.ok)
|
|
528
|
-
return {
|
|
529
|
-
state: 'unchecked',
|
|
530
|
-
reason: `${name} could not be fetched to check its signature (the registry answered ${response.status})`,
|
|
531
|
-
}
|
|
532
|
-
const bytes = new Uint8Array(await response.arrayBuffer())
|
|
533
|
-
if (dist.integrity?.startsWith('sha512-')) {
|
|
534
|
-
const got = `sha512-${new Bun.CryptoHasher('sha512').update(bytes).digest('base64')}`
|
|
535
|
-
if (got !== dist.integrity)
|
|
536
|
-
return { state: 'invalid', reason: `${name} is not the package the registry describes` }
|
|
537
|
-
}
|
|
538
|
-
const file = join(dir, 'bundle.tgz')
|
|
539
|
-
await Bun.write(file, bytes)
|
|
540
|
-
const unpacked = join(dir, 'package')
|
|
541
|
-
await extractTarball(file, unpacked)
|
|
542
|
-
return await verify(unpacked)
|
|
543
|
-
} catch (error) {
|
|
544
|
-
return {
|
|
545
|
-
state: 'unchecked',
|
|
546
|
-
reason: `${name} could not be checked: ${error instanceof Error ? error.message : String(error)}`,
|
|
547
|
-
}
|
|
548
|
-
} finally {
|
|
549
|
-
rmSync(dir, { recursive: true, force: true })
|
|
550
|
-
}
|
|
551
|
-
}
|
|
339
|
+
const declaresAt = (name: string, wanted?: string) =>
|
|
340
|
+
declaresAtRegistry(options.registry, name, wanted, call)
|
|
341
|
+
const verifyOnly = options.verify ?? ((dir: string) => verifyProvenance(dir))
|
|
342
|
+
/** A signature with whether its signer is trusted, asked fresh each time, since the list changes. */
|
|
343
|
+
const withTrust = async (result: ProvenanceResult): Promise<ProvenanceResult> =>
|
|
344
|
+
result.state === 'signed'
|
|
345
|
+
? { ...result, trusted: (await options.trustSigner?.(result)) ?? false }
|
|
346
|
+
: result
|
|
347
|
+
const verify = async (dir: string) => withTrust(await verifyOnly(dir))
|
|
348
|
+
const provenanceAt = (name: string, dist: Parameters<typeof provenanceAtRegistry>[1]) =>
|
|
349
|
+
provenanceAtRegistry(name, dist, { fetch: call, verify })
|
|
552
350
|
|
|
553
351
|
/** Why the site's policy refuses a version, as an outcome, or undefined when it may be installed. */
|
|
554
352
|
const refusedBySignature = (
|
|
555
353
|
label: string,
|
|
556
354
|
provenance: ProvenanceResult,
|
|
557
355
|
): InstallOutcome | undefined => {
|
|
558
|
-
const
|
|
559
|
-
|
|
560
|
-
options.policy ?? { signatures: 'optional', sources: [] },
|
|
561
|
-
)
|
|
562
|
-
return problem
|
|
563
|
-
? { ok: false, message: `${label} was not installed: ${problem}.`, provenance }
|
|
564
|
-
: undefined
|
|
356
|
+
const message = signatureRefusal(label, provenance, options.policy)
|
|
357
|
+
return message ? { ok: false, message, provenance } : undefined
|
|
565
358
|
}
|
|
566
359
|
|
|
567
360
|
/** Why the person may not grant what it asks for here: its level, by who they are and its signature (story 324). */
|
|
@@ -594,7 +387,7 @@ export function createMarketplace(options: MarketplaceOptions): Marketplace {
|
|
|
594
387
|
const key = `${bundle.packageName}@${bundle.version}`
|
|
595
388
|
let found = installedProvenance.get(key)
|
|
596
389
|
if (!found) {
|
|
597
|
-
found =
|
|
390
|
+
found = verifyOnly(bundle.directory).catch((error: unknown) => ({
|
|
598
391
|
state: 'unchecked' as const,
|
|
599
392
|
reason: error instanceof Error ? error.message : String(error),
|
|
600
393
|
}))
|
|
@@ -603,7 +396,7 @@ export function createMarketplace(options: MarketplaceOptions): Marketplace {
|
|
|
603
396
|
const result = await found
|
|
604
397
|
// Not kept: the next look may be able to check it.
|
|
605
398
|
if (result.state === 'unchecked') installedProvenance.delete(key)
|
|
606
|
-
return result
|
|
399
|
+
return withTrust(result)
|
|
607
400
|
}
|
|
608
401
|
|
|
609
402
|
/** What the registry says this package's latest version carries, when it is a valid bundle. */
|
|
@@ -828,16 +621,16 @@ export function createMarketplace(options: MarketplaceOptions): Marketplace {
|
|
|
828
621
|
return grantNeeded(declared.name, declared.permissions, '', layoutChoice(declared.layout))
|
|
829
622
|
// Kept in the site's bundles/ (story 245), so it is committed and every
|
|
830
623
|
// node, checkout and CI build installs the same file.
|
|
831
|
-
const kept = keepInSite(file, declared)
|
|
624
|
+
const kept = keepInSite(options.siteDir, file, declared)
|
|
832
625
|
if (typeof kept === 'string') return { ok: false, message: kept }
|
|
833
626
|
const discard = () => {
|
|
834
627
|
if (kept.copied) rmSync(join(options.siteDir, kept.path), { force: true })
|
|
835
628
|
}
|
|
836
|
-
const provenance = await
|
|
837
|
-
(error: unknown) => ({
|
|
629
|
+
const provenance = await withTrust(
|
|
630
|
+
await verifyPackage(join(options.siteDir, kept.path)).catch((error: unknown) => ({
|
|
838
631
|
state: 'unchecked' as const,
|
|
839
632
|
reason: error instanceof Error ? error.message : String(error),
|
|
840
|
-
}),
|
|
633
|
+
})),
|
|
841
634
|
)
|
|
842
635
|
const refused =
|
|
843
636
|
refusedBySignature(declared.name, provenance) ??
|
|
@@ -913,31 +706,14 @@ export function createMarketplace(options: MarketplaceOptions): Marketplace {
|
|
|
913
706
|
into: { id: string; integrity?: string },
|
|
914
707
|
): Promise<InstallOutcome> {
|
|
915
708
|
// Story 326: into a root of its own, never the site's dependencies.
|
|
916
|
-
const
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
const result = await install('add', inRoot, root)
|
|
921
|
-
if (!result.ok) {
|
|
922
|
-
options.extensions.invalidate()
|
|
923
|
-
return {
|
|
924
|
-
ok: false,
|
|
925
|
-
message: result.output || `Installing ${specifier} failed.`,
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
const landed = readPackageJson(
|
|
929
|
-
join(packageInRoot(options.siteDir, into.id, name), 'package.json'),
|
|
709
|
+
const installed = await installIntoRoot(
|
|
710
|
+
options.siteDir,
|
|
711
|
+
{ id: into.id, name, specifier, version, integrity: into.integrity },
|
|
712
|
+
install,
|
|
930
713
|
)
|
|
931
|
-
recordExtension(options.siteDir, into.id, {
|
|
932
|
-
name,
|
|
933
|
-
version: landed?.version ?? version ?? 'unknown',
|
|
934
|
-
...(into.integrity ? { integrity: into.integrity } : {}),
|
|
935
|
-
})
|
|
936
714
|
options.extensions.invalidate()
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
forgetExtension(options.siteDir, into.id)
|
|
940
|
-
}
|
|
715
|
+
if (!installed.ok) return { ok: false, message: installed.message }
|
|
716
|
+
const undo = installed.undo
|
|
941
717
|
|
|
942
718
|
const range = (await rangeFor(name)) ?? version ?? 'latest'
|
|
943
719
|
const discovered = options.extensions.bundles()
|
|
@@ -1030,58 +806,6 @@ export function createMarketplace(options: MarketplaceOptions): Marketplace {
|
|
|
1030
806
|
}
|
|
1031
807
|
}
|
|
1032
808
|
|
|
1033
|
-
/** A site package offered as a dependency: refused, saying how one is used (story 306). */
|
|
1034
|
-
function sitePackageRefused(name: string): { ok: false; message: string } {
|
|
1035
|
-
return {
|
|
1036
|
-
ok: false,
|
|
1037
|
-
message: `${name} is a site package, which is applied to a site with \`crombolo site apply\`, never installed, so it was not installed.`,
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
/** What a packed bundle on this machine declares, read from its package.json, or why it cannot be installed. */
|
|
1042
|
-
async function declaresIn(file: string): Promise<
|
|
1043
|
-
| {
|
|
1044
|
-
id: string
|
|
1045
|
-
name: string
|
|
1046
|
-
version: string
|
|
1047
|
-
server: boolean
|
|
1048
|
-
permissions: DeclaredPermission[]
|
|
1049
|
-
layout?: AskedLayout
|
|
1050
|
-
}
|
|
1051
|
-
| string
|
|
1052
|
-
> {
|
|
1053
|
-
const dir = mkdtempSync(join(tmpdir(), 'crombolo-bundle-file-'))
|
|
1054
|
-
try {
|
|
1055
|
-
await extractTarball(file, dir)
|
|
1056
|
-
const root = existsSync(join(dir, 'package', 'package.json')) ? join(dir, 'package') : dir
|
|
1057
|
-
const json = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')) as PackageJson
|
|
1058
|
-
if ((json.crombolo as { bundleType?: unknown } | undefined)?.bundleType === 'site')
|
|
1059
|
-
return sitePackageRefused(file).message
|
|
1060
|
-
const problems = validateBundlePackage(json)
|
|
1061
|
-
if (problems.length > 0 || typeof json.name !== 'string' || typeof json.version !== 'string')
|
|
1062
|
-
return `${file} is not an extension for this site, so it was not installed.`
|
|
1063
|
-
const field = json.crombolo as {
|
|
1064
|
-
id: string
|
|
1065
|
-
server?: string
|
|
1066
|
-
permissions?: unknown
|
|
1067
|
-
settings?: unknown
|
|
1068
|
-
}
|
|
1069
|
-
if (isSchema3Field(field)) return `${file} was not installed: ${SCHEMA_3_NOT_INSTALLED}.`
|
|
1070
|
-
return {
|
|
1071
|
-
id: field.id,
|
|
1072
|
-
name: json.name,
|
|
1073
|
-
version: json.version,
|
|
1074
|
-
server: field.server !== undefined,
|
|
1075
|
-
permissions: askedPermissions(field),
|
|
1076
|
-
layout: layoutAsked(field),
|
|
1077
|
-
}
|
|
1078
|
-
} catch {
|
|
1079
|
-
return `${file} could not be read as a packed bundle, so it was not installed.`
|
|
1080
|
-
} finally {
|
|
1081
|
-
rmSync(dir, { recursive: true, force: true })
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
809
|
/** A package's own description, read leniently: anything unreadable is none. */
|
|
1086
810
|
/** Who made an installed package, as its `author` says: npm's publisher is not kept with it. */
|
|
1087
811
|
function authorOf(directory: string): string | null {
|
|
@@ -1132,14 +856,6 @@ function consented(
|
|
|
1132
856
|
return granted.size === new Set(permissions).size && permissions.every((p) => granted.has(p))
|
|
1133
857
|
}
|
|
1134
858
|
|
|
1135
|
-
/** How many screens its manifest's entries name (story 323), for what it adds. */
|
|
1136
|
-
const screensOf = (field: { extensions?: unknown }): number =>
|
|
1137
|
-
Array.isArray(field.extensions)
|
|
1138
|
-
? field.extensions.filter(
|
|
1139
|
-
(entry) => entry && typeof entry === 'object' && 'screen' in (entry as object),
|
|
1140
|
-
).length
|
|
1141
|
-
: 0
|
|
1142
|
-
|
|
1143
859
|
/** A refusal the screen answers by showing what it asks for, with the reasons, and the grant. */
|
|
1144
860
|
function grantNeeded(
|
|
1145
861
|
name: string,
|
package/src/member-auth.ts
CHANGED
|
@@ -282,7 +282,11 @@ export function createMemberAuth(
|
|
|
282
282
|
applicationUrl: config.applicationUrl,
|
|
283
283
|
secureCookies: config.secureCookies,
|
|
284
284
|
resolve: (provider) =>
|
|
285
|
-
new IdentityProviderOverrides(
|
|
285
|
+
new IdentityProviderOverrides(
|
|
286
|
+
db,
|
|
287
|
+
config.secretKey,
|
|
288
|
+
config.lockedIdentityProviders,
|
|
289
|
+
).apply('member', provider),
|
|
286
290
|
},
|
|
287
291
|
)
|
|
288
292
|
|
package/src/outbound-address.ts
CHANGED
|
@@ -122,7 +122,7 @@ export async function checkedAddress(
|
|
|
122
122
|
const reason = refusedAddress(address)
|
|
123
123
|
if (reason)
|
|
124
124
|
throw new OutboundRefused(
|
|
125
|
-
`${host === address ? host : `${host} (${address})`} is ${reason}, which this site does not send to.
|
|
125
|
+
`${host === address ? host : `${host} (${address})`} is ${reason}, which this site does not send to. CROMBOLO_ALLOW_PRIVATE_ADDRESSES allows it.`,
|
|
126
126
|
)
|
|
127
127
|
}
|
|
128
128
|
return addresses[0]
|
package/src/ports.ts
CHANGED
|
@@ -122,7 +122,8 @@ function createServerPort(config: CromboloConfig, canSendUserLinks: boolean): Se
|
|
|
122
122
|
version: VERSION,
|
|
123
123
|
assemblyVersion: VERSION,
|
|
124
124
|
baseUtcOffset: '00:00:00',
|
|
125
|
-
|
|
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',
|
|
126
127
|
}),
|
|
127
128
|
}
|
|
128
129
|
}
|
|
@@ -476,10 +477,14 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
|
|
|
476
477
|
// through the partial-view file API because that one is path-addressed and
|
|
477
478
|
// already understands folders; the template API is id-addressed and cannot
|
|
478
479
|
// express a folder at all.
|
|
479
|
-
|
|
480
|
+
const readOnly = options.config.contentFilesReadOnly
|
|
481
|
+
deps.components = createComponentsPort(options.config.componentsDir, readOnly)
|
|
480
482
|
deps.componentSnippets = COMPONENT_SNIPPETS
|
|
481
|
-
deps.stylesheets = createFileSystemPort(options.config.stylesheetsDir, {
|
|
482
|
-
|
|
483
|
+
deps.stylesheets = createFileSystemPort(options.config.stylesheetsDir, {
|
|
484
|
+
extension: '.css',
|
|
485
|
+
readOnly,
|
|
486
|
+
})
|
|
487
|
+
deps.scripts = createFileSystemPort(options.config.scriptsDir, { extension: '.js', readOnly })
|
|
483
488
|
if (options.db) {
|
|
484
489
|
const dynamicRoots = new DynamicRootRepository(options.db)
|
|
485
490
|
deps.dynamicRoots = { resolve: (query) => dynamicRoots.resolve(query) }
|
|
@@ -567,7 +572,11 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
|
|
|
567
572
|
})
|
|
568
573
|
deps.contentTypes = createContentTypePort(options.db, schemaFiles(options.config), {
|
|
569
574
|
nodeState: options.schema?.nodeState,
|
|
570
|
-
componentFiles: createTemplateFileStore(
|
|
575
|
+
componentFiles: createTemplateFileStore(
|
|
576
|
+
options.config.componentsDir,
|
|
577
|
+
options.onViewsChange,
|
|
578
|
+
options.config.contentFilesReadOnly,
|
|
579
|
+
),
|
|
571
580
|
})
|
|
572
581
|
deps.mediaTypes = createContentTypePort(options.db, schemaFiles(options.config), {
|
|
573
582
|
nodeState: options.schema?.nodeState,
|
|
@@ -580,7 +589,11 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
|
|
|
580
589
|
deps.dataTypes = createDataTypePort(options.db, schemaFiles(options.config))
|
|
581
590
|
deps.templates = createTemplatePort(
|
|
582
591
|
options.db,
|
|
583
|
-
createTemplateFileStore(
|
|
592
|
+
createTemplateFileStore(
|
|
593
|
+
options.config.componentsDir,
|
|
594
|
+
options.onViewsChange,
|
|
595
|
+
options.config.contentFilesReadOnly,
|
|
596
|
+
),
|
|
584
597
|
)
|
|
585
598
|
deps.logViewer = createLogViewerPort(options.db, options.config)
|
|
586
599
|
deps.modelsBuilder = createModelsBuilderPort(options.config)
|
|
@@ -625,7 +638,11 @@ export function createDeps(options: DepsOptions): ManagementApiDeps {
|
|
|
625
638
|
nodeId: options.config.nodeId,
|
|
626
639
|
marketplaceUrl: options.config.marketplaceUrl,
|
|
627
640
|
secretKey: options.config.secretKey,
|
|
628
|
-
componentFiles: createTemplateFileStore(
|
|
641
|
+
componentFiles: createTemplateFileStore(
|
|
642
|
+
options.config.componentsDir,
|
|
643
|
+
options.onViewsChange,
|
|
644
|
+
options.config.contentFilesReadOnly,
|
|
645
|
+
),
|
|
629
646
|
mediaStore: mediaFiles.store,
|
|
630
647
|
components: deps.components,
|
|
631
648
|
stylesheets: deps.stylesheets,
|
package/src/provenance.ts
CHANGED
|
@@ -122,6 +122,11 @@ export interface ProvenanceResult {
|
|
|
122
122
|
package?: { name: string; version: string }
|
|
123
123
|
/** Why a signature was not accepted, in words a person can act on. */
|
|
124
124
|
reason?: string
|
|
125
|
+
/**
|
|
126
|
+
* Whether its signer is on this site's Trusted signers list (story 335), set by
|
|
127
|
+
* whoever asked; only a trusted signer vouches for an upper level.
|
|
128
|
+
*/
|
|
129
|
+
trusted?: boolean
|
|
125
130
|
}
|
|
126
131
|
|
|
127
132
|
/** A package's `provenance.json`, when it has one that reads. */
|
|
@@ -296,7 +301,14 @@ export function describeProvenance(result: ProvenanceResult): string {
|
|
|
296
301
|
? `signed by ${result.key.comment || 'a key'} (${result.key.fingerprint})`
|
|
297
302
|
: undefined
|
|
298
303
|
const said = [built, key].filter(Boolean).join(', and ')
|
|
299
|
-
|
|
304
|
+
// Story 335: said only where someone asked this site's list.
|
|
305
|
+
const trust =
|
|
306
|
+
result.trusted === undefined
|
|
307
|
+
? ''
|
|
308
|
+
: result.trusted
|
|
309
|
+
? '; this site trusts its signer'
|
|
310
|
+
: "; this site doesn't trust its signer"
|
|
311
|
+
return `Signed: ${said}${trust}`
|
|
300
312
|
}
|
|
301
313
|
case 'unsigned':
|
|
302
314
|
return 'Not signed'
|