@crombolo/backoffice-host 0.43.1 → 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.43.1",
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.43.1",
36
- "@crombolo/backoffice-dist": "0.43.1"
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.43.1",
5
+ "version": "0.45.0",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -61,6 +61,8 @@
61
61
  --crombolo-header-line: #3b2e25;
62
62
  --crombolo-section-sidebar-background: var(--crombolo-night-surface);
63
63
  --crombolo-card-shadow: none;
64
+ --crombolo-card-header-background: #4a2a1a;
65
+ --crombolo-card-header-text: #ffffff;
64
66
  --crombolo-terracotta-tint: var(--crombolo-night-alt);
65
67
 
66
68
  /* The SEO view's search-result preview, in Google's dark-mode link blue. */
@@ -92,6 +92,9 @@
92
92
  /* The sidebar is a white panel, like the cards, beside the cream page. */
93
93
  --crombolo-section-sidebar-background: #fff;
94
94
  /* Crombolo's own cards (the Overview, Settings) stand off the page; Umbraco's stay flat. */
95
+ /* A Settings card's title sits on a dark band. */
96
+ --crombolo-card-header-background: var(--crombolo-cocoa);
97
+ --crombolo-card-header-text: #fff;
95
98
  --crombolo-card-shadow: 0 1px 2px rgb(84 50 31 / 6%), 0 10px 28px -18px rgb(84 50 31 / 30%);
96
99
 
97
100
  /* Pure white panels on a warm off-white page, so cards still separate. */
@@ -83,7 +83,7 @@ export default class CromboloBundleEditorElement extends UmbLitElement {
83
83
 
84
84
  render() {
85
85
  return html`
86
- <umb-workspace-editor back-path="section/packages/view/created">
86
+ <umb-workspace-editor back-path="section/settings/dashboard/bundles/created">
87
87
  ${
88
88
  this._definition
89
89
  ? html`<div id="header" slot="header">
@@ -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,
@@ -20,7 +20,7 @@ import { downloadFile } from './download.js'
20
20
  const TAKE = 10
21
21
 
22
22
  /** Where the builder lives, which is Umbraco's route and not ours to rename. */
23
- export const BUILDER_PATH = 'section/packages/view/created/package-builder'
23
+ export const BUILDER_PATH = 'section/settings/dashboard/bundles/created/package-builder'
24
24
 
25
25
  export default class CromboloBundlesCreatedOverviewElement extends UmbLitElement {
26
26
  static properties = {
@@ -1,9 +1,8 @@
1
1
  /**
2
2
  * The Created view, in place of Umbraco's.
3
3
  *
4
- * Its manifest declares `overwrites: ['Umb.SectionView.Packages.Builder']`.
5
- * Umbraco's view is a router, not a screen: it mounts its own overview at
6
- * `overview` and every `package-builder` workspace at `package-builder/create`
4
+ * A tab of the Bundles tool in Settings (story 238). Umbraco's view is a
5
+ * router, not a screen: it mounts its own overview at `overview` and every `package-builder` workspace at `package-builder/create`
7
6
  * and `package-builder/edit/:unique`. Those two routes are the only way to
8
7
  * reach the builder, so this reproduces them exactly — replacing the view
9
8
  * without them would have left the builder unreachable rather than renamed.
@@ -12,7 +11,7 @@
12
11
  */
13
12
  import { createExtensionElement } from '@umbraco-cms/backoffice/extension-api'
14
13
  import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry'
15
- import { html } from '@umbraco-cms/backoffice/external/lit'
14
+ import { css, html } from '@umbraco-cms/backoffice/external/lit'
16
15
  import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
17
16
  import { editorsOf } from './bundle-editor-routing.js'
18
17
 
@@ -42,6 +41,16 @@ export default class CromboloBundlesCreatedElement extends UmbLitElement {
42
41
  render() {
43
42
  return html`<umb-router-slot .routes=${this._routes}></umb-router-slot>`
44
43
  }
44
+
45
+ // A tab of the Bundles tool, which gives it the space under the tabs; the
46
+ // builder's workspace fills that.
47
+ static styles = css`
48
+ :host,
49
+ umb-router-slot {
50
+ display: block;
51
+ height: 100%;
52
+ }
53
+ `
45
54
  }
46
55
 
47
56
  /** Umbraco's own route table, with our overview in place of its own. */
@@ -1,8 +1,7 @@
1
1
  /**
2
2
  * The Installed view, in place of Umbraco's.
3
3
  *
4
- * Its manifest declares `overwrites: ['Umb.SectionView.Packages.Installed']`.
5
- * Umbraco's view is built around package migrations — it lists installed
4
+ * A tab of the Bundles tool in Settings (story 238). Umbraco's view is built around package migrations — it lists installed
6
5
  * packages so that pending C# migrations can be run. Nothing carries those here
7
6
  * (`docs/bundles.md`), so the view would be a list of nothing with a button
8
7
  * that cannot apply.
@@ -18,6 +17,7 @@ import { css, html, nothing, repeat } from '@umbraco-cms/backoffice/external/lit
18
17
  import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
19
18
  import { carriesTags } from './bundles-carries.js'
20
19
  import { disableBundle, enableBundle, listInstalled, uninstallBundle } from './bundles-client.js'
20
+ import { signatureBlock, signatureStyles, signatureWords } from './bundles-signature.js'
21
21
 
22
22
  /** Where each part of a bundle stands on this site, in the words of someone running it. */
23
23
  function status(item) {
@@ -46,8 +46,10 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
46
46
  _busy: { state: true },
47
47
  _notice: { state: true },
48
48
  _installs: { state: true },
49
+ _restartPending: { state: true },
49
50
  _filter: { state: true },
50
51
  _selected: { state: true },
52
+ _policy: { state: true },
51
53
  }
52
54
 
53
55
  constructor() {
@@ -57,8 +59,10 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
57
59
  this._busy = ''
58
60
  this._notice = ''
59
61
  this._installs = true
62
+ this._restartPending = false
60
63
  this._filter = ''
61
- this._selected = ''
64
+ // Settings links a bundle's cards here, naming it in `?bundle=`.
65
+ this._selected = new URLSearchParams(window.location.search).get('bundle') ?? ''
62
66
  }
63
67
 
64
68
  connectedCallback() {
@@ -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)
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * The Marketplace view, in place of Umbraco's.
3
3
  *
4
- * Its manifest declares `overwrites: ['Umb.SectionView.Packages.Marketplace']`.
5
- * What it replaces is an iframe of marketplace.umbraco.com, which cannot work
4
+ * A tab of the Bundles tool in Settings (story 238), where Umbraco's Packages
5
+ * section had its Marketplace. What it replaces is an iframe of marketplace.umbraco.com, which cannot work
6
6
  * here twice over: npm refuses to be framed (`x-frame-options: SAMEORIGIN`), and
7
7
  * an Umbraco package does not install into this CMS anyway.
8
8
  *
@@ -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
+ `
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Bundles, a Settings tool (story 238): Marketplace, Installed and Created as
3
+ * tabs, each at an address of its own under `dashboard/bundles/`. The views
4
+ * are the ones Umbraco's Packages section showed, which this replaces.
5
+ */
6
+ import { css, html } from '@umbraco-cms/backoffice/external/lit'
7
+ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
8
+
9
+ /** The tabs, in order: each one's segment, its label, and its view. */
10
+ export const BUNDLE_TABS = [
11
+ { path: 'marketplace', label: 'Marketplace', load: () => import('./bundles-marketplace.js') },
12
+ { path: 'installed', label: 'Installed', load: () => import('./bundles-installed.js') },
13
+ { path: 'created', label: 'Created', load: () => import('./bundles-created.js') },
14
+ ]
15
+
16
+ /** Where the tool is, relative to the back office. */
17
+ export const BUNDLES_PATH = 'section/settings/dashboard/bundles'
18
+
19
+ export default class CromboloBundlesToolElement extends UmbLitElement {
20
+ static properties = { _routerPath: { state: true }, _active: { state: true } }
21
+
22
+ constructor() {
23
+ super()
24
+ this._routerPath = BUNDLES_PATH
25
+ this._active = BUNDLE_TABS[0].path
26
+ }
27
+
28
+ #routes = [
29
+ ...BUNDLE_TABS.map((tab) => ({ path: tab.path, component: tab.load })),
30
+ { path: '', pathMatch: 'full', redirectTo: BUNDLE_TABS[0].path },
31
+ ]
32
+
33
+ render() {
34
+ return html`
35
+ <uui-tab-group>
36
+ ${BUNDLE_TABS.map(
37
+ (tab) => html`<uui-tab
38
+ label=${tab.label}
39
+ href=${`${this._routerPath}/${tab.path}`}
40
+ ?active=${this._active === tab.path}
41
+ >${tab.label}</uui-tab>`,
42
+ )}
43
+ </uui-tab-group>
44
+ <umb-router-slot
45
+ .routes=${this.#routes}
46
+ @init=${(event) => {
47
+ this._routerPath = event.target.absoluteRouterPath
48
+ }}
49
+ @change=${(event) => {
50
+ const active = event.target.absoluteActiveViewPath ?? ''
51
+ this._active = BUNDLE_TABS.find((tab) => active.endsWith(`/${tab.path}`))?.path ?? ''
52
+ }}
53
+ ></umb-router-slot>
54
+ `
55
+ }
56
+
57
+ static styles = css`
58
+ :host {
59
+ display: flex;
60
+ flex-direction: column;
61
+ height: 100%;
62
+ }
63
+ uui-tab-group {
64
+ /* UUI's tab group fills its container's height; here it is a strip. */
65
+ flex: none;
66
+ height: auto;
67
+ padding: 0 var(--uui-size-layout-1);
68
+ border-bottom: 1px solid var(--uui-color-border);
69
+ --uui-tab-divider: transparent;
70
+ }
71
+ umb-router-slot {
72
+ display: block;
73
+ flex: 1 1 auto;
74
+ min-height: 0;
75
+ }
76
+ `
77
+ }
78
+
79
+ customElements.define('crombolo-bundles-tool', CromboloBundlesToolElement)
@@ -0,0 +1,63 @@
1
+ /** CI access's words and its one API call (story 160). Pure but for `trustApi`. */
2
+
3
+ /** What a rule may hold, in the order a person reads them. */
4
+ export const CI_PERMISSIONS = [
5
+ {
6
+ verb: 'Crombolo.Remote.Pull',
7
+ label: 'Pull',
8
+ explain: "Download the site's content, without its private parts.",
9
+ },
10
+ {
11
+ verb: 'Crombolo.Remote.PullFull',
12
+ label: 'Pull everything',
13
+ explain: 'Download the site with people and private data too.',
14
+ },
15
+ { verb: 'Crombolo.Remote.Push', label: 'Push', explain: 'Replace this site from a file.' },
16
+ {
17
+ verb: 'Crombolo.Remote.PushProtected',
18
+ label: 'Push to a protected site',
19
+ explain: 'Change a site people rely on, such as production, with nobody approving it.',
20
+ },
21
+ {
22
+ verb: 'Crombolo.Remote.ApplyStructure',
23
+ label: 'Change structure and code',
24
+ explain: 'Push a whole site, or apply a bundle that changes its types, views, styles or code.',
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
+ },
32
+ ]
33
+
34
+ /** A provider by the address its tokens come from. */
35
+ export function providerName(issuer) {
36
+ if (issuer === 'https://token.actions.githubusercontent.com') return 'GitHub Actions'
37
+ if (issuer === 'https://gitlab.com') return 'GitLab'
38
+ return `GitLab at ${issuer.replace(/^https?:\/\//, '')}`
39
+ }
40
+
41
+ const base = () =>
42
+ `${(document.querySelector('base')?.getAttribute('href') ?? '/umbraco/').replace(/\/$/, '')}/crombolo/api/remote-trust`
43
+
44
+ /** Calls the trust rules; a refusal throws with the server's reasons as `items`. */
45
+ export async function trustApi(method, path = '', body) {
46
+ const response = await fetch(`${base()}${path}`, {
47
+ method,
48
+ credentials: 'include',
49
+ headers: {
50
+ accept: 'application/json',
51
+ ...(body ? { 'content-type': 'application/json' } : {}),
52
+ },
53
+ ...(body ? { body: JSON.stringify(body) } : {}),
54
+ })
55
+ if (response.status === 204) return undefined
56
+ const result = await response.json().catch(() => ({}))
57
+ if (!response.ok) {
58
+ const error = new Error(result.title ?? `CI access responded ${response.status}`)
59
+ error.items = result.items
60
+ throw error
61
+ }
62
+ return result
63
+ }