@crombolo/backoffice-host 0.56.0 → 0.57.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.
@@ -23,6 +23,7 @@ import { UmbViewController } from '@umbraco-cms/backoffice/view'
23
23
  import {
24
24
  ADVANCED_MENU,
25
25
  advancedToolTitle,
26
+ CARDS,
26
27
  CODE_MENU,
27
28
  crumbsFor,
28
29
  SIDEBAR_APPS,
@@ -31,6 +32,7 @@ import {
31
32
  treeFor,
32
33
  } from './settings-cards.js'
33
34
  import './breadcrumb.js'
35
+ import './settings-title.js'
34
36
  import { readOnlyWords } from './definition-tree-model.js'
35
37
  import './settings-card.js'
36
38
 
@@ -80,6 +82,7 @@ export class CromboloSettingsSectionElement extends UmbLitElement {
80
82
  _sidebarApps: { state: true },
81
83
  _tree: { state: true },
82
84
  _crumbs: { state: true },
85
+ _tool: { state: true },
83
86
  _readOnly: { state: true },
84
87
  }
85
88
 
@@ -206,10 +209,11 @@ export class CromboloSettingsSectionElement extends UmbLitElement {
206
209
  if (this.#landing) this.#landing.groups = this.#cards()
207
210
  }
208
211
 
209
- /** Which tree shows, and the trail that heads the page. */
210
- #showing(tree, { title } = {}) {
212
+ /** Which tree shows, the trail that heads the page, and a tool's title section. */
213
+ #showing(tree, { title, tool } = {}) {
211
214
  this._tree = tree
212
215
  this._crumbs = crumbsFor({ tree, title })
216
+ this._tool = tool
213
217
  }
214
218
 
215
219
  #advanced() {
@@ -278,7 +282,14 @@ export class CromboloSettingsSectionElement extends UmbLitElement {
278
282
  context.provideAt(component)
279
283
  component.manifest = manifest
280
284
  }
281
- this.#showing(undefined, { title: this.#label(manifest) })
285
+ this.#showing(undefined, {
286
+ title: this.#label(manifest),
287
+ // The landing card's words for it, where there are any.
288
+ tool: {
289
+ heading: CARDS[manifest.alias]?.title ?? this.#label(manifest),
290
+ description: CARDS[manifest.alias]?.description ?? this.#description(manifest),
291
+ },
292
+ })
282
293
  },
283
294
  }))
284
295
  // Forms and Workflows are nodes in Structure, so its tree stays on screen beside them.
@@ -298,6 +309,16 @@ export class CromboloSettingsSectionElement extends UmbLitElement {
298
309
  tree('code'),
299
310
  // Umbraco's welcome, which this page replaces: an address people have.
300
311
  { path: 'dashboard/welcome', ...landing },
312
+ // Bundles became Extensions: its old addresses, tab and all, go to the new ones.
313
+ {
314
+ path: 'dashboard/bundles',
315
+ component: () => {
316
+ window.location.replace(
317
+ window.location.href.replace('/dashboard/bundles', '/dashboard/extensions'),
318
+ )
319
+ return document.createElement('div')
320
+ },
321
+ },
301
322
  // Workflows were a Settings card, then beside forms (story 289): an address people have.
302
323
  {
303
324
  path: 'dashboard/workflows',
@@ -342,6 +363,13 @@ export class CromboloSettingsSectionElement extends UmbLitElement {
342
363
  ? html`<crombolo-breadcrumb class="crumbs" .items=${crumbs}></crombolo-breadcrumb>`
343
364
  : nothing
344
365
  }
366
+ ${
367
+ this._tool
368
+ ? html`<crombolo-settings-title
369
+ heading=${this._tool.heading}
370
+ description=${this._tool.description ?? ''}></crombolo-settings-title>`
371
+ : nothing
372
+ }
345
373
  ${this._routes ? html`<umb-router-slot .routes=${this._routes}></umb-router-slot>` : nothing}
346
374
  </umb-section-main>`
347
375
  // Both trees stay in the page, the one not in use hidden, as Umbraco's own
@@ -412,7 +440,11 @@ export class CromboloSettingsSectionElement extends UmbLitElement {
412
440
  }
413
441
  .crumbs {
414
442
  display: block;
415
- padding: var(--uui-size-space-4) var(--uui-size-layout-1) 0;
443
+ padding: var(--uui-size-space-4) var(--uui-size-layout-1) var(--uui-size-space-4);
444
+ }
445
+ /* Umbraco's workspace headers, Webhooks' among them, as short as the tools' titles. */
446
+ umb-section-main {
447
+ --umb-header-layout-height: 56px;
416
448
  }
417
449
  `,
418
450
  ]
@@ -0,0 +1,46 @@
1
+ /**
2
+ * The title section every Settings tool opens with, under its breadcrumb: its
3
+ * name and what it is for. As tall as Umbraco's own workspace headers, such as
4
+ * Webhooks', which the section sets shorter (`--umb-header-layout-height`).
5
+ */
6
+ import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
7
+ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
8
+
9
+ export class CromboloSettingsTitleElement extends UmbLitElement {
10
+ static properties = { heading: { type: String }, description: { type: String } }
11
+
12
+ constructor() {
13
+ super()
14
+ this.heading = ''
15
+ this.description = ''
16
+ }
17
+
18
+ render() {
19
+ return html`<h2>${this.heading}</h2>
20
+ ${this.description ? html`<p>${this.description}</p>` : nothing}`
21
+ }
22
+
23
+ static styles = css`
24
+ :host {
25
+ display: flex;
26
+ flex-direction: column;
27
+ justify-content: center;
28
+ min-height: var(--umb-header-layout-height, 56px);
29
+ box-sizing: border-box;
30
+ padding: var(--uui-size-space-2) var(--uui-size-layout-1);
31
+ background: var(--uui-color-surface);
32
+ border-bottom: 1px solid var(--uui-color-border);
33
+ }
34
+ h2 {
35
+ margin: 0;
36
+ font-size: var(--uui-type-h5-size);
37
+ line-height: 1.2;
38
+ }
39
+ p {
40
+ margin: var(--uui-size-space-1) 0 0;
41
+ color: var(--uui-color-text-alt);
42
+ }
43
+ `
44
+ }
45
+
46
+ customElements.define('crombolo-settings-title', CromboloSettingsTitleElement)
@@ -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.56.0",
5
+ "version": "0.57.0",
6
6
  "allowPublicAccess": true,
7
7
  "extensions": [
8
8
  {
@@ -70,6 +70,7 @@ export default class CromboloTemplatePickerModalElement extends UmbModalBaseElem
70
70
  id: c.id,
71
71
  alias: c.alias,
72
72
  name: componentName(c.alias),
73
+ ...(c.extension ? { extension: c.extension } : {}),
73
74
  }))
74
75
  } catch {
75
76
  this._problem = 'The templates could not be listed.'
@@ -8,7 +8,8 @@
8
8
 
9
9
  /**
10
10
  * A component: `id` is its template's key, null while nothing names it.
11
- * @typedef {{ id: string | null, name: string, alias: string, allowed: boolean }} TemplateItem
11
+ * `extension` names the extension that renders it, when one does.
12
+ * @typedef {{ id: string | null, name: string, alias: string, allowed: boolean, extension?: string }} TemplateItem
12
13
  * @typedef {{ name: string, path: string, folders: TemplateFolder[], items: TemplateItem[] }} TemplateFolder
13
14
  */
14
15
 
@@ -24,7 +25,10 @@ export function templateTree(templates, allowedIds) {
24
25
  const allowed = new Set(allowedIds.map((id) => id.toLowerCase()))
25
26
  const root = { name: '', path: '', folders: [], items: [] }
26
27
  for (const template of templates) {
27
- const parts = template.alias.split('/').slice(0, -1)
28
+ // An extension's component sits under the extension's name, not its id's folder (story 312).
29
+ const parts = template.extension
30
+ ? [`${template.extension} (extension)`, ...template.alias.split('/').slice(1, -1)]
31
+ : template.alias.split('/').slice(0, -1)
28
32
  let at = root
29
33
  for (const part of parts) {
30
34
  const path = at.path ? `${at.path}/${part}` : part
@@ -0,0 +1,374 @@
1
+ /**
2
+ * Settings → Trusted signers (story 316): the keys and builds this site trusts
3
+ * to sign the site bundles it applies, as GitHub lists SSH keys. This site's own
4
+ * key is at the top, to copy to the sites that take its bundles. Administrators
5
+ * only; every change is audited.
6
+ */
7
+
8
+ import { UMB_CURRENT_USER_CONTEXT } from '@umbraco-cms/backoffice/current-user'
9
+ import { css, html, nothing, repeat } from '@umbraco-cms/backoffice/external/lit'
10
+ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
11
+ import { umbConfirmModal } from '@umbraco-cms/backoffice/modal'
12
+
13
+ const base = () => {
14
+ const href = document.querySelector('base')?.getAttribute('href') ?? '/umbraco/'
15
+ return `${href.replace(/\/$/, '')}/crombolo/api/bundles/signers`
16
+ }
17
+
18
+ /** The answer and its body; an outcome the server refused carries its message. */
19
+ async function call(path, method = 'GET', body) {
20
+ const response = await fetch(`${base()}${path}`, {
21
+ method,
22
+ credentials: 'include',
23
+ headers: {
24
+ accept: 'application/json',
25
+ ...(body ? { 'content-type': 'application/json' } : {}),
26
+ },
27
+ ...(body ? { body: JSON.stringify(body) } : {}),
28
+ })
29
+ const json = await response.json().catch(() => ({}))
30
+ if (!response.ok)
31
+ throw new Error(json.message ?? `The list could not be changed (${response.status}).`)
32
+ return json
33
+ }
34
+
35
+ const KINDS = {
36
+ user: 'User key',
37
+ site: 'Site key',
38
+ source: 'Build in CI',
39
+ }
40
+
41
+ const EMPTY = { kind: 'user', name: '', publicKey: '', source: '' }
42
+
43
+ const when = (iso) => (iso ? new Date(iso).toLocaleDateString() : '')
44
+
45
+ export default class CromboloTrustedSignersElement extends UmbLitElement {
46
+ static properties = {
47
+ _items: { state: true },
48
+ _draft: { state: true },
49
+ _renaming: { state: true },
50
+ _problem: { state: true },
51
+ _busy: { state: true },
52
+ _copied: { state: true },
53
+ _mine: { state: true },
54
+ _me: { state: true },
55
+ }
56
+
57
+ constructor() {
58
+ super()
59
+ this._items = undefined
60
+ this._draft = { ...EMPTY }
61
+ this._renaming = undefined
62
+ this._problem = ''
63
+ this._busy = false
64
+ this._copied = false
65
+ /** "Add my key" chosen: the form shows the steps to make one. */
66
+ this._mine = false
67
+ this._me = ''
68
+ this.consumeContext(UMB_CURRENT_USER_CONTEXT, (user) => {
69
+ this.observe(user?.currentUser, (current) => {
70
+ this._me = current?.name ?? ''
71
+ })
72
+ })
73
+ }
74
+
75
+ #addMine() {
76
+ this._mine = true
77
+ this._draft = { ...EMPTY, kind: 'user', name: this._me ? `${this._me}'s key` : '' }
78
+ this.updateComplete.then(() =>
79
+ this.renderRoot.querySelector('uui-box.add')?.scrollIntoView({ behavior: 'smooth' }),
80
+ )
81
+ }
82
+
83
+ /** The steps to make a key of your own, shown when adding yours. */
84
+ #steps() {
85
+ const name = (this._me || 'my-key')
86
+ .toLowerCase()
87
+ .replace(/[^a-z0-9]+/g, '-')
88
+ .replace(/^-|-$/g, '')
89
+ return html`<ol class="steps">
90
+ <li>
91
+ On your own computer, in a site's folder, run
92
+ <code>bunx crombolo keys create ${name}</code>. The private half stays on that computer.
93
+ </li>
94
+ <li>Copy the line it prints, which starts <code>crombolo-ed25519</code>.</li>
95
+ <li>Paste it below, and add it.</li>
96
+ <li>
97
+ Sign a site bundle with it: <code>bunx crombolo site build . --out ../bundle --sign-with
98
+ ${name}</code>.
99
+ </li>
100
+ </ol>`
101
+ }
102
+
103
+ connectedCallback() {
104
+ super.connectedCallback()
105
+ this.#load()
106
+ }
107
+
108
+ async #load() {
109
+ try {
110
+ this._items = (await call('')).items ?? []
111
+ } catch (error) {
112
+ this._problem = error.message
113
+ this._items = []
114
+ }
115
+ }
116
+
117
+ async #run(work) {
118
+ this._busy = true
119
+ this._problem = ''
120
+ try {
121
+ await work()
122
+ await this.#load()
123
+ } catch (error) {
124
+ this._problem = error.message
125
+ } finally {
126
+ this._busy = false
127
+ }
128
+ }
129
+
130
+ #add() {
131
+ const draft = this._draft
132
+ return this.#run(async () => {
133
+ this._mine = false
134
+ await call(
135
+ '',
136
+ 'POST',
137
+ draft.kind === 'source'
138
+ ? { kind: 'source', name: draft.name, source: draft.source }
139
+ : { kind: draft.kind, name: draft.name, publicKey: draft.publicKey },
140
+ )
141
+ this._draft = { ...EMPTY }
142
+ })
143
+ }
144
+
145
+ #rename(item) {
146
+ return this.#run(async () => {
147
+ await call(`/${item.id}`, 'PUT', { name: this._renaming.name })
148
+ this._renaming = undefined
149
+ })
150
+ }
151
+
152
+ async #remove(item) {
153
+ await umbConfirmModal(this, {
154
+ color: 'danger',
155
+ headline: `Stop trusting ${item.name}?`,
156
+ content:
157
+ 'Site bundles it signed are refused from now on, including ones already made. You can add it again later.',
158
+ confirmLabel: 'Remove',
159
+ })
160
+ await this.#run(() => call(`/${item.id}`, 'DELETE'))
161
+ }
162
+
163
+ async #copy(line) {
164
+ await navigator.clipboard?.writeText(line)
165
+ this._copied = true
166
+ setTimeout(() => {
167
+ this._copied = false
168
+ }, 2000)
169
+ }
170
+
171
+ #identity(item) {
172
+ return item.source
173
+ ? html`<code>${item.source}</code>`
174
+ : html`<code class="fingerprint">${item.fingerprint}</code>`
175
+ }
176
+
177
+ #row(item) {
178
+ const renaming = this._renaming?.id === item.id && item.id
179
+ return html`<li class="signer">
180
+ <div class="who">
181
+ ${
182
+ renaming
183
+ ? html`<uui-input
184
+ label="Name"
185
+ .value=${this._renaming.name}
186
+ @input=${(event) => (this._renaming = { ...this._renaming, name: event.target.value })}></uui-input>`
187
+ : html`<strong>${item.name}</strong>`
188
+ }
189
+ <span class="kind">${KINDS[item.kind] ?? item.kind}</span>
190
+ <div>${this.#identity(item)}</div>
191
+ <div class="meta">
192
+ ${
193
+ item.own
194
+ ? 'This site’s own key: always trusted here.'
195
+ : item.locked
196
+ ? 'Set in the site’s configuration.'
197
+ : `Added ${item.addedBy ? `by ${item.addedBy} ` : ''}on ${when(item.addedAt)}.`
198
+ }
199
+ ${item.lastSignedAt ? ` Last signed something applied here on ${when(item.lastSignedAt)}.` : ''}
200
+ </div>
201
+ </div>
202
+ <div class="actions">
203
+ ${
204
+ item.own
205
+ ? html`<uui-button
206
+ look="secondary"
207
+ label=${this._copied ? 'Copied' : 'Copy its public key'}
208
+ @click=${() => this.#copy(item.publicKey)}></uui-button>`
209
+ : nothing
210
+ }
211
+ ${
212
+ item.id && !item.locked
213
+ ? renaming
214
+ ? html`<uui-button look="primary" label="Save" ?disabled=${this._busy} @click=${() => this.#rename(item)}></uui-button>
215
+ <uui-button label="Cancel" @click=${() => (this._renaming = undefined)}></uui-button>`
216
+ : html`<uui-button
217
+ look="secondary"
218
+ label="Rename"
219
+ @click=${() => (this._renaming = { id: item.id, name: item.name })}></uui-button>
220
+ <uui-button
221
+ look="secondary"
222
+ color="danger"
223
+ label="Remove"
224
+ @click=${() => this.#remove(item)}></uui-button>`
225
+ : nothing
226
+ }
227
+ </div>
228
+ </li>`
229
+ }
230
+
231
+ #form() {
232
+ const draft = this._draft
233
+ const set = (patch) => {
234
+ this._draft = { ...this._draft, ...patch }
235
+ }
236
+ return html`<uui-box class="add" headline=${this._mine ? 'Add my key' : 'Add a trusted signer'}>
237
+ <div class="form">
238
+ ${this._mine ? this.#steps() : nothing}
239
+ <uui-select
240
+ label="What it is"
241
+ .options=${Object.entries(KINDS).map(([value, name]) => ({
242
+ name,
243
+ value,
244
+ selected: draft.kind === value,
245
+ }))}
246
+ @change=${(event) => set({ kind: event.target.value })}></uui-select>
247
+ <uui-input
248
+ label="Name"
249
+ placeholder=${draft.kind === 'source' ? 'Our site’s releases' : 'Adam’s laptop'}
250
+ .value=${draft.name}
251
+ @input=${(event) => set({ name: event.target.value })}></uui-input>
252
+ ${
253
+ draft.kind === 'source'
254
+ ? html`<uui-input
255
+ label="Repository"
256
+ placeholder="acme/site@v*"
257
+ .value=${draft.source}
258
+ @input=${(event) => set({ source: event.target.value })}></uui-input>
259
+ <p class="hint">
260
+ Bundles built and signed in GitHub Actions from this repository. Add @ and a tag
261
+ pattern to take only its releases.
262
+ </p>`
263
+ : html`<uui-textarea
264
+ label="Public key"
265
+ placeholder="crombolo-ed25519 AAAA… name"
266
+ .value=${draft.publicKey}
267
+ @input=${(event) => set({ publicKey: event.target.value })}></uui-textarea>
268
+ <p class="hint">
269
+ ${
270
+ draft.kind === 'site'
271
+ ? 'Another site’s key, from the top of its own Trusted signers list.'
272
+ : 'A person’s or a CI job’s key, from `crombolo keys create`.'
273
+ }
274
+ </p>`
275
+ }
276
+ <uui-button
277
+ look="primary"
278
+ label="Add"
279
+ ?disabled=${this._busy || !draft.name}
280
+ @click=${() => this.#add()}></uui-button>
281
+ </div>
282
+ </uui-box>`
283
+ }
284
+
285
+ render() {
286
+ if (!this._items) return html`<uui-loader></uui-loader>`
287
+ return html`
288
+ <uui-box headline="Trusted signers">
289
+ <uui-button
290
+ slot="header-actions"
291
+ look="primary"
292
+ label="Add my key"
293
+ @click=${() => this.#addMine()}></uui-button>
294
+ <p class="intro">
295
+ A site bundle is applied here only when one of these signed it. In production that is
296
+ required; elsewhere an unsigned one is applied, with a warning.
297
+ </p>
298
+ ${this._problem ? html`<p class="problem" role="alert">${this._problem}</p>` : nothing}
299
+ <ul class="signers">
300
+ ${repeat(
301
+ this._items,
302
+ (item) => item.id ?? item.fingerprint ?? item.source,
303
+ (item) => this.#row(item),
304
+ )}
305
+ </ul>
306
+ </uui-box>
307
+ ${this.#form()}
308
+ `
309
+ }
310
+
311
+ static styles = css`
312
+ :host {
313
+ display: block;
314
+ padding: var(--uui-size-layout-1);
315
+ max-width: 72rem;
316
+ }
317
+ uui-box + uui-box {
318
+ margin-top: var(--uui-size-layout-1);
319
+ }
320
+ .intro,
321
+ .hint,
322
+ .meta {
323
+ color: var(--uui-color-text-alt);
324
+ }
325
+ .intro {
326
+ margin-top: 0;
327
+ }
328
+ .signers {
329
+ list-style: none;
330
+ margin: 0;
331
+ padding: 0;
332
+ }
333
+ .signer {
334
+ display: flex;
335
+ justify-content: space-between;
336
+ gap: var(--uui-size-space-5);
337
+ padding: var(--uui-size-space-4) 0;
338
+ border-top: 1px solid var(--uui-color-divider);
339
+ }
340
+ .kind {
341
+ margin-left: var(--uui-size-space-3);
342
+ color: var(--uui-color-text-alt);
343
+ }
344
+ .fingerprint {
345
+ word-break: break-all;
346
+ }
347
+ .actions {
348
+ display: flex;
349
+ align-items: flex-start;
350
+ gap: var(--uui-size-space-2);
351
+ white-space: nowrap;
352
+ }
353
+ .form {
354
+ display: grid;
355
+ gap: var(--uui-size-space-4);
356
+ max-width: 40rem;
357
+ }
358
+ .form uui-button {
359
+ justify-self: start;
360
+ }
361
+ .problem {
362
+ color: var(--uui-color-danger);
363
+ }
364
+ .steps {
365
+ margin: 0;
366
+ padding-left: var(--uui-size-space-6);
367
+ }
368
+ .steps li + li {
369
+ margin-top: var(--uui-size-space-2);
370
+ }
371
+ `
372
+ }
373
+
374
+ customElements.define('crombolo-trusted-signers', CromboloTrustedSignersElement)
@@ -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.56.0",
5
+ "version": "0.57.0",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -190,14 +190,33 @@
190
190
  }
191
191
  ]
192
192
  },
193
+ {
194
+ "type": "dashboard",
195
+ "alias": "Crombolo.Dashboard.TrustedSigners",
196
+ "name": "Crombolo Trusted Signers",
197
+ "element": "/crombolo-plugin/trusted-signers.js",
198
+ "meta": {
199
+ "label": "Trusted signers",
200
+ "pathname": "trusted-signers"
201
+ },
202
+ "conditions": [
203
+ {
204
+ "alias": "Umb.Condition.SectionAlias",
205
+ "match": "Umb.Section.Settings"
206
+ },
207
+ {
208
+ "alias": "Umb.Condition.CurrentUser.IsAdmin"
209
+ }
210
+ ]
211
+ },
193
212
  {
194
213
  "type": "dashboard",
195
214
  "alias": "Crombolo.Dashboard.Bundles",
196
215
  "name": "Crombolo Bundles",
197
216
  "element": "/crombolo-plugin/bundles-tool.js",
198
217
  "meta": {
199
- "label": "Bundles",
200
- "pathname": "bundles"
218
+ "label": "Extensions",
219
+ "pathname": "extensions"
201
220
  },
202
221
  "conditions": [
203
222
  {