@crombolo/core 0.43.1 → 0.44.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 +2 -2
- package/src/content-types.ts +2 -0
- package/src/form-library.ts +130 -0
- package/src/form-submissions.ts +12 -0
- package/src/forms.ts +15 -0
- package/src/index.ts +1 -0
- package/src/permissions.ts +2 -0
- package/src/sections.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.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.
|
|
31
|
+
"@crombolo/common": "0.44.0"
|
|
32
32
|
}
|
|
33
33
|
}
|
package/src/content-types.ts
CHANGED
|
@@ -103,6 +103,8 @@ export interface ContentTypeAggregate {
|
|
|
103
103
|
siteSearch?: boolean
|
|
104
104
|
/** A site's settings (story 058). Absent means unchanged on a save. */
|
|
105
105
|
siteSettings?: boolean
|
|
106
|
+
/** The form a Library form type is made from (story 239); null for every other type. Absent means unchanged on a save. */
|
|
107
|
+
formKey?: string | null
|
|
106
108
|
}
|
|
107
109
|
|
|
108
110
|
/**
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Forms in the Library (story 239). A developer's form, from its TOML, gives
|
|
3
|
+
* the Library one element type; an editor's element of that type is a Library
|
|
4
|
+
* form, whose words are laid over the form's when a page shows it.
|
|
5
|
+
*/
|
|
6
|
+
import type { SchemaForm } from './forms.ts'
|
|
7
|
+
import { derivedKey } from './keys.ts'
|
|
8
|
+
|
|
9
|
+
/** The properties of every type made from a form, by alias. */
|
|
10
|
+
export const LIBRARY_FORM_PROPERTY = {
|
|
11
|
+
heading: 'heading',
|
|
12
|
+
introduction: 'introduction',
|
|
13
|
+
submitLabel: 'submitLabel',
|
|
14
|
+
messageOnSubmit: 'messageOnSubmit',
|
|
15
|
+
redirectTo: 'redirectTo',
|
|
16
|
+
recipients: 'recipients',
|
|
17
|
+
} as const
|
|
18
|
+
|
|
19
|
+
export interface LibraryFormPropertyDefinition {
|
|
20
|
+
alias: string
|
|
21
|
+
name: string
|
|
22
|
+
description: string
|
|
23
|
+
/** A built-in data type's alias. */
|
|
24
|
+
dataType: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const LIBRARY_FORM_PROPERTIES: readonly LibraryFormPropertyDefinition[] = [
|
|
28
|
+
{
|
|
29
|
+
alias: LIBRARY_FORM_PROPERTY.heading,
|
|
30
|
+
name: 'Heading',
|
|
31
|
+
description: 'Shown above the form.',
|
|
32
|
+
dataType: 'textstring',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
alias: LIBRARY_FORM_PROPERTY.introduction,
|
|
36
|
+
name: 'Introduction',
|
|
37
|
+
description: 'Shown under the heading, before the first field.',
|
|
38
|
+
dataType: 'richtext',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
alias: LIBRARY_FORM_PROPERTY.submitLabel,
|
|
42
|
+
name: 'Submit button',
|
|
43
|
+
description: "The button's text. Leave empty for the form's own.",
|
|
44
|
+
dataType: 'textstring',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
alias: LIBRARY_FORM_PROPERTY.messageOnSubmit,
|
|
48
|
+
name: 'Thank-you message',
|
|
49
|
+
description: "Shown once the form is sent. Leave empty for the form's own.",
|
|
50
|
+
dataType: 'textarea',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
alias: LIBRARY_FORM_PROPERTY.redirectTo,
|
|
54
|
+
name: 'Page to go to after sending',
|
|
55
|
+
description: 'Shown in place of the thank-you message.',
|
|
56
|
+
dataType: 'contentPicker',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
alias: LIBRARY_FORM_PROPERTY.recipients,
|
|
60
|
+
name: 'E-mail entries to',
|
|
61
|
+
description:
|
|
62
|
+
"Addresses to tell about each entry, separated by commas. Leave empty for the form's own.",
|
|
63
|
+
dataType: 'textstring',
|
|
64
|
+
},
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
/** What identifies a form to its Library type: its key, or its alias when it has none. */
|
|
68
|
+
export const libraryFormId = (form: Pick<SchemaForm, 'key' | 'alias'>): string =>
|
|
69
|
+
form.key ?? form.alias
|
|
70
|
+
|
|
71
|
+
/** The key of the element type made from a form; stable for as long as the form's id is. */
|
|
72
|
+
export const libraryFormTypeKey = (formId: string): string => derivedKey('form-type', formId)
|
|
73
|
+
|
|
74
|
+
/** The alias of the element type made from a form: `contactUs` gives `contactUsForm`. */
|
|
75
|
+
export const libraryFormTypeAlias = (form: Pick<SchemaForm, 'alias'>): string => `${form.alias}Form`
|
|
76
|
+
|
|
77
|
+
/** A property's key on the type made from a form. */
|
|
78
|
+
export const libraryFormPropertyKey = (typeKey: string, alias: string): string =>
|
|
79
|
+
derivedKey(typeKey, alias)
|
|
80
|
+
|
|
81
|
+
/** The words on a Library form, as its element's values give them. */
|
|
82
|
+
export interface LibraryFormValues {
|
|
83
|
+
heading?: string
|
|
84
|
+
introduction?: string
|
|
85
|
+
submitLabel?: string
|
|
86
|
+
messageOnSubmit?: string
|
|
87
|
+
/** A document key. */
|
|
88
|
+
redirectTo?: string
|
|
89
|
+
recipients?: string
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Addresses from the recipients field: separated by commas, semicolons or new lines. */
|
|
93
|
+
export function libraryFormRecipients(text: string | undefined): string[] {
|
|
94
|
+
return (text ?? '')
|
|
95
|
+
.split(/[,;\n]/)
|
|
96
|
+
.map((address) => address.trim())
|
|
97
|
+
.filter(Boolean)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const filled = (value: string | undefined): string | undefined =>
|
|
101
|
+
value && value.trim() !== '' ? value : undefined
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The form as a Library form shows it: each of the editor's words that is not
|
|
105
|
+
* empty replaces the form's own, and the rest are the form's. Pure.
|
|
106
|
+
*/
|
|
107
|
+
export function applyLibraryForm(
|
|
108
|
+
form: SchemaForm,
|
|
109
|
+
key: string,
|
|
110
|
+
values: LibraryFormValues,
|
|
111
|
+
): SchemaForm {
|
|
112
|
+
const submitLabel = filled(values.submitLabel)
|
|
113
|
+
const messageOnSubmit = filled(values.messageOnSubmit)
|
|
114
|
+
const redirectTo = filled(values.redirectTo)
|
|
115
|
+
const heading = filled(values.heading)
|
|
116
|
+
const introduction = filled(values.introduction)
|
|
117
|
+
const recipients = libraryFormRecipients(values.recipients)
|
|
118
|
+
return {
|
|
119
|
+
...form,
|
|
120
|
+
...(submitLabel ? { submitLabel } : {}),
|
|
121
|
+
...(messageOnSubmit ? { messageOnSubmit } : {}),
|
|
122
|
+
...(redirectTo ? { redirectTo } : {}),
|
|
123
|
+
library: {
|
|
124
|
+
key,
|
|
125
|
+
...(heading ? { heading } : {}),
|
|
126
|
+
...(introduction ? { introduction } : {}),
|
|
127
|
+
...(recipients.length > 0 ? { recipients } : {}),
|
|
128
|
+
},
|
|
129
|
+
}
|
|
130
|
+
}
|
package/src/form-submissions.ts
CHANGED
|
@@ -59,14 +59,24 @@ export const FORM_HONEYPOT_FIELD = `${FORM_FIELD_PREFIX}_hp`
|
|
|
59
59
|
/** When the form was rendered, so an instant submission can be spotted. */
|
|
60
60
|
export const FORM_RENDERED_FIELD = `${FORM_FIELD_PREFIX}_at`
|
|
61
61
|
export const FORM_PAGE_FIELD = `${FORM_FIELD_PREFIX}_page`
|
|
62
|
+
/** The Library form it was shown through (story 239), signed into the token. */
|
|
63
|
+
export const FORM_LIBRARY_FIELD = `${FORM_FIELD_PREFIX}_library`
|
|
62
64
|
|
|
63
65
|
export const FORM_RESERVED_FIELDS: readonly string[] = [
|
|
64
66
|
FORM_TOKEN_FIELD,
|
|
65
67
|
FORM_HONEYPOT_FIELD,
|
|
66
68
|
FORM_RENDERED_FIELD,
|
|
67
69
|
FORM_PAGE_FIELD,
|
|
70
|
+
FORM_LIBRARY_FIELD,
|
|
68
71
|
]
|
|
69
72
|
|
|
73
|
+
/**
|
|
74
|
+
* What a form's token is signed over: its key, and the Library form it is
|
|
75
|
+
* shown through, so a submission cannot claim another Library form's words.
|
|
76
|
+
*/
|
|
77
|
+
export const formTokenSubject = (formKey: string, libraryKey?: string): string =>
|
|
78
|
+
libraryKey ? `${formKey}#${libraryKey}` : formKey
|
|
79
|
+
|
|
70
80
|
/**
|
|
71
81
|
* What a page knows about a submission that just happened.
|
|
72
82
|
*
|
|
@@ -76,6 +86,8 @@ export const FORM_RESERVED_FIELDS: readonly string[] = [
|
|
|
76
86
|
*/
|
|
77
87
|
export interface FormSubmissionState {
|
|
78
88
|
formKey: string
|
|
89
|
+
/** The Library form it came through, which tells two of one form apart on a page. */
|
|
90
|
+
libraryKey?: string
|
|
79
91
|
formAlias: string
|
|
80
92
|
values: SubmittedValues
|
|
81
93
|
errors: FormFieldError[]
|
package/src/forms.ts
CHANGED
|
@@ -575,6 +575,21 @@ export interface SchemaForm {
|
|
|
575
575
|
since?: string
|
|
576
576
|
pages: SchemaFormPage[]
|
|
577
577
|
workflows: SchemaFormWorkflow[]
|
|
578
|
+
/**
|
|
579
|
+
* Set when the form is shown through a Library form (story 239): which one,
|
|
580
|
+
* and the editor's words that have no TOML counterpart. Never in a file.
|
|
581
|
+
*/
|
|
582
|
+
library?: LibraryFormWords
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/** A Library form's own words, laid over its form's. */
|
|
586
|
+
export interface LibraryFormWords {
|
|
587
|
+
key: string
|
|
588
|
+
heading?: string
|
|
589
|
+
/** Rich text, as HTML. */
|
|
590
|
+
introduction?: string
|
|
591
|
+
/** Replaces the `to` of the form's send-e-mail workflows. */
|
|
592
|
+
recipients?: string[]
|
|
578
593
|
}
|
|
579
594
|
|
|
580
595
|
/** Every field in a form, in the order a visitor meets them. */
|
package/src/index.ts
CHANGED
package/src/permissions.ts
CHANGED
|
@@ -64,6 +64,8 @@ export const RemotePermissions = {
|
|
|
64
64
|
PullFull: 'Crombolo.Remote.PullFull',
|
|
65
65
|
Push: 'Crombolo.Remote.Push',
|
|
66
66
|
PushProtected: 'Crombolo.Remote.PushProtected',
|
|
67
|
+
/** Changing a remote's schema, views, styles or code: a whole-site push, or such a bundle (story 167). */
|
|
68
|
+
ApplyStructure: 'Crombolo.Remote.ApplyStructure',
|
|
67
69
|
} as const
|
|
68
70
|
export type RemoteVerb = (typeof RemotePermissions)[keyof typeof RemotePermissions]
|
|
69
71
|
|
package/src/sections.ts
CHANGED
|
@@ -20,7 +20,7 @@ export const SECTION_ALIASES = {
|
|
|
20
20
|
members: 'Umb.Section.Members',
|
|
21
21
|
translation: 'Umb.Section.Translation',
|
|
22
22
|
library: 'Umb.Section.Library',
|
|
23
|
-
packages
|
|
23
|
+
// No `packages`: Bundles is a Settings tool, for whoever has Settings (story 238).
|
|
24
24
|
// Umbraco seeds this alias and then has no section for it: Forms is a
|
|
25
25
|
// commercial add-on there. Form building is in core here, so the section is
|
|
26
26
|
// real and the alias resolves (`docs/forms.md`).
|