@crombolo/backoffice-host 0.64.0 → 0.66.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.64.0",
3
+ "version": "0.66.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",
@@ -19,7 +19,9 @@
19
19
  "type": "module",
20
20
  "exports": {
21
21
  ".": "./src/index.ts",
22
+ "./activity-words": "./plugin/bundles-activity-words.js",
22
23
  "./branding": "./src/branding.ts",
24
+ "./media-access-rules": "./plugin/media-access-rules.js",
23
25
  "./registry": "./src/registry.ts"
24
26
  },
25
27
  "files": [
@@ -32,7 +34,7 @@
32
34
  "access": "public"
33
35
  },
34
36
  "dependencies": {
35
- "@crombolo/core": "0.64.0",
36
- "@crombolo/backoffice-dist": "0.64.0"
37
+ "@crombolo/core": "0.66.0",
38
+ "@crombolo/backoffice-dist": "0.66.0"
37
39
  }
38
40
  }
@@ -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.64.0",
5
+ "version": "0.66.0",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Another person's command-line tokens (story 351), as a view on their user
3
+ * screen: an administrator sees them and revokes any. Shown only while the
4
+ * site takes tokens; the endpoint refuses anyone but an administrator.
5
+ */
6
+ import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
7
+ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
8
+ import { UMB_USER_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/user'
9
+ import { TOKENS_API } from './cli-tokens.js'
10
+ import { HEADLINE, NONE, OTHERS_INTRO, revokeQuestion, tokenLine } from './cli-tokens-words.js'
11
+
12
+ export default class CromboloCliTokensUserElement extends UmbLitElement {
13
+ static properties = { _state: { state: true }, _error: { state: true } }
14
+
15
+ #user = undefined
16
+
17
+ constructor() {
18
+ super()
19
+ this._state = undefined
20
+ this._error = ''
21
+ this.consumeContext(UMB_USER_WORKSPACE_CONTEXT, (context) => {
22
+ if (!context) return
23
+ this.observe(context.unique, (unique) => {
24
+ this.#user = unique ?? undefined
25
+ if (this.#user) this.#load()
26
+ })
27
+ })
28
+ }
29
+
30
+ async #load() {
31
+ try {
32
+ const response = await fetch(`${TOKENS_API}?user=${encodeURIComponent(this.#user)}`, {
33
+ credentials: 'include',
34
+ })
35
+ const body = await response.json().catch(() => ({}))
36
+ this._state = response.ok ? body : { enabled: true, items: [] }
37
+ this._error = response.ok ? '' : (body.message ?? 'Could not load the tokens.')
38
+ } catch {
39
+ this._error = 'Could not load the tokens.'
40
+ }
41
+ }
42
+
43
+ async #revoke(token) {
44
+ if (!confirm(revokeQuestion(token.name))) return
45
+ const response = await fetch(`${TOKENS_API}/${token.key}`, {
46
+ method: 'DELETE',
47
+ credentials: 'include',
48
+ })
49
+ if (!response.ok) this._error = 'That token could not be revoked.'
50
+ await this.#load()
51
+ }
52
+
53
+ render() {
54
+ if (!this._state) return nothing
55
+ if (!this._state.enabled)
56
+ return html`<uui-box headline=${HEADLINE}><p>This site does not take command-line tokens.</p></uui-box>`
57
+ const items = this._state.items ?? []
58
+ return html`<uui-box headline=${HEADLINE}>
59
+ <p class="muted">${OTHERS_INTRO}</p>
60
+ ${this._error ? html`<p class="error">${this._error}</p>` : nothing}
61
+ ${
62
+ items.length === 0
63
+ ? html`<p>${NONE}</p>`
64
+ : html`<ul>
65
+ ${items.map(
66
+ (token) => html`<li>
67
+ <div>
68
+ <strong>${token.name}</strong>
69
+ <small>${tokenLine(token)}</small>
70
+ </div>
71
+ <uui-button look="secondary" color="danger" label="Revoke" @click=${() => this.#revoke(token)}></uui-button>
72
+ </li>`,
73
+ )}
74
+ </ul>`
75
+ }
76
+ </uui-box>`
77
+ }
78
+
79
+ static styles = css`
80
+ :host {
81
+ display: block;
82
+ padding: var(--uui-size-layout-1);
83
+ }
84
+ ul {
85
+ list-style: none;
86
+ margin: 0;
87
+ padding: 0;
88
+ }
89
+ li {
90
+ display: flex;
91
+ justify-content: space-between;
92
+ align-items: center;
93
+ gap: var(--uui-size-space-4);
94
+ padding: var(--uui-size-space-3) 0;
95
+ border-bottom: 1px solid var(--uui-color-divider);
96
+ }
97
+ li div {
98
+ display: flex;
99
+ flex-direction: column;
100
+ }
101
+ small,
102
+ .muted {
103
+ color: var(--uui-color-text-alt);
104
+ }
105
+ .error {
106
+ color: var(--uui-color-danger);
107
+ }
108
+ `
109
+ }
110
+
111
+ customElements.define('crombolo-cli-tokens-user', CromboloCliTokensUserElement)
@@ -0,0 +1,74 @@
1
+ /** What the back office says about command-line tokens (story 351). Pure. */
2
+
3
+ export const HEADLINE = 'Command-line tokens'
4
+
5
+ /** What the profile box says the tokens are for. */
6
+ export const INTRO =
7
+ 'A token lets a script or an automated job run commands as you, with your permissions. ' +
8
+ 'Treat it like a password.'
9
+
10
+ /** What the user's screen says, for an administrator looking at someone else's. */
11
+ export const OTHERS_INTRO =
12
+ 'Tokens this person made so scripts can run commands as them. Revoking one stops it working straight away.'
13
+
14
+ export const NONE = 'No tokens.'
15
+
16
+ /** Shown above a new token, the one time it can be seen. */
17
+ export const SHOWN_ONCE = "Copy this token now. You won't be able to see it again."
18
+
19
+ /** The group editor's words for the permission. */
20
+ export const PERMISSION_LABEL = 'Command-line tokens'
21
+ export const PERMISSION_DESCRIPTION = 'Create tokens that let scripts run commands as you'
22
+
23
+ /**
24
+ * A date as the browser writes dates: "14 Dec 2026".
25
+ * @param {string} iso
26
+ * @param {string} [locale]
27
+ * @returns {string}
28
+ */
29
+ export function day(iso, locale) {
30
+ return new Date(iso).toLocaleDateString(locale, {
31
+ day: 'numeric',
32
+ month: 'short',
33
+ year: 'numeric',
34
+ })
35
+ }
36
+
37
+ /**
38
+ * The line under a token's name: when it stops working and when it was last used.
39
+ * @param {{ expiresAt: string, lastUsedAt: string | null }} token
40
+ * @param {string} [locale]
41
+ * @returns {string}
42
+ */
43
+ export function tokenLine(token, locale) {
44
+ const used = token.lastUsedAt ? `last used ${day(token.lastUsedAt, locale)}` : 'not used yet'
45
+ return `Works until ${day(token.expiresAt, locale)}, ${used}`
46
+ }
47
+
48
+ /**
49
+ * How long a new token may last, as choices: the usual lengths up to the site's limit, and the limit.
50
+ * @param {number} maxDays
51
+ * @returns {Array<{ days: number, label: string }>}
52
+ */
53
+ export function expiryChoices(maxDays) {
54
+ const days = [...new Set([7, 30, 60, 90].filter((d) => d < maxDays).concat(maxDays))]
55
+ return days.map((d) => ({ days: d, label: d === 1 ? '1 day' : `${d} days` }))
56
+ }
57
+
58
+ /**
59
+ * Whether Create may be pressed, and what it says.
60
+ * @param {string} name
61
+ * @returns {{ enabled: boolean, label: string }}
62
+ */
63
+ export function createButton(name) {
64
+ return name.trim() === ''
65
+ ? { enabled: false, label: 'Give it a name' }
66
+ : { enabled: true, label: 'Create token' }
67
+ }
68
+
69
+ /**
70
+ * The question before revoking.
71
+ * @param {string} name
72
+ * @returns {string}
73
+ */
74
+ export const revokeQuestion = (name) => `Revoke "${name}"? Anything using it will stop working.`
@@ -0,0 +1,196 @@
1
+ /**
2
+ * A person's command-line tokens (story 351), in their profile: listed, made
3
+ * from a name and how long it lasts and shown once with a copy button, and
4
+ * revoked. Making one is offered only to someone whose groups give it.
5
+ */
6
+ import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
7
+ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
8
+ import {
9
+ createButton,
10
+ expiryChoices,
11
+ HEADLINE,
12
+ INTRO,
13
+ NONE,
14
+ revokeQuestion,
15
+ SHOWN_ONCE,
16
+ tokenLine,
17
+ } from './cli-tokens-words.js'
18
+
19
+ /** The plugin's API, under the back office wherever it is mounted. */
20
+ export const TOKENS_API = `${(document.querySelector('base')?.getAttribute('href') ?? '/crombolo/').replace(/\/$/, '')}/crombolo/api/cli-tokens`
21
+
22
+ export default class CromboloCliTokensElement extends UmbLitElement {
23
+ static properties = {
24
+ _state: { state: true },
25
+ _error: { state: true },
26
+ _name: { state: true },
27
+ _days: { state: true },
28
+ _made: { state: true },
29
+ }
30
+
31
+ constructor() {
32
+ super()
33
+ this._state = undefined
34
+ this._error = ''
35
+ this._name = ''
36
+ this._days = undefined
37
+ this._made = undefined
38
+ }
39
+
40
+ connectedCallback() {
41
+ super.connectedCallback()
42
+ this.#load()
43
+ }
44
+
45
+ async #load() {
46
+ try {
47
+ const response = await fetch(TOKENS_API, { credentials: 'include' })
48
+ this._state = response.ok ? await response.json() : { enabled: false }
49
+ this._days ??= this._state.defaultDays
50
+ } catch {
51
+ this._error = 'Could not load your tokens.'
52
+ }
53
+ }
54
+
55
+ async #create() {
56
+ this._error = ''
57
+ const response = await fetch(TOKENS_API, {
58
+ method: 'POST',
59
+ credentials: 'include',
60
+ headers: { 'content-type': 'application/json' },
61
+ body: JSON.stringify({ name: this._name, days: Number(this._days) }),
62
+ })
63
+ const body = await response.json().catch(() => ({}))
64
+ if (!response.ok) this._error = body.message ?? 'The token could not be made.'
65
+ else {
66
+ this._made = body
67
+ this._name = ''
68
+ }
69
+ await this.#load()
70
+ }
71
+
72
+ async #revoke(token) {
73
+ if (!confirm(revokeQuestion(token.name))) return
74
+ const response = await fetch(`${TOKENS_API}/${token.key}`, {
75
+ method: 'DELETE',
76
+ credentials: 'include',
77
+ })
78
+ if (!response.ok) this._error = 'That token could not be revoked.'
79
+ if (this._made?.key === token.key) this._made = undefined
80
+ await this.#load()
81
+ }
82
+
83
+ async #copy() {
84
+ await navigator.clipboard?.writeText(this._made.token)
85
+ }
86
+
87
+ #renderNew() {
88
+ if (!this._state.mayCreate) return nothing
89
+ const button = createButton(this._name)
90
+ return html`<div class="new">
91
+ <uui-input
92
+ label="Name"
93
+ placeholder="What it is for"
94
+ .value=${this._name}
95
+ @input=${(e) => {
96
+ this._name = e.target.value
97
+ }}></uui-input>
98
+ <uui-select
99
+ label="Lasts"
100
+ .options=${expiryChoices(this._state.maxDays).map((c) => ({
101
+ name: c.label,
102
+ value: String(c.days),
103
+ selected: c.days === Number(this._days),
104
+ }))}
105
+ @change=${(e) => {
106
+ this._days = e.target.value
107
+ }}></uui-select>
108
+ <uui-button
109
+ look="primary"
110
+ label=${button.label}
111
+ ?disabled=${!button.enabled}
112
+ @click=${() => this.#create()}></uui-button>
113
+ </div>`
114
+ }
115
+
116
+ render() {
117
+ if (!this._state?.enabled) return nothing
118
+ const items = this._state.items ?? []
119
+ return html`<uui-box headline=${HEADLINE}>
120
+ <p class="muted">${INTRO}</p>
121
+ ${this._error ? html`<p class="error">${this._error}</p>` : nothing}
122
+ ${
123
+ this._made
124
+ ? html`<div class="made">
125
+ <strong>${SHOWN_ONCE}</strong>
126
+ <code>${this._made.token}</code>
127
+ <uui-button look="secondary" label="Copy" @click=${() => this.#copy()}></uui-button>
128
+ </div>`
129
+ : nothing
130
+ }
131
+ ${this.#renderNew()}
132
+ ${
133
+ items.length === 0
134
+ ? html`<p>${NONE}</p>`
135
+ : html`<ul>
136
+ ${items.map(
137
+ (token) => html`<li>
138
+ <div>
139
+ <strong>${token.name}</strong>
140
+ <small>${tokenLine(token)}</small>
141
+ </div>
142
+ <uui-button look="secondary" color="danger" label="Revoke" @click=${() => this.#revoke(token)}></uui-button>
143
+ </li>`,
144
+ )}
145
+ </ul>`
146
+ }
147
+ </uui-box>`
148
+ }
149
+
150
+ static styles = css`
151
+ ul {
152
+ list-style: none;
153
+ margin: 0;
154
+ padding: 0;
155
+ }
156
+ li {
157
+ display: flex;
158
+ justify-content: space-between;
159
+ align-items: center;
160
+ gap: var(--uui-size-space-4);
161
+ padding: var(--uui-size-space-3) 0;
162
+ border-bottom: 1px solid var(--uui-color-divider);
163
+ }
164
+ li div {
165
+ display: flex;
166
+ flex-direction: column;
167
+ }
168
+ .new {
169
+ display: flex;
170
+ gap: var(--uui-size-space-3);
171
+ align-items: center;
172
+ margin-bottom: var(--uui-size-space-4);
173
+ }
174
+ .made {
175
+ display: flex;
176
+ flex-direction: column;
177
+ gap: var(--uui-size-space-2);
178
+ padding: var(--uui-size-space-4);
179
+ margin-bottom: var(--uui-size-space-4);
180
+ border: 1px solid var(--uui-color-positive);
181
+ border-radius: var(--uui-border-radius);
182
+ }
183
+ code {
184
+ word-break: break-all;
185
+ }
186
+ small,
187
+ .muted {
188
+ color: var(--uui-color-text-alt);
189
+ }
190
+ .error {
191
+ color: var(--uui-color-danger);
192
+ }
193
+ `
194
+ }
195
+
196
+ customElements.define('crombolo-cli-tokens', CromboloCliTokensElement)
@@ -4,6 +4,8 @@
4
4
  * server's (`@crombolo/core`, `permission-levels.ts`).
5
5
  */
6
6
 
7
+ import { PERMISSION_DESCRIPTION, PERMISSION_LABEL } from './cli-tokens-words.js'
8
+
7
9
  export const TABS = [
8
10
  { id: 'access', label: 'Access' },
9
11
  { id: 'permissions', label: 'Permissions' },
@@ -243,6 +245,12 @@ export const TRANSFER = [
243
245
  label: 'Install code on this site',
244
246
  line: 'Templates, server code and whole-site pushes: all of these run on the server. Nobody has this unless a group gives it, administrators included. Keep it on a group of its own, such as "Deployers".',
245
247
  },
248
+ {
249
+ group: 'Command line',
250
+ verb: 'Crombolo.CliTokens.Create',
251
+ label: PERMISSION_LABEL,
252
+ line: `${PERMISSION_DESCRIPTION}. Nobody has this unless a group gives it, administrators included.`,
253
+ },
246
254
  ]
247
255
 
248
256
  /** Verbs the editor speaks for; anything else a group holds is an extension's, kept as it is. */
@@ -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.64.0",
5
+ "version": "0.66.0",
6
6
  "allowPublicAccess": true,
7
7
  "extensions": [
8
8
  {
@@ -5,7 +5,8 @@
5
5
  import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
6
6
  import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
7
7
  import { UMB_MEDIA_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/media'
8
- import { readMediaAccess, summarise, usedByText } from './media-access.js'
8
+ import { readMediaAccess } from './media-access.js'
9
+ import { summarise, usedByText } from './media-access-rules.js'
9
10
 
10
11
  export default class CromboloMediaAccessInfoElement extends UmbLitElement {
11
12
  static properties = {
@@ -6,6 +6,7 @@
6
6
  import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
7
7
  import { UmbModalBaseElement } from '@umbraco-cms/backoffice/modal'
8
8
  import '@umbraco-cms/backoffice/member'
9
+ import { readMediaAccess, saveMediaAccess } from './media-access.js'
9
10
  import {
10
11
  bytesOf,
11
12
  describeAccess,
@@ -14,12 +15,10 @@ import {
14
15
  megabytesOf,
15
16
  PUBLIC_NOTE,
16
17
  READ_MODES,
17
- readMediaAccess,
18
18
  requestFor,
19
- saveMediaAccess,
20
19
  usedByText,
21
20
  WRITE_MODES,
22
- } from './media-access.js'
21
+ } from './media-access-rules.js'
23
22
 
24
23
  export default class CromboloMediaAccessModalElement extends UmbModalBaseElement {
25
24
  static properties = {
@@ -0,0 +1,96 @@
1
+ /** Types for media-access-rules.js, so a site's own tsconfig, without allowJs, checks the server against them. */
2
+
3
+ export interface GroupGrant {
4
+ name: string
5
+ read: boolean
6
+ write: boolean
7
+ }
8
+ export interface MemberGrant {
9
+ key: string
10
+ read: boolean
11
+ write: boolean
12
+ }
13
+ export interface Rule {
14
+ publicRead?: boolean
15
+ groups?: GroupGrant[]
16
+ members?: MemberGrant[]
17
+ newRead?: string | null
18
+ newWrite?: string | null
19
+ memberTypes?: string[]
20
+ memberMaxBytes?: number | null
21
+ }
22
+ export interface ItemPolicy {
23
+ readPolicy: string
24
+ writePolicy: string
25
+ }
26
+ export interface AccessState {
27
+ key?: string
28
+ name?: string
29
+ hasParent?: boolean
30
+ hasFile?: boolean
31
+ own?: Rule | null
32
+ inherited?: (Rule & { from?: { key?: string; name: string } }) | null
33
+ item: ItemPolicy & { creator?: { key: string; name?: string | null } | null }
34
+ protected?: boolean
35
+ memberGroups?: string[]
36
+ usedBy?: string[]
37
+ }
38
+ export interface AccessView {
39
+ read: string
40
+ write: string
41
+ allMembers: boolean
42
+ groups: GroupGrant[]
43
+ members: MemberGrant[]
44
+ newRead: string | null
45
+ newWrite: string | null
46
+ memberTypes: string[]
47
+ memberMaxBytes: number | null
48
+ }
49
+ export interface AccessForm {
50
+ inherit: boolean
51
+ read: string
52
+ write: string
53
+ allMembers?: boolean
54
+ groups: GroupGrant[]
55
+ members: MemberGrant[]
56
+ newRead?: string | null
57
+ newWrite?: string | null
58
+ memberTypes?: string[]
59
+ memberMaxBytes?: number | null
60
+ }
61
+ export interface AccessRequest {
62
+ rule:
63
+ | (Required<
64
+ Pick<
65
+ Rule,
66
+ 'publicRead' | 'groups' | 'newRead' | 'newWrite' | 'memberTypes' | 'memberMaxBytes'
67
+ >
68
+ > &
69
+ Pick<Rule, 'members'>)
70
+ | null
71
+ item: ItemPolicy
72
+ }
73
+
74
+ export const PUBLIC_NOTE: string
75
+ export function summarise(state: AccessState | undefined): string
76
+ export function groupRows(rule: Rule | null | undefined, memberGroups: string[]): GroupGrant[]
77
+ export function megabytesOf(bytes: number | null | undefined): string
78
+ export function bytesOf(megabytes: string | number | null | undefined): number | null
79
+ export const READ_MODES: { value: string; label: string }[]
80
+ export const WRITE_MODES: { value: string; label: string }[]
81
+ export function accessMode(
82
+ policy: string,
83
+ action: 'read' | 'write',
84
+ rule: Rule | null | undefined,
85
+ ): string
86
+ export function inheritsParent(state: AccessState): boolean
87
+ export function viewOf(
88
+ rule: Rule | null | undefined,
89
+ item: ItemPolicy & { creator?: { key: string } | null },
90
+ state: AccessState,
91
+ ): AccessView
92
+ export function formFor(state: AccessState): AccessForm & AccessView
93
+ export function inheritedForm(state: AccessState): AccessForm & AccessView
94
+ export function describeAccess(form: AccessForm, state: AccessState): string
95
+ export function requestFor(form: AccessForm, original?: ItemPolicy): AccessRequest
96
+ export function usedByText(bundles: string[] | null | undefined): string