@crombolo/backoffice-host 0.44.0 → 0.45.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/backoffice-host",
3
- "version": "0.44.0",
3
+ "version": "0.45.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.44.0",
36
- "@crombolo/backoffice-dist": "0.44.0"
35
+ "@crombolo/core": "0.45.0",
36
+ "@crombolo/backoffice-dist": "0.45.0"
37
37
  }
38
38
  }
@@ -2,7 +2,7 @@
2
2
  "$schema": "../../../backoffice-dist/dist/umbraco-package-schema.json",
3
3
  "name": "Crombolo App Preview",
4
4
  "id": "Crombolo.AppPreview",
5
- "version": "0.44.0",
5
+ "version": "0.45.0",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -27,6 +27,12 @@ export const searchMarketplace = (query) =>
27
27
 
28
28
  export const listInstalled = () => json('/installed')
29
29
 
30
+ /** Where a version was built, and whether this site would install it (story 060). */
31
+ export const bundleSignature = (name, version) =>
32
+ json(
33
+ `/signature?name=${encodeURIComponent(name)}${version ? `&version=${encodeURIComponent(version)}` : ''}`,
34
+ )
35
+
30
36
  export const installBundle = (
31
37
  name,
32
38
  version,
@@ -17,6 +17,7 @@ import { css, html, nothing, repeat } from '@umbraco-cms/backoffice/external/lit
17
17
  import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
18
18
  import { carriesTags } from './bundles-carries.js'
19
19
  import { disableBundle, enableBundle, listInstalled, uninstallBundle } from './bundles-client.js'
20
+ import { signatureBlock, signatureStyles, signatureWords } from './bundles-signature.js'
20
21
 
21
22
  /** Where each part of a bundle stands on this site, in the words of someone running it. */
22
23
  function status(item) {
@@ -45,8 +46,10 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
45
46
  _busy: { state: true },
46
47
  _notice: { state: true },
47
48
  _installs: { state: true },
49
+ _restartPending: { state: true },
48
50
  _filter: { state: true },
49
51
  _selected: { state: true },
52
+ _policy: { state: true },
50
53
  }
51
54
 
52
55
  constructor() {
@@ -56,6 +59,7 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
56
59
  this._busy = ''
57
60
  this._notice = ''
58
61
  this._installs = true
62
+ this._restartPending = false
59
63
  this._filter = ''
60
64
  // Settings links a bundle's cards here, naming it in `?bundle=`.
61
65
  this._selected = new URLSearchParams(window.location.search).get('bundle') ?? ''
@@ -72,6 +76,8 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
72
76
  const result = await listInstalled()
73
77
  this._items = result.items ?? []
74
78
  this._installs = result.installs !== false
79
+ this._restartPending = Boolean(result.restartPending)
80
+ this._policy = result.policy
75
81
  if (!this._items.some((item) => item.packageName === this._selected))
76
82
  this._selected = this._items[0]?.packageName ?? ''
77
83
  } catch (error) {
@@ -174,6 +180,11 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
174
180
  const shown = this.#shown
175
181
  return html`
176
182
  ${this._notice ? html`<div id="notice">${this._notice}</div>` : nothing}
183
+ ${
184
+ this._restartPending
185
+ ? html`<div id="restart">Installed changes take effect when the site restarts.</div>`
186
+ : nothing
187
+ }
177
188
  <div id="columns">
178
189
  <uui-box headline="Installed bundles" style="--uui-box-default-padding:0;">
179
190
  <div id="filter">
@@ -196,7 +207,7 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
196
207
  (item) => item.packageName,
197
208
  (item) => html`<uui-ref-node
198
209
  name=${item.name}
199
- detail=${`${item.packageName} ${item.version}`}
210
+ detail=${`${item.packageName} ${item.version} · ${this.#words(item).label}`}
200
211
  selectable
201
212
  select-only
202
213
  ?selected=${item.packageName === this._selected}
@@ -212,6 +223,13 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
212
223
  `
213
224
  }
214
225
 
226
+ /** Signed or not (story 060); an unsigned one under a site that wants signatures says so. */
227
+ #words(item) {
228
+ const unsignedRefused =
229
+ item.provenance?.state === 'unsigned' && this._policy?.signatures === 'required'
230
+ return signatureWords(item.provenance, unsignedRefused ? 'unsigned' : null, this._policy)
231
+ }
232
+
215
233
  #details(item) {
216
234
  return html`<uui-box headline=${item.name}>
217
235
  ${item.description ? html`<p>${item.description}</p>` : nothing}
@@ -226,6 +244,8 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
226
244
  <dd class="status">${status(item)}</dd>
227
245
  <dt>Works with</dt>
228
246
  <dd>Crombolo ${item.peerRange}</dd>
247
+ <dt>Signature</dt>
248
+ <dd>${signatureBlock(this.#words(item))}</dd>
229
249
  </dl>
230
250
  ${this.#permissions(item)}
231
251
  ${
@@ -241,7 +261,9 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
241
261
  </uui-box>`
242
262
  }
243
263
 
244
- static styles = css`
264
+ static styles = [
265
+ signatureStyles,
266
+ css`
245
267
  .asks {
246
268
  padding-left: 1.25em;
247
269
  }
@@ -260,6 +282,12 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
260
282
  border-left: 3px solid var(--uui-color-positive, #2bc37c);
261
283
  background: var(--uui-color-surface-alt, #f3f3f5);
262
284
  }
285
+ #restart {
286
+ margin-bottom: var(--uui-size-space-4, 12px);
287
+ padding: var(--uui-size-space-4, 12px);
288
+ border-left: 3px solid var(--uui-color-warning, #f0ac00);
289
+ background: var(--uui-color-surface-alt, #f3f3f5);
290
+ }
263
291
  #columns {
264
292
  display: grid;
265
293
  grid-template-columns: minmax(240px, 1fr) 2fr;
@@ -307,7 +335,8 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
307
335
  opacity: 0.8;
308
336
  font-size: 0.9em;
309
337
  }
310
- `
338
+ `,
339
+ ]
311
340
  }
312
341
 
313
342
  customElements.define('crombolo-bundles-installed', CromboloBundlesInstalledElement)
@@ -16,7 +16,8 @@
16
16
  import { css, html, nothing, repeat } from '@umbraco-cms/backoffice/external/lit'
17
17
  import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
18
18
  import { carriesTags } from './bundles-carries.js'
19
- import { installBundle, searchMarketplace } from './bundles-client.js'
19
+ import { bundleSignature, installBundle, searchMarketplace } from './bundles-client.js'
20
+ import { signatureBlock, signatureStyles, signatureWords } from './bundles-signature.js'
20
21
 
21
22
  export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
22
23
  static properties = {
@@ -34,6 +35,8 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
34
35
  _consenting: { state: true },
35
36
  _trusted: { state: true },
36
37
  _asks: { state: true },
38
+ _reviewing: { state: true },
39
+ _signatures: { state: true },
37
40
  }
38
41
 
39
42
  constructor() {
@@ -53,6 +56,8 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
53
56
  this._consenting = ''
54
57
  this._trusted = false
55
58
  this._asks = []
59
+ this._reviewing = ''
60
+ this._signatures = new Map()
56
61
  }
57
62
 
58
63
  connectedCallback() {
@@ -89,10 +94,59 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
89
94
  this.#load()
90
95
  }
91
96
 
92
- /** Asks first when the bundle runs code on the server; installs otherwise. */
93
- /** A bundle with server code is asked about first: the server answers with what it asks to do. */
94
- #requestInstall(item) {
95
- this.#install(item, false)
97
+ /**
98
+ * Where the version was built is checked first and shown (story 060), so the
99
+ * person sees signed or not, and whether this site would take it, before
100
+ * anything is installed.
101
+ */
102
+ async #requestInstall(item) {
103
+ this._busy = item.name
104
+ this._notice = ''
105
+ try {
106
+ const checked = await bundleSignature(item.name, item.version)
107
+ if (!checked.ok) {
108
+ this._notice = checked.message ?? ''
109
+ return
110
+ }
111
+ this._signatures = new Map(this._signatures).set(item.name, checked)
112
+ this._reviewing = item.name
113
+ } catch (error) {
114
+ this._notice = error instanceof Error ? error.message : String(error)
115
+ } finally {
116
+ this._busy = ''
117
+ }
118
+ }
119
+
120
+ #signature(item) {
121
+ const checked = this._signatures.get(item.name)
122
+ if (!checked) return nothing
123
+ return signatureBlock(signatureWords(checked.provenance, checked.refused, checked.policy))
124
+ }
125
+
126
+ /** The signature, and the install it leads to unless this site would refuse it. */
127
+ #review(item) {
128
+ const checked = this._signatures.get(item.name)
129
+ const refused = Boolean(checked?.refused) || checked?.provenance?.state === 'invalid'
130
+ return html`
131
+ ${this.#signature(item)}
132
+ <div class="actions">
133
+ ${
134
+ refused
135
+ ? nothing
136
+ : html`<uui-button
137
+ look="primary"
138
+ label="Install"
139
+ .state=${this._busy === item.name ? 'waiting' : undefined}
140
+ @click=${() => this.#install(item, false)}></uui-button>`
141
+ }
142
+ <uui-button
143
+ look="secondary"
144
+ label="Cancel"
145
+ @click=${() => {
146
+ this._reviewing = ''
147
+ }}></uui-button>
148
+ </div>
149
+ `
96
150
  }
97
151
 
98
152
  #askConsent(item, asks) {
@@ -126,6 +180,7 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
126
180
  return
127
181
  }
128
182
  this._consenting = ''
183
+ this._reviewing = ''
129
184
  // The dependency line is what there is to commit, so it is shown rather
130
185
  // than described: the install lives in this node's node_modules until it
131
186
  // is in the site's repository.
@@ -164,6 +219,7 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
164
219
  #consent(item) {
165
220
  return html`
166
221
  <div class="consent" role="group" aria-label="Install code that runs on the server">
222
+ ${this.#signature(item)}
167
223
  <p>
168
224
  <strong>This bundle runs code on the server.</strong> Once your site's developers turn
169
225
  it on, its code can read and change the site's data, files and settings.
@@ -271,7 +327,9 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
271
327
  : html`<p class="meta">Add it to the site with <code>bun add ${item.name}</code>, then deploy.</p>`
272
328
  : this._consenting === item.name
273
329
  ? this.#consent(item)
274
- : html`
330
+ : this._reviewing === item.name
331
+ ? this.#review(item)
332
+ : html`
275
333
  <uui-button
276
334
  look="primary"
277
335
  label="Install"
@@ -288,7 +346,9 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
288
346
  `
289
347
  }
290
348
 
291
- static styles = css`
349
+ static styles = [
350
+ signatureStyles,
351
+ css`
292
352
  :host {
293
353
  display: block;
294
354
  padding: var(--uui-size-layout-1, 24px);
@@ -349,12 +409,14 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
349
409
  margin: 0 0 var(--uui-size-space-3, 9px);
350
410
  padding-left: 1.25em;
351
411
  }
352
- .consent .actions {
412
+ .consent .actions,
413
+ .actions {
353
414
  display: flex;
354
415
  gap: var(--uui-size-space-3, 9px);
355
416
  margin-top: var(--uui-size-space-4, 12px);
356
417
  }
357
- `
418
+ `,
419
+ ]
358
420
  }
359
421
 
360
422
  customElements.define('crombolo-bundles-marketplace', CromboloBundlesMarketplaceElement)
@@ -0,0 +1,47 @@
1
+ /**
2
+ * What the Bundles screens say about where a bundle was built (story 060), in
3
+ * words for the person installing it. Pure, so it is tested without a browser.
4
+ */
5
+ const short = (commit) => (commit ?? '').slice(0, 7)
6
+ const refName = (ref) => (ref ?? '').replace(/^refs\/(tags|heads)\//, '')
7
+
8
+ /**
9
+ * @param {{ state: string, source?: { repository: string, ref: string, commit: string },
10
+ * links?: { commit?: string, tag?: string | null, run?: string | null }, reason?: string }} provenance
11
+ * @param {string | null | undefined} refused why this site would not install it, when it would not
12
+ * @param {{ signatures?: string, sources?: string[] } | undefined} policy
13
+ * @returns {{ tone: string, label: string, detail: string, links: { label: string, href: string }[], refusal: string }}
14
+ */
15
+ export function signatureWords(provenance, refused, policy) {
16
+ const links = []
17
+ let tone = 'default'
18
+ let label = 'Not signed'
19
+ let detail = "Nobody has signed this bundle, so where it was built can't be checked."
20
+ if (provenance?.state === 'signed' && provenance.source) {
21
+ const { repository, ref, commit } = provenance.source
22
+ tone = 'positive'
23
+ label = 'Signed'
24
+ detail = `Built from github.com/${repository} at ${refName(ref)} (${short(commit)}).`
25
+ if (provenance.links?.commit) links.push({ label: 'Commit', href: provenance.links.commit })
26
+ if (provenance.links?.tag) links.push({ label: 'Release', href: provenance.links.tag })
27
+ if (provenance.links?.run) links.push({ label: 'Build', href: provenance.links.run })
28
+ } else if (provenance?.state === 'local') {
29
+ label = 'From this site'
30
+ detail = "Linked from this site's own code, not from a package registry."
31
+ } else if (provenance?.state === 'invalid') {
32
+ tone = 'danger'
33
+ label = "Signature doesn't match"
34
+ detail = provenance.reason?.startsWith('the bundle has changed')
35
+ ? 'It has been changed since it was signed, so it will not be installed.'
36
+ : "Its signature can't be checked, so it will not be installed."
37
+ }
38
+ let refusal = ''
39
+ if (refused && provenance?.state !== 'invalid') {
40
+ tone = 'danger'
41
+ refusal =
42
+ provenance?.state === 'signed' && policy?.sources?.length
43
+ ? `This site only installs signed bundles from ${policy.sources.join(', ')}.`
44
+ : 'This site only installs signed bundles.'
45
+ }
46
+ return { tone, label, detail, links, refusal }
47
+ }
@@ -0,0 +1,35 @@
1
+ /** The signature as the Bundles screens show it (story 060): a tag, a line, its links, any refusal. */
2
+ import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
3
+
4
+ export { signatureWords } from './bundles-signature-words.js'
5
+
6
+ /** @param {ReturnType<typeof import('./bundles-signature-words.js').signatureWords>} words */
7
+ export function signatureBlock(words) {
8
+ return html`
9
+ <div class="signature" data-tone=${words.tone}>
10
+ <uui-tag look=${words.tone === 'positive' ? 'primary' : 'secondary'} color=${words.tone === 'default' ? 'default' : words.tone}>${words.label}</uui-tag>
11
+ <span>${words.detail}</span>
12
+ ${words.links.map(
13
+ (link) => html`<a href=${link.href} target="_blank" rel="noopener">${link.label}</a>`,
14
+ )}
15
+ ${words.refusal ? html`<p class="refusal">${words.refusal}</p>` : nothing}
16
+ </div>
17
+ `
18
+ }
19
+
20
+ /** The block's look, for the screens that show it. */
21
+ export const signatureStyles = css`
22
+ .signature {
23
+ display: flex;
24
+ flex-wrap: wrap;
25
+ align-items: center;
26
+ gap: var(--uui-size-space-3, 9px);
27
+ margin: var(--uui-size-space-3, 9px) 0;
28
+ font-size: 0.9em;
29
+ }
30
+ .signature .refusal {
31
+ flex-basis: 100%;
32
+ margin: 0;
33
+ color: var(--uui-color-danger, #d42054);
34
+ }
35
+ `
@@ -23,6 +23,12 @@ export const CI_PERMISSIONS = [
23
23
  label: 'Change structure and code',
24
24
  explain: 'Push a whole site, or apply a bundle that changes its types, views, styles or code.',
25
25
  },
26
+ {
27
+ verb: 'Crombolo.Remote.InstallCode',
28
+ label: 'Install code',
29
+ explain:
30
+ 'Install bundles and the code a bundle carries, which runs on the server after a restart.',
31
+ },
26
32
  ]
27
33
 
28
34
  /** A provider by the address its tokens come from. */
@@ -2,7 +2,7 @@
2
2
  "$schema": "../../../backoffice-dist/dist/umbraco-package-schema.json",
3
3
  "name": "Crombolo Localizations",
4
4
  "id": "Crombolo.Localizations",
5
- "version": "0.44.0",
5
+ "version": "0.45.0",
6
6
  "allowPublicAccess": true,
7
7
  "extensions": [
8
8
  {
@@ -2,7 +2,7 @@
2
2
  "$schema": "../../../backoffice-dist/dist/umbraco-package-schema.json",
3
3
  "name": "Crombolo Search & sharing",
4
4
  "id": "Crombolo.Seo",
5
- "version": "0.44.0",
5
+ "version": "0.45.0",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -2,7 +2,7 @@
2
2
  "$schema": "../../../backoffice-dist/dist/umbraco-package-schema.json",
3
3
  "name": "Crombolo Sign-in Dialog",
4
4
  "id": "Crombolo.SignInDialog",
5
- "version": "0.44.0",
5
+ "version": "0.45.0",
6
6
  "allowPublicAccess": true,
7
7
  "extensions": [
8
8
  {
@@ -2,7 +2,7 @@
2
2
  "$schema": "../../backoffice-dist/dist/umbraco-package-schema.json",
3
3
  "name": "Crombolo",
4
4
  "id": "Crombolo.Core",
5
- "version": "0.44.0",
5
+ "version": "0.45.0",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -82,6 +82,17 @@
82
82
  "description": "Push a whole site, or apply a bundle that changes its content types, views, styles or code"
83
83
  }
84
84
  },
85
+ {
86
+ "type": "entityUserPermission",
87
+ "alias": "Crombolo.UserPermission.Remote.InstallCode",
88
+ "name": "Crombolo Remote InstallCode Permission",
89
+ "forEntityTypes": ["crombolo-remote"],
90
+ "meta": {
91
+ "verbs": ["Crombolo.Remote.InstallCode"],
92
+ "label": "Install code on this site",
93
+ "description": "Install bundles and the code a bundle carries, which runs on the server after a restart. Administrators only have this when a group gives it to them: give it to a group of its own rather than Administrators"
94
+ }
95
+ },
85
96
  {
86
97
  "type": "entityUserPermission",
87
98
  "alias": "Crombolo.UserPermission.Media.Read",