@crombolo/backoffice-host 0.59.0 → 0.61.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.
@@ -15,10 +15,10 @@
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'
20
18
  import { carriesTags } from './bundles-carries.js'
21
19
  import { bundleSignature, installBundle, searchMarketplace } from './bundles-client.js'
20
+ import { levelBlock, levelStyles } from './bundles-level.js'
21
+ import { configSnippet, grantChoice, unvouchedLine } from './bundles-level-words.js'
22
22
  import { signatureBlock, signatureStyles, signatureWords } from './bundles-signature.js'
23
23
 
24
24
  export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
@@ -36,12 +36,9 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
36
36
  _elsewhere: { state: true },
37
37
  _consenting: { state: true },
38
38
  _trusted: { state: true },
39
- _trustsCode: { state: true },
40
39
  _asks: { state: true },
41
- _asksActAs: { state: true },
42
40
  _layout: { state: true },
43
41
  _layoutChoice: { state: true },
44
- _actAs: { state: true },
45
42
  _reviewing: { state: true },
46
43
  _signatures: { state: true },
47
44
  }
@@ -63,8 +60,6 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
63
60
  this._consenting = ''
64
61
  this._trusted = false
65
62
  this._asks = []
66
- this._asksActAs = false
67
- this._actAs = 'installer'
68
63
  this._reviewing = ''
69
64
  this._signatures = new Map()
70
65
  }
@@ -85,6 +80,9 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
85
80
  this._appliesContent = result.appliesContent !== false
86
81
  this._installs = result.installs !== false
87
82
  this._elsewhere = result.installsElsewhere ?? null
83
+ this._mayGrant = result.mayGrant ?? {}
84
+ // Story 324: installing is an administrator's, as granting is.
85
+ this._isAdmin = this._mayGrant.limited === 'yes'
88
86
  } catch (error) {
89
87
  this._error = error instanceof Error ? error.message : String(error)
90
88
  } finally {
@@ -164,22 +162,19 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
164
162
  #askConsent(item, outcome) {
165
163
  this._consenting = item.name
166
164
  this._trusted = false
167
- this._trustsCode = false
168
165
  this._asks = outcome.permissions ?? []
169
- this._asksActAs = outcome.asksActAs === true
166
+ // Story 324: how far it reaches, and the four groups, before anything else.
167
+ this._level = outcome.level ?? 'limited'
168
+ this._groups = outcome.groups ?? {}
169
+ this._id = outcome.id ?? item.name
170
170
  // Story 312: the site layout its page templates sit in, its suggestion first.
171
171
  this._layout = outcome.layout
172
172
  this._layoutChoice = outcome.layout?.suggested ?? ''
173
173
  }
174
174
 
175
- #asksForCode() {
176
- return Boolean(splitBackOfficeCode(this._asks).code)
177
- }
178
-
179
175
  #cancelConsent() {
180
176
  this._consenting = ''
181
177
  this._trusted = false
182
- this._trustsCode = false
183
178
  this._asks = []
184
179
  }
185
180
 
@@ -192,7 +187,6 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
192
187
  item.version,
193
188
  !this._declined.has(item.name),
194
189
  granting ? this._asks.map((ask) => ask.permission) : [],
195
- granting && this._asksActAs ? this._actAs : undefined,
196
190
  granting && this._layout && this._layoutChoice
197
191
  ? { [this._layout.key]: this._layoutChoice }
198
192
  : undefined,
@@ -240,58 +234,20 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
240
234
  `
241
235
  }
242
236
 
243
- /** What it asks for, each permission with its reason, granted together in its own card. */
237
+ /** How far it reaches at a glance, the four groups, the detail on asking, and the grant (story 324). */
244
238
  #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
239
  const checked = this._signatures.get(item.name)
248
- const signature = checked
249
- ? signatureWords(checked.provenance, checked.refused, checked.policy)
250
- : undefined
240
+ const state = checked?.provenance?.state
241
+ const choice = grantChoice(this._level, this._mayGrant, state)
251
242
  return html`
252
243
  <div class="consent" role="group" aria-label="What it asks for">
244
+ ${levelBlock({
245
+ level: this._level,
246
+ groups: this._groups,
247
+ permissions: this._asks,
248
+ unvouched: unvouchedLine(this._level, state),
249
+ })}
253
250
  ${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
- }
265
- <p>
266
- <strong>It asks for these permissions.</strong> Grant them to install it: it may do only
267
- this.
268
- </p>
269
- <ul class="asks">
270
- ${rest.map(
271
- (ask) =>
272
- html`<li>
273
- ${ask.allows}${ask.origins?.length ? html`: ${ask.origins.join(', ')}` : nothing}
274
- ${ask.reason ? html`<span class="reason">${ask.reason}</span>` : nothing}
275
- </li>`,
276
- )}
277
- </ul>
278
- ${
279
- this._asksActAs
280
- ? html`<uui-select
281
- label="Acts for"
282
- .options=${[
283
- {
284
- name: 'You, who install it',
285
- value: 'installer',
286
- selected: this._actAs === 'installer',
287
- },
288
- { name: 'Whoever uses it', value: 'caller', selected: this._actAs === 'caller' },
289
- ]}
290
- @change=${(event) => {
291
- this._actAs = event.target.value
292
- }}></uui-select>`
293
- : nothing
294
- }
295
251
  ${
296
252
  this._layout
297
253
  ? html`<uui-select
@@ -318,22 +274,44 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
318
274
  : nothing
319
275
  }
320
276
  </p>
321
- <uui-checkbox
322
- label="I trust this publisher, and grant what it asks for"
323
- .checked=${this._trusted}
324
- @change=${(event) => {
325
- this._trusted = event.target.checked
326
- }}></uui-checkbox>
327
- <div class="actions">
328
- <uui-button
329
- look="primary"
330
- color="warning"
331
- label="Grant and install"
332
- ?disabled=${!this._trusted || (this.#asksForCode() && !this._trustsCode)}
333
- .state=${this._busy === item.name ? 'waiting' : undefined}
334
- @click=${() => this.#install(item, true)}></uui-button>
335
- <uui-button look="secondary" label="Cancel" @click=${this.#cancelConsent}></uui-button>
336
- </div>
277
+ ${
278
+ choice.grant
279
+ ? html`<uui-checkbox
280
+ label="I trust this publisher, and grant what it asks for"
281
+ .checked=${this._trusted}
282
+ @change=${(event) => {
283
+ this._trusted = event.target.checked
284
+ }}></uui-checkbox>
285
+ <div class="actions">
286
+ <uui-button
287
+ look="primary"
288
+ color=${this._level === 'limited' ? 'positive' : 'warning'}
289
+ label="Grant and install"
290
+ ?disabled=${!this._trusted}
291
+ .state=${this._busy === item.name ? 'waiting' : undefined}
292
+ @click=${() => this.#install(item, true)}></uui-button>
293
+ <uui-button look="secondary" label="Cancel" @click=${this.#cancelConsent}></uui-button>
294
+ </div>`
295
+ : html`<p class="note">
296
+ ${
297
+ choice.snippet
298
+ ? 'This site turns on Unrestricted extensions only in its configuration. Your developers add this to crombolo.config.ts:'
299
+ : choice.sentence
300
+ }
301
+ </p>
302
+ ${
303
+ choice.snippet
304
+ ? html`<pre class="snippet">${configSnippet(
305
+ this._id,
306
+ this._asks.map((ask) => ask.permission),
307
+ this._asks.flatMap((ask) => ask.origins ?? []),
308
+ )}</pre>`
309
+ : nothing
310
+ }
311
+ <div class="actions">
312
+ <uui-button look="secondary" label="Cancel" @click=${this.#cancelConsent}></uui-button>
313
+ </div>`
314
+ }
337
315
  </div>
338
316
  `
339
317
  }
@@ -402,11 +380,13 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
402
380
  ? this._elsewhere
403
381
  ? html`<p class="meta">${this.#elsewhereLink() || this._elsewhere.message}</p>`
404
382
  : html`<p class="meta">Add it to the site with <code>bun add ${item.name}</code>, then deploy.</p>`
405
- : this._consenting === item.name
406
- ? this.#consent(item)
407
- : this._reviewing === item.name
408
- ? this.#review(item)
409
- : html`
383
+ : !this._isAdmin
384
+ ? html`<p class="meta">An administrator can install this.</p>`
385
+ : this._consenting === item.name
386
+ ? this.#consent(item)
387
+ : this._reviewing === item.name
388
+ ? this.#review(item)
389
+ : html`
410
390
  <uui-button
411
391
  look="primary"
412
392
  label="Install"
@@ -425,7 +405,7 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
425
405
 
426
406
  static styles = [
427
407
  signatureStyles,
428
- backOfficeCodeStyles,
408
+ levelStyles,
429
409
  css`
430
410
  :host {
431
411
  display: block;
@@ -7,23 +7,15 @@
7
7
  */
8
8
  import { treeFor } from './settings-cards.js'
9
9
 
10
- const STRUCTURE = 'Crombolo.Section.Structure'
11
- const COMPONENTS = 'Crombolo.Section.Components'
12
- const WORKFLOW_SETUP = 'Crombolo.Section.WorkflowSetup'
10
+ const SETTINGS = 'Umb.Section.Settings'
13
11
  const APPROVALS = 'Crombolo.Section.Workflow'
14
12
  /** Reading forms, which is what a group's Forms comes to. */
15
13
  const FORM_READ = 'Crombolo.Form.Read'
16
14
  const FORMS = 'Crombolo.Section.Forms'
17
15
  const CONTENT = 'Umb.Section.Content'
18
16
 
19
- /**
20
- * Forms and Workflows are nodes in Structure; someone with either alone, and not
21
- * Structure, gets it beside the other in the Forms section.
22
- */
23
- const STRUCTURE_ELSE = [
24
- { path: 'section/forms', section: FORMS, verb: FORM_READ },
25
- { path: 'section/forms/view/workflows', section: WORKFLOW_SETUP },
26
- ]
17
+ /** Forms is a node in Structure; someone with Forms and not Settings gets it in the Forms section. */
18
+ const STRUCTURE_ELSE = [{ path: 'section/forms', section: FORMS, verb: FORM_READ }]
27
19
 
28
20
  const ITEMS = [
29
21
  { label: 'Pages', path: 'section/content', section: CONTENT },
@@ -31,10 +23,10 @@ const ITEMS = [
31
23
  {
32
24
  label: 'Structure',
33
25
  path: 'section/settings/structure',
34
- section: STRUCTURE,
26
+ section: SETTINGS,
35
27
  or: STRUCTURE_ELSE,
36
28
  },
37
- { label: 'Code', path: 'section/settings/code', section: COMPONENTS },
29
+ { label: 'Code', path: 'section/settings/code', section: SETTINGS },
38
30
  ]
39
31
 
40
32
  /**
@@ -0,0 +1,124 @@
1
+ /**
2
+ * What the back office decides about a described screen without asking the
3
+ * extension (story 323): which fields show, which hints apply, whether a form
4
+ * may be sent, where a link may go and what an action sends. Pure, so it is
5
+ * tested without a browser.
6
+ */
7
+
8
+ const isEmpty = (value) =>
9
+ value === undefined ||
10
+ value === null ||
11
+ value === '' ||
12
+ (Array.isArray(value) && value.length === 0)
13
+
14
+ /** Whether a condition holds over a form's current values. */
15
+ export function holds(condition, values) {
16
+ if (!condition) return true
17
+ const value = values?.[condition.field]
18
+ if (condition.notEmpty && isEmpty(value)) return false
19
+ if ('equals' in condition && value !== condition.equals) return false
20
+ if (Array.isArray(condition.oneOf) && !condition.oneOf.includes(value)) return false
21
+ return true
22
+ }
23
+
24
+ /** The fields a form shows now. */
25
+ export const visibleFields = (fields, values) =>
26
+ (fields ?? []).filter((field) => holds(field.visibleWhen, values))
27
+
28
+ /** A field's hint, and the hints whose conditions hold. */
29
+ export function hintsFor(field, values) {
30
+ return [
31
+ ...(field.hint ? [field.hint] : []),
32
+ ...(field.hints ?? []).filter((hint) => holds(hint.when, values)).map((hint) => hint.text),
33
+ ]
34
+ }
35
+
36
+ /** Why each shown field cannot be sent as it is, by name; empty when the form may be sent. */
37
+ export function fieldProblems(fields, values) {
38
+ const problems = {}
39
+ for (const field of visibleFields(fields, values)) {
40
+ const value = values?.[field.name]
41
+ if (field.required && isEmpty(value) && field.kind !== 'boolean') {
42
+ problems[field.name] = `${field.label} is required.`
43
+ continue
44
+ }
45
+ // A list with a minimum is short of it even when it has no rows.
46
+ if (isEmpty(value) && !(field.kind === 'list' && field.min)) continue
47
+ // Story 329: a list's rows, each held to its sub-fields, and to its bounds.
48
+ if (field.kind === 'list') {
49
+ const rows = Array.isArray(value) ? value : []
50
+ if (field.min !== undefined && rows.length < field.min)
51
+ problems[field.name] = `${field.label} needs at least ${field.min}.`
52
+ else if (field.max !== undefined && rows.length > field.max)
53
+ problems[field.name] = `${field.label} takes at most ${field.max}.`
54
+ else
55
+ for (const [index, row] of rows.entries()) {
56
+ const inner = Object.values(fieldProblems(field.fields, row))
57
+ if (inner.length > 0) {
58
+ problems[field.name] = `Row ${index + 1}: ${inner[0]}`
59
+ break
60
+ }
61
+ }
62
+ continue
63
+ }
64
+ if (field.kind === 'text') {
65
+ const text = String(value)
66
+ if (field.minLength !== undefined && text.length < field.minLength)
67
+ problems[field.name] = `${field.label} needs at least ${field.minLength} characters.`
68
+ else if (field.maxLength !== undefined && text.length > field.maxLength)
69
+ problems[field.name] = `${field.label} takes at most ${field.maxLength} characters.`
70
+ else if (field.pattern) {
71
+ let matches = true
72
+ try {
73
+ matches = new RegExp(`^(?:${field.pattern})$`, 'u').test(text)
74
+ } catch {}
75
+ if (!matches) problems[field.name] = `${field.label} is not in the form it takes.`
76
+ }
77
+ }
78
+ if (field.kind === 'number') {
79
+ const n = Number(value)
80
+ if (!Number.isFinite(n)) problems[field.name] = `${field.label} is a number.`
81
+ else if (field.min !== undefined && n < field.min)
82
+ problems[field.name] = `${field.label} is at least ${field.min}.`
83
+ else if (field.max !== undefined && n > field.max)
84
+ problems[field.name] = `${field.label} is at most ${field.max}.`
85
+ }
86
+ }
87
+ return problems
88
+ }
89
+
90
+ /**
91
+ * Where a link goes, or undefined when it may not: http and https, a path on
92
+ * this site, or a back-office path, which is put below the back office's base.
93
+ */
94
+ export function linkTarget(href, backOfficeBase) {
95
+ if (typeof href !== 'string') return undefined
96
+ const trimmed = href.trim()
97
+ if (/^https?:\/\//i.test(trimmed)) return trimmed
98
+ if (trimmed.startsWith('section/')) return `${backOfficeBase.replace(/\/$/, '')}/${trimmed}`
99
+ if (/^\/(?!\/)/.test(trimmed) && !trimmed.includes('\\')) return trimmed
100
+ return undefined
101
+ }
102
+
103
+ /** Where a screen answers: below its extension's back-office namespace. */
104
+ export const screenUrl = (backOfficeBase, bundle, screen) =>
105
+ `${backOfficeBase.replace(/\/$/, '')}/crombolo/api/bundle/${encodeURIComponent(bundle)}/_screen/${encodeURIComponent(screen)}`
106
+
107
+ /** The visible values of a form, with an untouched secret left out. */
108
+ export function sentValues(fields, values, typedSecrets) {
109
+ const out = {}
110
+ for (const field of visibleFields(fields, values)) {
111
+ if (field.kind === 'secret' && !typedSecrets?.has(field.name)) continue
112
+ // A read-only field is the screen's to show, never the person's to send (story 329).
113
+ if (field.readOnly) continue
114
+ if (values?.[field.name] !== undefined) out[field.name] = values[field.name]
115
+ }
116
+ return out
117
+ }
118
+
119
+ /** What a button sends: its action, its input, the form's values when it submits, and the state. */
120
+ export function actionBody(button, state, form) {
121
+ const input = { ...(button.input ?? {}) }
122
+ if (button.submit && form) input.values = form
123
+ return { action: button.action, input, state: state ?? {} }
124
+ }