@crombolo/backoffice-host 0.58.1 → 0.59.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 +3 -3
- package/plugin/app-preview/umbraco-package.json +1 -1
- package/plugin/bundles-backoffice-code-words.js +34 -0
- package/plugin/bundles-backoffice-code.js +51 -0
- package/plugin/bundles-installed.js +23 -2
- package/plugin/bundles-marketplace.js +30 -3
- package/plugin/localizations/umbraco-package.json +1 -1
- package/plugin/seo/umbraco-package.json +1 -1
- package/plugin/sign-in/umbraco-package.json +1 -1
- package/plugin/umbraco-package.json +1 -1
- package/src/bundle-package.ts +142 -20
- package/src/bundle-permissions.ts +24 -6
- package/src/extensions.ts +28 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/backoffice-host",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.59.0",
|
|
4
4
|
"description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. Serves the Umbraco backoffice SPA: shell HTML, import map and package manifests.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@crombolo/core": "0.
|
|
36
|
-
"@crombolo/backoffice-dist": "0.
|
|
35
|
+
"@crombolo/core": "0.59.0",
|
|
36
|
+
"@crombolo/backoffice-dist": "0.59.0"
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the Extensions screens say when an extension asks to run code in the back
|
|
3
|
+
* office (story 320): it acts as whoever is signed in, it can't be kept apart
|
|
4
|
+
* like the rest of an extension, and it is installed only from a publisher you
|
|
5
|
+
* trust, named here with what its signature shows. Pure, so it is tested
|
|
6
|
+
* without a browser.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** The permission an extension's back-office code needs. */
|
|
10
|
+
export const BACKOFFICE_CODE = 'backoffice.code'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {{ allows: string, reason?: string | null, warning?: string }} ask the permission as the server describes it
|
|
14
|
+
* @param {string | null | undefined} publisher who published it, when the registry says
|
|
15
|
+
* @param {{ label: string, detail: string } | undefined} signature `signatureWords`' reading of its signature
|
|
16
|
+
*/
|
|
17
|
+
export function backOfficeCodeWords(ask, publisher, signature) {
|
|
18
|
+
return {
|
|
19
|
+
label: ask.allows,
|
|
20
|
+
reason: ask.reason ?? '',
|
|
21
|
+
warning: ask.warning ?? '',
|
|
22
|
+
publisher: publisher ? `Published by ${publisher}.` : "Who published this isn't known.",
|
|
23
|
+
signature: signature ? `${signature.label}. ${signature.detail}` : '',
|
|
24
|
+
confirm: `I trust ${publisher ?? 'its publisher'} to act as anyone signed in to this back office`,
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The back-office code a set of asks includes, and the rest, so it is shown first and apart. */
|
|
29
|
+
export function splitBackOfficeCode(asks) {
|
|
30
|
+
return {
|
|
31
|
+
code: asks.find((ask) => ask.permission === BACKOFFICE_CODE),
|
|
32
|
+
rest: asks.filter((ask) => ask.permission !== BACKOFFICE_CODE),
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The warning an extension's back-office code is granted under (story 320), with
|
|
3
|
+
* its own confirmation, shared by the Marketplace's install and Installed's grant.
|
|
4
|
+
*/
|
|
5
|
+
import { css, html } from '@umbraco-cms/backoffice/external/lit'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {ReturnType<typeof import('./bundles-backoffice-code-words.js').backOfficeCodeWords>} words
|
|
9
|
+
* @param {boolean} confirmed
|
|
10
|
+
* @param {((confirmed: boolean) => void) | undefined} onConfirm absent once it is granted: there is nothing to confirm
|
|
11
|
+
*/
|
|
12
|
+
export function backOfficeCodeBlock(words, confirmed, onConfirm) {
|
|
13
|
+
return html`
|
|
14
|
+
<div class="backoffice-code" role="alert">
|
|
15
|
+
<p class="heading"><uui-icon name="icon-alert"></uui-icon><strong>${words.label}</strong></p>
|
|
16
|
+
${words.reason ? html`<p class="reason">${words.reason}</p>` : ''}
|
|
17
|
+
<p>${words.warning}</p>
|
|
18
|
+
<p>${words.publisher} ${words.signature}</p>
|
|
19
|
+
${
|
|
20
|
+
onConfirm
|
|
21
|
+
? html`<uui-checkbox
|
|
22
|
+
label=${words.confirm}
|
|
23
|
+
.checked=${confirmed}
|
|
24
|
+
@change=${(event) => onConfirm(event.target.checked)}></uui-checkbox>`
|
|
25
|
+
: ''
|
|
26
|
+
}
|
|
27
|
+
</div>
|
|
28
|
+
`
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const backOfficeCodeStyles = css`
|
|
32
|
+
.backoffice-code {
|
|
33
|
+
margin: var(--uui-size-space-3) 0;
|
|
34
|
+
padding: var(--uui-size-space-4);
|
|
35
|
+
border: 1px solid var(--uui-color-warning-standalone, var(--uui-color-warning));
|
|
36
|
+
border-radius: var(--uui-border-radius);
|
|
37
|
+
background: var(--uui-color-warning-surface, var(--uui-color-surface-alt));
|
|
38
|
+
}
|
|
39
|
+
.backoffice-code p {
|
|
40
|
+
margin: 0 0 var(--uui-size-space-2);
|
|
41
|
+
}
|
|
42
|
+
.backoffice-code .heading {
|
|
43
|
+
display: flex;
|
|
44
|
+
align-items: center;
|
|
45
|
+
gap: var(--uui-size-space-2);
|
|
46
|
+
color: var(--uui-color-warning-standalone, var(--uui-color-warning-emphasis));
|
|
47
|
+
}
|
|
48
|
+
.backoffice-code .reason {
|
|
49
|
+
color: var(--uui-color-text-alt);
|
|
50
|
+
}
|
|
51
|
+
`
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { css, html, nothing, repeat } from '@umbraco-cms/backoffice/external/lit'
|
|
17
17
|
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
|
|
18
|
+
import { backOfficeCodeBlock, backOfficeCodeStyles } from './bundles-backoffice-code.js'
|
|
19
|
+
import { backOfficeCodeWords, splitBackOfficeCode } from './bundles-backoffice-code-words.js'
|
|
18
20
|
import { carriesTags } from './bundles-carries.js'
|
|
19
21
|
import {
|
|
20
22
|
disableBundle,
|
|
@@ -63,6 +65,7 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
|
|
|
63
65
|
_policy: { state: true },
|
|
64
66
|
_actAs: { state: true },
|
|
65
67
|
_edits: { state: true },
|
|
68
|
+
_trustsCode: { state: true },
|
|
66
69
|
}
|
|
67
70
|
|
|
68
71
|
constructor() {
|
|
@@ -234,7 +237,10 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
|
|
|
234
237
|
|
|
235
238
|
/** What it may do with the site, who approved it, and the button that turns it off or on. */
|
|
236
239
|
#permissions(item) {
|
|
237
|
-
|
|
240
|
+
// Back-office code first and apart, confirmed on its own before it is granted (story 320).
|
|
241
|
+
const { code, rest: asks } = splitBackOfficeCode(item.permissions ?? [])
|
|
242
|
+
const granting = item.status === 'waiting' || item.status === 'not-granted'
|
|
243
|
+
const confirmed = this._trustsCode === item.packageName
|
|
238
244
|
const approved = item.granted
|
|
239
245
|
? item.granted.by === "the site's code"
|
|
240
246
|
? `Developer installed, on ${new Date(item.granted.at).toLocaleDateString()}.`
|
|
@@ -243,7 +249,20 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
|
|
|
243
249
|
return html`
|
|
244
250
|
<h4>What it may do</h4>
|
|
245
251
|
${
|
|
246
|
-
|
|
252
|
+
code
|
|
253
|
+
? backOfficeCodeBlock(
|
|
254
|
+
backOfficeCodeWords(code, item.publisher, this.#words(item)),
|
|
255
|
+
confirmed,
|
|
256
|
+
granting
|
|
257
|
+
? (yes) => {
|
|
258
|
+
this._trustsCode = yes ? item.packageName : ''
|
|
259
|
+
}
|
|
260
|
+
: undefined,
|
|
261
|
+
)
|
|
262
|
+
: nothing
|
|
263
|
+
}
|
|
264
|
+
${
|
|
265
|
+
asks.length === 0 && !code
|
|
247
266
|
? html`<p>Nothing beyond its own data: it asks for no access to the site's content, members or settings.</p>`
|
|
248
267
|
: html`<ul class="asks">
|
|
249
268
|
${asks.map(
|
|
@@ -305,6 +324,7 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
|
|
|
305
324
|
<uui-button
|
|
306
325
|
look="primary"
|
|
307
326
|
label="Grant"
|
|
327
|
+
?disabled=${Boolean(code) && !confirmed}
|
|
308
328
|
.state=${this._busy === item.packageName ? 'waiting' : undefined}
|
|
309
329
|
@click=${() => this.#grant(item)}></uui-button>`
|
|
310
330
|
: item.on
|
|
@@ -440,6 +460,7 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
|
|
|
440
460
|
|
|
441
461
|
static styles = [
|
|
442
462
|
signatureStyles,
|
|
463
|
+
backOfficeCodeStyles,
|
|
443
464
|
css`
|
|
444
465
|
.asks {
|
|
445
466
|
padding-left: 1.25em;
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { css, html, nothing, repeat } from '@umbraco-cms/backoffice/external/lit'
|
|
17
17
|
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
|
|
18
|
+
import { backOfficeCodeBlock, backOfficeCodeStyles } from './bundles-backoffice-code.js'
|
|
19
|
+
import { backOfficeCodeWords, splitBackOfficeCode } from './bundles-backoffice-code-words.js'
|
|
18
20
|
import { carriesTags } from './bundles-carries.js'
|
|
19
21
|
import { bundleSignature, installBundle, searchMarketplace } from './bundles-client.js'
|
|
20
22
|
import { signatureBlock, signatureStyles, signatureWords } from './bundles-signature.js'
|
|
@@ -34,6 +36,7 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
|
|
|
34
36
|
_elsewhere: { state: true },
|
|
35
37
|
_consenting: { state: true },
|
|
36
38
|
_trusted: { state: true },
|
|
39
|
+
_trustsCode: { state: true },
|
|
37
40
|
_asks: { state: true },
|
|
38
41
|
_asksActAs: { state: true },
|
|
39
42
|
_layout: { state: true },
|
|
@@ -161,6 +164,7 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
|
|
|
161
164
|
#askConsent(item, outcome) {
|
|
162
165
|
this._consenting = item.name
|
|
163
166
|
this._trusted = false
|
|
167
|
+
this._trustsCode = false
|
|
164
168
|
this._asks = outcome.permissions ?? []
|
|
165
169
|
this._asksActAs = outcome.asksActAs === true
|
|
166
170
|
// Story 312: the site layout its page templates sit in, its suggestion first.
|
|
@@ -168,9 +172,14 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
|
|
|
168
172
|
this._layoutChoice = outcome.layout?.suggested ?? ''
|
|
169
173
|
}
|
|
170
174
|
|
|
175
|
+
#asksForCode() {
|
|
176
|
+
return Boolean(splitBackOfficeCode(this._asks).code)
|
|
177
|
+
}
|
|
178
|
+
|
|
171
179
|
#cancelConsent() {
|
|
172
180
|
this._consenting = ''
|
|
173
181
|
this._trusted = false
|
|
182
|
+
this._trustsCode = false
|
|
174
183
|
this._asks = []
|
|
175
184
|
}
|
|
176
185
|
|
|
@@ -233,15 +242,32 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
|
|
|
233
242
|
|
|
234
243
|
/** What it asks for, each permission with its reason, granted together in its own card. */
|
|
235
244
|
#consent(item) {
|
|
245
|
+
// Back-office code first and apart, with a confirmation of its own (story 320).
|
|
246
|
+
const { code, rest } = splitBackOfficeCode(this._asks)
|
|
247
|
+
const checked = this._signatures.get(item.name)
|
|
248
|
+
const signature = checked
|
|
249
|
+
? signatureWords(checked.provenance, checked.refused, checked.policy)
|
|
250
|
+
: undefined
|
|
236
251
|
return html`
|
|
237
252
|
<div class="consent" role="group" aria-label="What it asks for">
|
|
238
253
|
${this.#signature(item)}
|
|
254
|
+
${
|
|
255
|
+
code
|
|
256
|
+
? backOfficeCodeBlock(
|
|
257
|
+
backOfficeCodeWords(code, item.publisher, signature),
|
|
258
|
+
this._trustsCode,
|
|
259
|
+
(confirmed) => {
|
|
260
|
+
this._trustsCode = confirmed
|
|
261
|
+
},
|
|
262
|
+
)
|
|
263
|
+
: nothing
|
|
264
|
+
}
|
|
239
265
|
<p>
|
|
240
266
|
<strong>It asks for these permissions.</strong> Grant them to install it: it may do only
|
|
241
|
-
this
|
|
267
|
+
this.
|
|
242
268
|
</p>
|
|
243
269
|
<ul class="asks">
|
|
244
|
-
${
|
|
270
|
+
${rest.map(
|
|
245
271
|
(ask) =>
|
|
246
272
|
html`<li>
|
|
247
273
|
${ask.allows}${ask.origins?.length ? html`: ${ask.origins.join(', ')}` : nothing}
|
|
@@ -303,7 +329,7 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
|
|
|
303
329
|
look="primary"
|
|
304
330
|
color="warning"
|
|
305
331
|
label="Grant and install"
|
|
306
|
-
?disabled=${!this._trusted}
|
|
332
|
+
?disabled=${!this._trusted || (this.#asksForCode() && !this._trustsCode)}
|
|
307
333
|
.state=${this._busy === item.name ? 'waiting' : undefined}
|
|
308
334
|
@click=${() => this.#install(item, true)}></uui-button>
|
|
309
335
|
<uui-button look="secondary" label="Cancel" @click=${this.#cancelConsent}></uui-button>
|
|
@@ -399,6 +425,7 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
|
|
|
399
425
|
|
|
400
426
|
static styles = [
|
|
401
427
|
signatureStyles,
|
|
428
|
+
backOfficeCodeStyles,
|
|
402
429
|
css`
|
|
403
430
|
:host {
|
|
404
431
|
display: block;
|
package/src/bundle-package.ts
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* marketplace, the server half and the installer cannot disagree about what a
|
|
7
7
|
* bundle is.
|
|
8
8
|
*/
|
|
9
|
-
import { existsSync, readFileSync, statSync } from 'node:fs'
|
|
9
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
|
|
10
10
|
import { dirname, join, normalize } from 'node:path'
|
|
11
|
-
import { permissionsProblem, readSettings } from './bundle-permissions.ts'
|
|
11
|
+
import { BACKOFFICE_CODE, permissionsProblem, readSettings } from './bundle-permissions.ts'
|
|
12
12
|
import type { PackageManifestImportmap } from './manifests.ts'
|
|
13
13
|
|
|
14
14
|
/** The package a bundle declares its peer range on. */
|
|
@@ -83,20 +83,82 @@ export interface CromboloField {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
|
-
* The bundle schema
|
|
87
|
-
*
|
|
86
|
+
* The bundle schema an extension with code must be written for: 5 put its server
|
|
87
|
+
* half in `src/server/` and its back-office code in `src/backoffice/` (story 320);
|
|
88
|
+
* 4 gave each permission a reason (308); 3 declared them (222); 2 made its routes
|
|
89
|
+
* route handlers (211).
|
|
88
90
|
*/
|
|
89
|
-
export const BUNDLE_SCHEMA_VERSION =
|
|
91
|
+
export const BUNDLE_SCHEMA_VERSION = 5
|
|
92
|
+
|
|
93
|
+
/** The oldest schema read: an extension at 4 or before is refused until it is migrated (story 320). */
|
|
94
|
+
export const OLDEST_BUNDLE_SCHEMA_VERSION = 5
|
|
90
95
|
|
|
91
96
|
/**
|
|
92
|
-
* The oldest
|
|
93
|
-
*
|
|
97
|
+
* The oldest server half the site's config may still wire in itself: its own
|
|
98
|
+
* code, run in the CMS, so the layout does not apply, only the routes and
|
|
99
|
+
* permissions it is written against (stories 211, 222).
|
|
94
100
|
*/
|
|
95
|
-
export const
|
|
101
|
+
export const OLDEST_WIRED_SCHEMA_VERSION = 3
|
|
102
|
+
|
|
103
|
+
/** Where an extension's server half lives (story 320). */
|
|
104
|
+
export const SERVER_DIR = 'src/server'
|
|
105
|
+
|
|
106
|
+
/** Where an extension's back-office code lives (story 320). */
|
|
107
|
+
export const BACKOFFICE_DIR = 'src/backoffice'
|
|
108
|
+
|
|
109
|
+
/** The manifest keys that name a module, in an entry and nested in it. */
|
|
110
|
+
const MODULE_KEYS = new Set(['element', 'api', 'js', 'loader'])
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Every module an extension's manifest names: its entries' `element`, `api`,
|
|
114
|
+
* `js` and `loader`, however deep, and its import map's targets. Pure.
|
|
115
|
+
*/
|
|
116
|
+
export function backOfficeModules(field: { extensions?: unknown; importmap?: unknown }): string[] {
|
|
117
|
+
const found = new Set<string>()
|
|
118
|
+
const walk = (value: unknown) => {
|
|
119
|
+
if (Array.isArray(value)) for (const item of value) walk(item)
|
|
120
|
+
else if (value && typeof value === 'object')
|
|
121
|
+
for (const [key, item] of Object.entries(value as Record<string, unknown>)) {
|
|
122
|
+
if (MODULE_KEYS.has(key) && typeof item === 'string') found.add(item)
|
|
123
|
+
else walk(item)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
walk(field.extensions)
|
|
127
|
+
const importmap = field.importmap as
|
|
128
|
+
| { imports?: Record<string, unknown>; scopes?: Record<string, Record<string, unknown>> }
|
|
129
|
+
| undefined
|
|
130
|
+
for (const target of Object.values(importmap?.imports ?? {}))
|
|
131
|
+
if (typeof target === 'string') found.add(target)
|
|
132
|
+
for (const scope of Object.values(importmap?.scopes ?? {}))
|
|
133
|
+
for (const target of Object.values(scope ?? {}))
|
|
134
|
+
if (typeof target === 'string') found.add(target)
|
|
135
|
+
return [...found]
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** A module path as the package names it, without a leading `./`. */
|
|
139
|
+
const packagePath = (path: string) => path.replace(/^\.\//, '')
|
|
140
|
+
|
|
141
|
+
const SOURCE_FILE = /\.(m?[jt]s|[jt]sx)$/
|
|
142
|
+
|
|
143
|
+
/** The entry a package exports, as its `package.json` says, relative to the package. */
|
|
144
|
+
export function exportedEntry(json: PackageJson): string | undefined {
|
|
145
|
+
const pick = (value: unknown): string | undefined => {
|
|
146
|
+
if (typeof value === 'string') return value
|
|
147
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
148
|
+
const conditions = value as Record<string, unknown>
|
|
149
|
+
if ('.' in conditions) return pick(conditions['.'])
|
|
150
|
+
for (const key of ['bun', 'import', 'default', 'node', 'require'])
|
|
151
|
+
if (key in conditions) return pick(conditions[key])
|
|
152
|
+
}
|
|
153
|
+
return undefined
|
|
154
|
+
}
|
|
155
|
+
const entry = pick(json.exports) ?? json.main
|
|
156
|
+
return entry ? packagePath(entry) : undefined
|
|
157
|
+
}
|
|
96
158
|
|
|
97
159
|
/** Said when a schema 3 extension is offered for a new install (story 308). */
|
|
98
160
|
export const SCHEMA_3_NOT_INSTALLED =
|
|
99
|
-
'it asks for permissions without saying why (bundle schema 3); install a version written for schema
|
|
161
|
+
'it asks for permissions without saying why (bundle schema 3); install a version written for schema 5'
|
|
100
162
|
|
|
101
163
|
/** A bundle as read from its package. */
|
|
102
164
|
export interface BundlePackage {
|
|
@@ -121,6 +183,8 @@ export interface PackageJson {
|
|
|
121
183
|
private?: boolean
|
|
122
184
|
dependencies?: Record<string, string>
|
|
123
185
|
peerDependencies?: Record<string, string>
|
|
186
|
+
exports?: unknown
|
|
187
|
+
main?: string
|
|
124
188
|
crombolo?: unknown
|
|
125
189
|
}
|
|
126
190
|
|
|
@@ -145,15 +209,64 @@ export function declaresBundle(json: PackageJson | undefined): boolean {
|
|
|
145
209
|
return Boolean(json?.crombolo) && json?.name !== CORE_PACKAGE
|
|
146
210
|
}
|
|
147
211
|
|
|
148
|
-
/** What
|
|
149
|
-
export function schemaProblem(schema: number): string {
|
|
212
|
+
/** What an extension written for an older schema must change, by the schema it is at. */
|
|
213
|
+
export function schemaProblem(schema: number, options: { wired?: boolean } = {}): string {
|
|
150
214
|
const changes = [
|
|
151
215
|
schema < 2 ? 'its routes are route handlers since 0.37 (docs/bundles.md, "Routes")' : '',
|
|
152
216
|
schema < 3
|
|
153
217
|
? 'it declares the permissions it needs in "crombolo.permissions" (docs/bundles.md, "Permissions")'
|
|
154
218
|
: '',
|
|
219
|
+
schema < 4 && !options.wired ? 'each permission gives its reason' : '',
|
|
220
|
+
options.wired
|
|
221
|
+
? ''
|
|
222
|
+
: `its server code moves to ${SERVER_DIR}/ and its back-office code to ${BACKOFFICE_DIR}/, which \`crombolo extension migrate <dir>\` does`,
|
|
155
223
|
].filter(Boolean)
|
|
156
|
-
|
|
224
|
+
const reads = options.wired ? OLDEST_WIRED_SCHEMA_VERSION : BUNDLE_SCHEMA_VERSION
|
|
225
|
+
return `it is written for bundle schema ${schema}, and this release reads ${reads}${options.wired ? ` to ${BUNDLE_SCHEMA_VERSION}` : ''}: ${changes.join(', and ')}, with "crombolo.schemaVersion": ${BUNDLE_SCHEMA_VERSION}${options.wired ? '' : '; then publish it again'}`
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Where an extension's files must sit (story 320): its exported entry under
|
|
230
|
+
* `src/server/`, every module its manifest names under `src/backoffice/`, and
|
|
231
|
+
* nothing in the layout before it. Pure but for reading the directory.
|
|
232
|
+
*/
|
|
233
|
+
function layoutProblems(
|
|
234
|
+
json: PackageJson,
|
|
235
|
+
f: Record<string, unknown>,
|
|
236
|
+
directory?: string,
|
|
237
|
+
): string[] {
|
|
238
|
+
const problems: string[] = []
|
|
239
|
+
for (const module of backOfficeModules(f)) {
|
|
240
|
+
const path = packagePath(module)
|
|
241
|
+
if (module.startsWith('/') || /^[a-z][a-z0-9+.-]*:/i.test(module) || path.includes('..'))
|
|
242
|
+
problems.push(`its manifest names ${module}, which is not a file under ${BACKOFFICE_DIR}/`)
|
|
243
|
+
else if (!path.startsWith(`${BACKOFFICE_DIR}/`) || !SOURCE_FILE.test(path))
|
|
244
|
+
problems.push(
|
|
245
|
+
`its manifest names ${path}, and its back-office code is a .ts or .js file under ${BACKOFFICE_DIR}/`,
|
|
246
|
+
)
|
|
247
|
+
else if (directory && !existsSync(join(directory, path)))
|
|
248
|
+
problems.push(`its manifest names ${path}, which it does not hold`)
|
|
249
|
+
}
|
|
250
|
+
// One the site's config wires in itself may export nothing: the config holds its code.
|
|
251
|
+
const entry = f.server !== undefined ? exportedEntry(json) : undefined
|
|
252
|
+
if (entry && !entry.startsWith(`${SERVER_DIR}/`))
|
|
253
|
+
problems.push(
|
|
254
|
+
`its server half is the entry its package exports, which must be under ${SERVER_DIR}/, not ${entry}`,
|
|
255
|
+
)
|
|
256
|
+
if (directory) {
|
|
257
|
+
if (existsSync(join(directory, 'plugin')))
|
|
258
|
+
problems.push(
|
|
259
|
+
`it holds plugin/, the layout before bundle schema 5: its back-office code belongs in ${BACKOFFICE_DIR}/`,
|
|
260
|
+
)
|
|
261
|
+
const src = join(directory, 'src')
|
|
262
|
+
if (isDirectory(src))
|
|
263
|
+
for (const name of readdirSync(src))
|
|
264
|
+
if (name !== 'server' && name !== 'backoffice')
|
|
265
|
+
problems.push(
|
|
266
|
+
`it holds src/${name}, and an extension's code is under ${SERVER_DIR}/ or ${BACKOFFICE_DIR}/`,
|
|
267
|
+
)
|
|
268
|
+
}
|
|
269
|
+
return problems
|
|
157
270
|
}
|
|
158
271
|
|
|
159
272
|
const isPlainObject = (value: unknown): value is Record<string, unknown> =>
|
|
@@ -220,24 +333,33 @@ export function validateBundlePackage(json: PackageJson, directory?: string): st
|
|
|
220
333
|
)
|
|
221
334
|
if (f.server !== undefined && (typeof f.server !== 'string' || !EXPORT_NAME.test(f.server)))
|
|
222
335
|
problems.push('"crombolo.server" must name the factory the package exports')
|
|
336
|
+
// Code of either half: a server, or a module the back office would load.
|
|
337
|
+
const modules = backOfficeModules(f)
|
|
338
|
+
const hasCode = f.server !== undefined || modules.length > 0
|
|
339
|
+
const schema = (f.schemaVersion as number | undefined) ?? 1
|
|
223
340
|
if (
|
|
224
341
|
f.schemaVersion !== undefined &&
|
|
225
342
|
(!Number.isInteger(f.schemaVersion) || (f.schemaVersion as number) < 1)
|
|
226
343
|
)
|
|
227
344
|
problems.push('"crombolo.schemaVersion" is a whole number')
|
|
228
|
-
else if (
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
)
|
|
232
|
-
problems.push(schemaProblem((f.schemaVersion as number | undefined) ?? 1))
|
|
233
|
-
const schema = (f.schemaVersion as number | undefined) ?? 1
|
|
234
|
-
if (f.server !== undefined && f.permissions === undefined)
|
|
345
|
+
else if (hasCode && schema < OLDEST_BUNDLE_SCHEMA_VERSION) problems.push(schemaProblem(schema))
|
|
346
|
+
else if (hasCode) problems.push(...layoutProblems(json, f, directory))
|
|
347
|
+
if (hasCode && f.permissions === undefined)
|
|
235
348
|
problems.push(
|
|
236
|
-
'
|
|
349
|
+
'it declares no "crombolo.permissions": each permission it asks for with its reason, {} for nothing (docs/bundles.md, "Permissions")',
|
|
237
350
|
)
|
|
238
351
|
else if (f.permissions !== undefined) {
|
|
239
352
|
const problem = permissionsProblem(f.permissions, schema)
|
|
240
353
|
if (problem) problems.push(problem)
|
|
354
|
+
else if (schema >= BUNDLE_SCHEMA_VERSION) {
|
|
355
|
+
const asksForCode = Object.hasOwn(f.permissions as object, BACKOFFICE_CODE)
|
|
356
|
+
if (modules.length > 0 && !asksForCode)
|
|
357
|
+
problems.push(
|
|
358
|
+
`it runs code in the back office and does not ask for "${BACKOFFICE_CODE}": that code acts as whoever is signed in, so it is asked for, with its reason`,
|
|
359
|
+
)
|
|
360
|
+
if (modules.length === 0 && asksForCode)
|
|
361
|
+
problems.push(`it asks for "${BACKOFFICE_CODE}" and has no back-office code`)
|
|
362
|
+
}
|
|
241
363
|
}
|
|
242
364
|
{
|
|
243
365
|
const settings = readSettings(f.settings)
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* What an extension may ask to do with the site (stories 222, 308): each
|
|
3
3
|
* permission, and the sentence an administrator reads before granting it.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* sentence; `http.outbound` also names its origins. Schema
|
|
7
|
-
*
|
|
5
|
+
* From schema 4 each is asked for with a reason, which the install shows beside
|
|
6
|
+
* the sentence; `http.outbound` also names its origins. Schema 5 (story 320)
|
|
7
|
+
* adds `backoffice.code`, the one that runs unconfined: `BACKOFFICE_CODE_WARNING`.
|
|
8
8
|
* docs/bundles.md, "Permissions".
|
|
9
9
|
*/
|
|
10
10
|
|
|
@@ -43,6 +43,8 @@ export const BUNDLE_PERMISSIONS = {
|
|
|
43
43
|
'Send requests from the server, and from its screens in your browser, to the addresses it names',
|
|
44
44
|
'routes.public': 'Answer addresses on the site that anyone may call',
|
|
45
45
|
templates: "Render its own components into the site's pages",
|
|
46
|
+
// Story 320: the one permission that is not confined. Its words are the install's warning.
|
|
47
|
+
'backoffice.code': 'Runs in your back office as each person using it',
|
|
46
48
|
} as const
|
|
47
49
|
|
|
48
50
|
export type BundlePermission = keyof typeof BUNDLE_PERMISSIONS
|
|
@@ -59,6 +61,16 @@ export const SCHEMA_3_PERMISSIONS = {
|
|
|
59
61
|
'member.delegate': BUNDLE_PERMISSIONS['member.delegate'],
|
|
60
62
|
} as const
|
|
61
63
|
|
|
64
|
+
/** The permission an extension's back-office code needs (story 320). */
|
|
65
|
+
export const BACKOFFICE_CODE = 'backoffice.code'
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* What the install says beside `backoffice.code`, before the publisher's name and
|
|
69
|
+
* what its signature shows.
|
|
70
|
+
*/
|
|
71
|
+
export const BACKOFFICE_CODE_WARNING =
|
|
72
|
+
"Its screens act as whoever is signed in, with everything that person can do on this site. Unlike the rest of an extension, this part can't be kept apart from the site. Don't install this from a publisher you don't trust."
|
|
73
|
+
|
|
62
74
|
/** Never offered, whatever an extension asks: writing users could make anyone an administrator. */
|
|
63
75
|
export const NEVER_OFFERED: ReadonlySet<string> = new Set(['users.write'])
|
|
64
76
|
|
|
@@ -130,9 +142,14 @@ export function readPermissions(
|
|
|
130
142
|
}
|
|
131
143
|
|
|
132
144
|
/** Each permission with what it lets the extension do, and its reason, in the order declared. */
|
|
133
|
-
export function describePermissions(
|
|
134
|
-
|
|
135
|
-
|
|
145
|
+
export function describePermissions(permissions: readonly (string | DeclaredPermission)[]): {
|
|
146
|
+
permission: string
|
|
147
|
+
allows: string
|
|
148
|
+
reason: string | null
|
|
149
|
+
origins?: string[]
|
|
150
|
+
/** What the install says before it is granted: only `backoffice.code` has one (story 320). */
|
|
151
|
+
warning?: string
|
|
152
|
+
}[] {
|
|
136
153
|
return permissions.map((entry) => {
|
|
137
154
|
const declared = typeof entry === 'string' ? { permission: entry, reason: null } : entry
|
|
138
155
|
return {
|
|
@@ -140,6 +157,7 @@ export function describePermissions(
|
|
|
140
157
|
allows: SENTENCES[declared.permission] ?? declared.permission,
|
|
141
158
|
reason: declared.reason,
|
|
142
159
|
...(declared.origins ? { origins: declared.origins } : {}),
|
|
160
|
+
...(declared.permission === BACKOFFICE_CODE ? { warning: BACKOFFICE_CODE_WARNING } : {}),
|
|
143
161
|
}
|
|
144
162
|
})
|
|
145
163
|
}
|
package/src/extensions.ts
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { join, normalize, sep } from 'node:path'
|
|
14
14
|
import {
|
|
15
|
+
BACKOFFICE_DIR,
|
|
15
16
|
type BundlePackage,
|
|
16
17
|
type DiscoveredBundles,
|
|
17
18
|
discoverBundles,
|
|
@@ -36,6 +37,11 @@ export interface InstalledExtension {
|
|
|
36
37
|
directory: string
|
|
37
38
|
manifest: PackageManifest
|
|
38
39
|
bundle: BundlePackage
|
|
40
|
+
/**
|
|
41
|
+
* Where its back-office code was built (story 320), which is all that is
|
|
42
|
+
* served of it; undefined until the server has built it.
|
|
43
|
+
*/
|
|
44
|
+
servedDir?: string
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
/**
|
|
@@ -44,11 +50,21 @@ export interface InstalledExtension {
|
|
|
44
50
|
*/
|
|
45
51
|
const ASSET_KEYS = new Set(['element', 'api', 'js', 'loader'])
|
|
46
52
|
|
|
47
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Where a module is served from its build (story 320): `src/backoffice/seo.ts`
|
|
55
|
+
* inside `@acme/seo` is built to `seo.js`, served at `/bundles/@acme/seo/seo.js`.
|
|
56
|
+
*/
|
|
57
|
+
export function builtModulePath(target: string): string {
|
|
58
|
+
return target
|
|
59
|
+
.replace(/^\.?\//, '')
|
|
60
|
+
.slice(BACKOFFICE_DIR.length + 1)
|
|
61
|
+
.replace(/\.(m?[jt]s|[jt]sx)$/, '.js')
|
|
62
|
+
}
|
|
63
|
+
|
|
48
64
|
const assetPath = (packageName: string, target: string): string =>
|
|
49
65
|
target.startsWith('/') || /^[a-z][a-z0-9+.-]*:/i.test(target)
|
|
50
66
|
? target
|
|
51
|
-
: `${EXTENSION_PATH}/${packageName}/${target
|
|
67
|
+
: `${EXTENSION_PATH}/${packageName}/${builtModulePath(target)}`
|
|
52
68
|
|
|
53
69
|
function rewriteAssets(value: unknown, packageName: string): unknown {
|
|
54
70
|
if (Array.isArray(value)) return value.map((item) => rewriteAssets(item, packageName))
|
|
@@ -121,11 +137,12 @@ export function discoverExtensions(siteDir: string): InstalledExtension[] {
|
|
|
121
137
|
}
|
|
122
138
|
|
|
123
139
|
/**
|
|
124
|
-
* The
|
|
140
|
+
* The extension a `/bundles/…` request names, and the file inside its build.
|
|
125
141
|
*
|
|
126
|
-
* The name is matched against the site's own extensions rather than trusted,
|
|
127
|
-
*
|
|
128
|
-
*
|
|
142
|
+
* The name is matched against the site's own extensions rather than trusted, and
|
|
143
|
+
* the file is looked for only where its back-office code was built, so nothing
|
|
144
|
+
* else of the package, nor anything in `node_modules`, is served; a scoped name
|
|
145
|
+
* takes two segments, as npm writes it.
|
|
129
146
|
*/
|
|
130
147
|
export function resolveExtensionFile(
|
|
131
148
|
extensions: readonly InstalledExtension[],
|
|
@@ -148,14 +165,14 @@ export function resolveExtensionFile(
|
|
|
148
165
|
}
|
|
149
166
|
const relative = segments.slice(take).join('/')
|
|
150
167
|
const extension = extensions.find((candidate) => candidate.packageName === name)
|
|
151
|
-
|
|
168
|
+
// Only what was built from its back-office code, never the package itself (story 320).
|
|
169
|
+
const served = extension?.servedDir
|
|
170
|
+
if (!served || relative.length === 0) return undefined
|
|
152
171
|
|
|
153
172
|
const decoded = decodeURIComponent(relative)
|
|
154
173
|
if (decoded.includes('\0')) return undefined
|
|
155
|
-
const root =
|
|
156
|
-
|
|
157
|
-
: `${extension.directory}${sep}`
|
|
158
|
-
const target = normalize(join(extension.directory, decoded))
|
|
174
|
+
const root = served.endsWith(sep) ? served : `${served}${sep}`
|
|
175
|
+
const target = normalize(join(served, decoded))
|
|
159
176
|
return target.startsWith(root) ? target : undefined
|
|
160
177
|
}
|
|
161
178
|
|