@crombolo/schema 0.61.0 → 0.63.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 +3 -3
- package/src/user-groups.ts +26 -4
- package/src/validate-forms.ts +32 -1
- package/src/write-forms.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/schema",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.63.0",
|
|
4
4
|
"description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. Schema-as-code for crombolo: TOML document, media and member type definitions.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@crombolo/core": "0.
|
|
32
|
-
"@crombolo/data": "0.
|
|
31
|
+
"@crombolo/core": "0.63.0",
|
|
32
|
+
"@crombolo/data": "0.63.0"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/user-groups.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `schema/user-groups/*.toml` — user groups a site declares (story 228): what a
|
|
3
|
-
* group is (its name, sections, permission verbs and
|
|
4
|
-
* starts or who is in it, which each environment's Users section keeps. Strict
|
|
3
|
+
* group is (its name, sections, permission verbs, languages and owners), never
|
|
4
|
+
* where it starts or who is in it, which each environment's Users section keeps. Strict
|
|
5
5
|
* as the type parser is, and canonical on the way out, so
|
|
6
6
|
* `parseUserGroup(writeUserGroup(x))` equals `x`. `docs/schema-as-code.md`.
|
|
7
7
|
*/
|
|
8
8
|
import {
|
|
9
9
|
ADMIN_GROUP_ALIAS,
|
|
10
10
|
isExtensionSectionAlias,
|
|
11
|
+
isRemotePermission,
|
|
11
12
|
KNOWN_PERMISSIONS,
|
|
12
13
|
RETIRED_SECTIONS,
|
|
13
14
|
SECTION_ALIASES,
|
|
15
|
+
withoutPrunedPermissions,
|
|
14
16
|
} from '@crombolo/core'
|
|
15
17
|
import { type ParseResult, Reader, toml } from './reader.ts'
|
|
16
18
|
|
|
@@ -24,9 +26,20 @@ export interface SchemaUserGroup {
|
|
|
24
26
|
permissions: string[]
|
|
25
27
|
/** ISO codes, or every language. */
|
|
26
28
|
languages: string[] | 'all'
|
|
29
|
+
/** The aliases of the groups whose members choose who is in it (story 302). */
|
|
30
|
+
owners?: string[]
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
const KEYS = [
|
|
33
|
+
const KEYS = [
|
|
34
|
+
'alias',
|
|
35
|
+
'name',
|
|
36
|
+
'description',
|
|
37
|
+
'icon',
|
|
38
|
+
'sections',
|
|
39
|
+
'permissions',
|
|
40
|
+
'languages',
|
|
41
|
+
'owners',
|
|
42
|
+
]
|
|
30
43
|
|
|
31
44
|
export function parseUserGroup(file: string, source: string): ParseResult<SchemaUserGroup> {
|
|
32
45
|
const r = new Reader(file)
|
|
@@ -55,7 +68,8 @@ export function parseUserGroup(file: string, source: string): ParseResult<Schema
|
|
|
55
68
|
`${path}.sections`,
|
|
56
69
|
`"${section}" is not a section: one of ${Object.keys(SECTION_ALIASES).join(', ')}, or an extension's section alias`,
|
|
57
70
|
)
|
|
58
|
-
|
|
71
|
+
// A verb story 338 took out is read as what replaced it, so a file written before still loads.
|
|
72
|
+
const permissions = withoutPrunedPermissions(r.strs(t, 'permissions', path))
|
|
59
73
|
for (const permission of permissions)
|
|
60
74
|
if (!KNOWN_PERMISSIONS.has(permission))
|
|
61
75
|
r.problem(
|
|
@@ -65,6 +79,12 @@ export function parseUserGroup(file: string, source: string): ParseResult<Schema
|
|
|
65
79
|
let languages: string[] | 'all' = []
|
|
66
80
|
if (t.languages === 'all') languages = 'all'
|
|
67
81
|
else if (t.languages !== undefined) languages = r.strs(t, 'languages', path)
|
|
82
|
+
const owners = t.owners === undefined ? undefined : r.strs(t, 'owners', path)
|
|
83
|
+
if (owners?.length && permissions.some(isRemotePermission))
|
|
84
|
+
r.problem(
|
|
85
|
+
`${path}.owners`,
|
|
86
|
+
"a group that can move sites or install code is only an administrator's to fill, so it cannot have owners",
|
|
87
|
+
)
|
|
68
88
|
const description = r.str(t, 'description', path)
|
|
69
89
|
const icon = r.str(t, 'icon', path)
|
|
70
90
|
const value: SchemaUserGroup = {
|
|
@@ -75,6 +95,7 @@ export function parseUserGroup(file: string, source: string): ParseResult<Schema
|
|
|
75
95
|
sections,
|
|
76
96
|
permissions,
|
|
77
97
|
languages,
|
|
98
|
+
...(owners !== undefined ? { owners } : {}),
|
|
78
99
|
}
|
|
79
100
|
return { value: r.problems.length === 0 ? value : undefined, problems: r.problems }
|
|
80
101
|
}
|
|
@@ -91,5 +112,6 @@ export function writeUserGroup(group: SchemaUserGroup): string {
|
|
|
91
112
|
`permissions = ${list(group.permissions)}`,
|
|
92
113
|
`languages = ${group.languages === 'all' ? '"all"' : list(group.languages)}`,
|
|
93
114
|
)
|
|
115
|
+
if (group.owners !== undefined) out.push(`owners = ${list(group.owners)}`)
|
|
94
116
|
return `${out.join('\n')}\n`
|
|
95
117
|
}
|
package/src/validate-forms.ts
CHANGED
|
@@ -20,6 +20,16 @@ import {
|
|
|
20
20
|
} from '@crombolo/core'
|
|
21
21
|
import type { SchemaProblem } from './model.ts'
|
|
22
22
|
|
|
23
|
+
/** An absolute http or https URL (story 304): no other scheme is sent to. */
|
|
24
|
+
const isWebAddress = (url: string): boolean => {
|
|
25
|
+
try {
|
|
26
|
+
const parsed = new URL(url)
|
|
27
|
+
return parsed.protocol === 'http:' || parsed.protocol === 'https:'
|
|
28
|
+
} catch {
|
|
29
|
+
return false
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
23
33
|
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
|
|
24
34
|
|
|
25
35
|
const VERSION = /^\d+(\.\d+)*$/
|
|
@@ -373,8 +383,29 @@ function validateWorkflows(
|
|
|
373
383
|
|
|
374
384
|
if (workflow.type === 'sendToUrl') {
|
|
375
385
|
const url = workflow.settings.url
|
|
376
|
-
if (typeof url === 'string' &&
|
|
386
|
+
if (typeof url === 'string' && !isWebAddress(url))
|
|
377
387
|
add(file, `${path}.settings.url`, 'must be an http or https URL')
|
|
388
|
+
const headers = workflow.settings.headers
|
|
389
|
+
if (headers !== undefined) {
|
|
390
|
+
if (!headers || typeof headers !== 'object' || Array.isArray(headers))
|
|
391
|
+
add(file, `${path}.settings.headers`, 'expected a table of header names')
|
|
392
|
+
else
|
|
393
|
+
for (const [name, value] of Object.entries(headers))
|
|
394
|
+
if (
|
|
395
|
+
typeof value !== 'string' &&
|
|
396
|
+
!(
|
|
397
|
+
value &&
|
|
398
|
+
typeof value === 'object' &&
|
|
399
|
+
Object.keys(value).length === 1 &&
|
|
400
|
+
(value as { secret?: unknown }).secret === true
|
|
401
|
+
)
|
|
402
|
+
)
|
|
403
|
+
add(
|
|
404
|
+
file,
|
|
405
|
+
`${path}.settings.headers.${name}`,
|
|
406
|
+
'expected the value as text, or { secret = true } for one kept sealed on the site',
|
|
407
|
+
)
|
|
408
|
+
}
|
|
378
409
|
const method = workflow.settings.method
|
|
379
410
|
if (method !== undefined && method !== 'POST' && method !== 'PUT')
|
|
380
411
|
add(file, `${path}.settings.method`, "expected 'POST' or 'PUT'")
|
package/src/write-forms.ts
CHANGED
|
@@ -23,7 +23,9 @@ function scalar(value: unknown): string {
|
|
|
23
23
|
if (typeof value === 'number' || typeof value === 'boolean') return String(value)
|
|
24
24
|
if (Array.isArray(value)) return `[${value.map(scalar).join(', ')}]`
|
|
25
25
|
if (value === null || value === undefined) return '""'
|
|
26
|
-
|
|
26
|
+
// A table, such as a send-to-URL workflow's headers, as an inline table.
|
|
27
|
+
const entries = Object.entries(value as Record<string, unknown>)
|
|
28
|
+
return `{ ${entries.map(([key, inner]) => `${keyOf(key)} = ${scalar(inner)}`).join(', ')} }`
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
/** Workflow settings arrive from the API, so a key may need quoting. */
|