@crombolo/core 0.45.0 → 0.47.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/core",
3
- "version": "0.45.0",
3
+ "version": "0.47.0",
4
4
  "description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. Domain model, entity keys and shared contracts for crombolo. No I/O.",
5
5
  "license": "MIT",
6
6
  "author": "Crombolo",
@@ -28,6 +28,6 @@
28
28
  "access": "public"
29
29
  },
30
30
  "dependencies": {
31
- "@crombolo/common": "0.45.0"
31
+ "@crombolo/common": "0.47.0"
32
32
  }
33
33
  }
package/src/index.ts CHANGED
@@ -25,6 +25,7 @@ export * from './media-access.ts'
25
25
  export * from './notifications.ts'
26
26
  export * from './object-types.ts'
27
27
  export * from './paging.ts'
28
+ export * from './permission-names.ts'
28
29
  export * from './permissions.ts'
29
30
  export * from './problem-details.ts'
30
31
  export * from './property-values.ts'
@@ -0,0 +1,153 @@
1
+ /**
2
+ * Permissions, sections and webhook events by plain names (story 254): what a
3
+ * person types at the command line, beside the verbs and aliases that are
4
+ * stored. A permission's plain name is always `area:action`, since read,
5
+ * publish and the rest exist for pages, Library items, media and forms alike.
6
+ */
7
+ import {
8
+ DocumentPermissions,
9
+ ElementContainerPermissions,
10
+ ElementPermissions,
11
+ FormPermissions,
12
+ MediaPermissions,
13
+ RemotePermissions,
14
+ } from './permissions.ts'
15
+ import type { SECTION_ALIASES } from './sections.ts'
16
+
17
+ export interface PermissionName {
18
+ /** `content:publish` */
19
+ name: string
20
+ area: string
21
+ /** `Umb.Document.Publish`, as a group stores it. */
22
+ verb: string
23
+ /** What it allows, in a line. */
24
+ says: string
25
+ }
26
+
27
+ const kebab = (text: string) =>
28
+ text
29
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
30
+ .replace(/([A-Z])([A-Z][a-z])/g, '$1-$2')
31
+ .toLowerCase()
32
+
33
+ const area = (
34
+ name: string,
35
+ verbs: Record<string, string>,
36
+ says: Record<string, string>,
37
+ strip = '',
38
+ ): PermissionName[] =>
39
+ Object.entries(verbs).map(([key, verb]) => ({
40
+ name: `${name}:${kebab(key.slice(strip.length))}`,
41
+ area: name,
42
+ verb,
43
+ says: says[key] ?? key,
44
+ }))
45
+
46
+ const { EntriesView, EntriesManage, EntriesSensitive, ...formDesign } = FormPermissions
47
+
48
+ export const PERMISSION_NAMES: readonly PermissionName[] = [
49
+ ...area('content', DocumentPermissions, {
50
+ Read: 'See pages',
51
+ Create: 'Create pages',
52
+ Update: 'Change pages',
53
+ Delete: 'Delete pages',
54
+ Publish: 'Publish pages',
55
+ Unpublish: 'Unpublish pages',
56
+ Move: 'Move pages',
57
+ Duplicate: 'Copy pages',
58
+ Sort: 'Change the order of pages',
59
+ Rollback: "Put back a page's earlier version",
60
+ Notifications: 'Choose the notifications they get about pages',
61
+ Permissions: 'Set who may do what on a page',
62
+ CultureAndHostnames: "Set a page's languages and hostnames",
63
+ PublicAccess: 'Restrict a page to members',
64
+ CreateBlueprint: 'Make a blueprint from a page',
65
+ PropertyValueRead: "See a page's protected values",
66
+ PropertyValueWrite: "Change a page's protected values",
67
+ RecycleBinRestore: 'Restore pages from the recycle bin',
68
+ }),
69
+ ...area('library', ElementPermissions, {
70
+ Read: 'See Library items',
71
+ Create: 'Create Library items',
72
+ Update: 'Change Library items',
73
+ Delete: 'Delete Library items',
74
+ Move: 'Move Library items',
75
+ Duplicate: 'Copy Library items',
76
+ Publish: 'Publish Library items',
77
+ Unpublish: 'Unpublish Library items',
78
+ Rollback: "Put back a Library item's earlier version",
79
+ }),
80
+ ...area('library-folders', ElementContainerPermissions, {
81
+ Read: 'See Library folders',
82
+ Create: 'Create Library folders',
83
+ Update: 'Rename Library folders',
84
+ Delete: 'Delete Library folders',
85
+ Move: 'Move Library folders',
86
+ }),
87
+ ...area('media', MediaPermissions, { Read: 'See media', Update: 'Change media' }),
88
+ ...area('forms', formDesign, { View: 'See forms', Manage: 'Design forms' }),
89
+ ...area(
90
+ 'form-entries',
91
+ { EntriesView, EntriesManage, EntriesSensitive },
92
+ {
93
+ EntriesView: 'Read form entries',
94
+ EntriesManage: 'Change and delete form entries',
95
+ EntriesSensitive: 'See the answers a form marks sensitive',
96
+ },
97
+ 'Entries',
98
+ ),
99
+ ...area('remote', RemotePermissions, {
100
+ Pull: "Pull a site's content",
101
+ PullFull: 'Pull a whole site, with its members and users',
102
+ Push: 'Push a site',
103
+ PushProtected: 'Push to a protected environment',
104
+ ApplyStructure: "Change a site's definitions, views, styles or code from a bundle or push",
105
+ InstallCode: 'Install the code a bundle carries',
106
+ }),
107
+ ]
108
+
109
+ export type PermissionLookup =
110
+ | { ok: true; verb: string }
111
+ | { ok: false; reason: string; candidates: readonly string[] }
112
+
113
+ /** The stored verb a plain name or a verb names; a bare action is refused with the names it could mean. */
114
+ export function permissionVerb(given: string): PermissionLookup {
115
+ const wanted = given.trim().toLowerCase()
116
+ const found = PERMISSION_NAMES.find((p) => p.name === wanted || p.verb.toLowerCase() === wanted)
117
+ if (found) return { ok: true, verb: found.verb }
118
+ const sameAction = PERMISSION_NAMES.filter((p) => p.name.endsWith(`:${wanted}`))
119
+ if (sameAction.length > 0)
120
+ return {
121
+ ok: false,
122
+ reason: `"${given}" needs its area: ${sameAction.map((p) => p.name).join(', ')}`,
123
+ candidates: sameAction.map((p) => p.name),
124
+ }
125
+ return {
126
+ ok: false,
127
+ reason: `"${given}" is not a permission. \`crombolo users groups permissions\` lists them`,
128
+ candidates: PERMISSION_NAMES.map((p) => p.name),
129
+ }
130
+ }
131
+
132
+ /** A stored verb's plain name, or the verb itself when it has none. */
133
+ export const permissionName = (verb: string): string =>
134
+ PERMISSION_NAMES.find((p) => p.verb === verb)?.name ?? verb
135
+
136
+ export const SECTION_NAMES: ReadonlyArray<{ name: keyof typeof SECTION_ALIASES; says: string }> = [
137
+ { name: 'content', says: 'The pages of the site' },
138
+ { name: 'media', says: 'Images, documents and other files' },
139
+ { name: 'library', says: 'Items kept once and used on many pages' },
140
+ { name: 'forms', says: 'Forms and their entries' },
141
+ { name: 'members', says: 'The people who sign in to the site' },
142
+ { name: 'users', says: 'The people who work in the back office, and their groups' },
143
+ { name: 'translation', says: 'Dictionary items: words the site shows in each language' },
144
+ { name: 'workflow', says: 'Approvals: pages waiting for someone to approve them' },
145
+ { name: 'settings', says: 'Types, templates, languages, bundles and the rest of the setup' },
146
+ ]
147
+
148
+ /** An event's plain name from its display name: "Content Published" is `content-published`. */
149
+ export const eventName = (displayName: string): string =>
150
+ displayName
151
+ .toLowerCase()
152
+ .replace(/[^a-z0-9]+/g, '-')
153
+ .replace(/^-|-$/g, '')