@meith/install 0.16.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/LICENSE.md +165 -0
- package/package.json +25 -0
- package/src/form.ts +252 -0
- package/src/index.ts +36 -0
- package/src/plan.ts +64 -0
- package/src/preflight.ts +168 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@meith/install",
|
|
3
|
+
"version": "0.16.0",
|
|
4
|
+
"license": "LGPL-3.0-or-later",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/meith-dev/meith.git",
|
|
8
|
+
"directory": "packages/install"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./src/index.ts",
|
|
12
|
+
"types": "./src/index.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"src",
|
|
15
|
+
"!src/**/*.test.*",
|
|
16
|
+
"!src/**/*.type-test.*"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"zod": "^4.4.3",
|
|
23
|
+
"@meith/settings": "0.16.0"
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/form.ts
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
defaultPort,
|
|
5
|
+
isUsableOrigin,
|
|
6
|
+
MAIL_PRESET_BY_ID,
|
|
7
|
+
type MailConfig,
|
|
8
|
+
type MailSecurity,
|
|
9
|
+
mailConfigProblems,
|
|
10
|
+
normaliseOrigin,
|
|
11
|
+
} from '@meith/settings'
|
|
12
|
+
|
|
13
|
+
export const MAIL_SKIP = 'skip'
|
|
14
|
+
|
|
15
|
+
const mailFields = {
|
|
16
|
+
mailPreset: z.string().trim().default(MAIL_SKIP),
|
|
17
|
+
mailFrom: z.string().trim().default(''),
|
|
18
|
+
mailHost: z.string().trim().default(''),
|
|
19
|
+
mailPort: z.string().trim().default(''),
|
|
20
|
+
mailSecurity: z.preprocess(
|
|
21
|
+
(value) => (value === '' ? undefined : value),
|
|
22
|
+
z.enum(['tls', 'starttls', 'none']).optional(),
|
|
23
|
+
),
|
|
24
|
+
mailUsername: z.string().trim().default(''),
|
|
25
|
+
mailSecret: z.string().trim().default(''),
|
|
26
|
+
mailEndpoint: z.string().trim().default(''),
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const installInputObject = z.object({
|
|
30
|
+
boardName: z
|
|
31
|
+
.string()
|
|
32
|
+
.trim()
|
|
33
|
+
.min(1, 'install.validation.boardNameRequired')
|
|
34
|
+
.max(100, 'install.validation.nameTooLong'),
|
|
35
|
+
username: z
|
|
36
|
+
.string()
|
|
37
|
+
.trim()
|
|
38
|
+
.min(3, 'install.validation.usernameMin')
|
|
39
|
+
.max(30, 'install.validation.nameTooLong'),
|
|
40
|
+
email: z.string().trim().email('install.validation.email'),
|
|
41
|
+
boardUrl: z
|
|
42
|
+
.string()
|
|
43
|
+
.trim()
|
|
44
|
+
.min(1, 'install.validation.boardUrlRequired')
|
|
45
|
+
.refine(isUsableOrigin, 'install.validation.boardUrl')
|
|
46
|
+
.transform(normaliseOrigin),
|
|
47
|
+
password: z
|
|
48
|
+
.string()
|
|
49
|
+
.min(12, 'install.validation.passwordMin')
|
|
50
|
+
.max(200, 'install.validation.passwordTooLong'),
|
|
51
|
+
...mailFields,
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
export const installInputSchema = installInputObject.superRefine((value, ctx) => {
|
|
55
|
+
if (value.mailPreset === MAIL_SKIP) return
|
|
56
|
+
|
|
57
|
+
const preset = MAIL_PRESET_BY_ID.get(value.mailPreset)
|
|
58
|
+
if (preset === undefined) {
|
|
59
|
+
ctx.addIssue({
|
|
60
|
+
code: z.ZodIssueCode.custom,
|
|
61
|
+
path: ['mailPreset'],
|
|
62
|
+
message: 'install.validation.mailPreset',
|
|
63
|
+
})
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (value.mailFrom === '') {
|
|
68
|
+
ctx.addIssue({
|
|
69
|
+
code: z.ZodIssueCode.custom,
|
|
70
|
+
path: ['mailFrom'],
|
|
71
|
+
message: 'install.validation.mailFromRequired',
|
|
72
|
+
})
|
|
73
|
+
} else if (!z.string().email().safeParse(value.mailFrom).success) {
|
|
74
|
+
ctx.addIssue({
|
|
75
|
+
code: z.ZodIssueCode.custom,
|
|
76
|
+
path: ['mailFrom'],
|
|
77
|
+
message: 'install.validation.email',
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (preset.transport === 'http') {
|
|
82
|
+
const endpoint = value.mailEndpoint === '' ? (preset.endpoint ?? '') : value.mailEndpoint
|
|
83
|
+
if (endpoint === '') {
|
|
84
|
+
ctx.addIssue({
|
|
85
|
+
code: z.ZodIssueCode.custom,
|
|
86
|
+
path: ['mailEndpoint'],
|
|
87
|
+
message: 'install.validation.mailEndpointRequired',
|
|
88
|
+
})
|
|
89
|
+
} else if (!z.string().url().safeParse(endpoint).success) {
|
|
90
|
+
ctx.addIssue({
|
|
91
|
+
code: z.ZodIssueCode.custom,
|
|
92
|
+
path: ['mailEndpoint'],
|
|
93
|
+
message: 'install.validation.url',
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
if (value.mailSecret === '') {
|
|
97
|
+
ctx.addIssue({
|
|
98
|
+
code: z.ZodIssueCode.custom,
|
|
99
|
+
path: ['mailSecret'],
|
|
100
|
+
message: 'install.validation.mailSecretRequired',
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (value.mailHost === '' && (preset.host ?? '') === '') {
|
|
107
|
+
ctx.addIssue({
|
|
108
|
+
code: z.ZodIssueCode.custom,
|
|
109
|
+
path: ['mailHost'],
|
|
110
|
+
message: 'install.validation.mailHostRequired',
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (value.mailPort !== '') {
|
|
115
|
+
const port = Number(value.mailPort)
|
|
116
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
117
|
+
ctx.addIssue({
|
|
118
|
+
code: z.ZodIssueCode.custom,
|
|
119
|
+
path: ['mailPort'],
|
|
120
|
+
message: 'install.validation.mailPort',
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const username = value.mailUsername === '' ? (preset.username ?? '') : value.mailUsername
|
|
126
|
+
if (username !== '' && value.mailSecret === '') {
|
|
127
|
+
ctx.addIssue({
|
|
128
|
+
code: z.ZodIssueCode.custom,
|
|
129
|
+
path: ['mailSecret'],
|
|
130
|
+
message: 'install.validation.mailPasswordRequired',
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
if (username === '' && value.mailSecret !== '') {
|
|
134
|
+
ctx.addIssue({
|
|
135
|
+
code: z.ZodIssueCode.custom,
|
|
136
|
+
path: ['mailUsername'],
|
|
137
|
+
message: 'install.validation.mailUsernameRequired',
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
export type InstallInput = z.infer<typeof installInputSchema>
|
|
143
|
+
|
|
144
|
+
export const INSTALL_FIELDS: readonly string[] = Object.keys(installInputObject.shape)
|
|
145
|
+
|
|
146
|
+
export const SECRET_FIELDS: readonly string[] = ['password', 'mailSecret']
|
|
147
|
+
|
|
148
|
+
export const ECHOED_FIELDS: readonly string[] = INSTALL_FIELDS.filter(
|
|
149
|
+
(name) => !SECRET_FIELDS.includes(name),
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
export interface FormLike {
|
|
153
|
+
get(name: string): unknown
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function installInputFromForm(form: FormLike): Record<string, string> {
|
|
157
|
+
return Object.fromEntries(
|
|
158
|
+
INSTALL_FIELDS.map((name) => {
|
|
159
|
+
const value = form.get(name)
|
|
160
|
+
return [name, typeof value === 'string' ? value : '']
|
|
161
|
+
}),
|
|
162
|
+
)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export interface EnvironmentAnswers {
|
|
166
|
+
readonly boardUrl: string | null
|
|
167
|
+
readonly mailIsFromEnvironment: boolean
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function withEnvironmentAnswers(
|
|
171
|
+
raw: Record<string, string>,
|
|
172
|
+
environment: EnvironmentAnswers,
|
|
173
|
+
): Record<string, string> {
|
|
174
|
+
const answered = { ...raw }
|
|
175
|
+
|
|
176
|
+
if (environment.boardUrl !== null && environment.boardUrl !== '') {
|
|
177
|
+
answered.boardUrl = environment.boardUrl
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (environment.mailIsFromEnvironment) {
|
|
181
|
+
answered.mailPreset = MAIL_SKIP
|
|
182
|
+
for (const name of INSTALL_FIELDS) {
|
|
183
|
+
if (name.startsWith('mail') && name !== 'mailPreset') answered[name] = ''
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return answered
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function mailConfigFromInstallInput(input: InstallInput): MailConfig {
|
|
191
|
+
if (input.mailPreset === MAIL_SKIP) return { transport: 'log' }
|
|
192
|
+
|
|
193
|
+
const preset = MAIL_PRESET_BY_ID.get(input.mailPreset)
|
|
194
|
+
if (preset === undefined) return { transport: 'log' }
|
|
195
|
+
|
|
196
|
+
if (preset.transport === 'http') {
|
|
197
|
+
return {
|
|
198
|
+
transport: 'http',
|
|
199
|
+
from: input.mailFrom,
|
|
200
|
+
endpoint: input.mailEndpoint === '' ? (preset.endpoint ?? '') : input.mailEndpoint,
|
|
201
|
+
token: input.mailSecret,
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const security: MailSecurity = input.mailSecurity ?? preset.security ?? 'starttls'
|
|
206
|
+
|
|
207
|
+
return {
|
|
208
|
+
transport: 'smtp',
|
|
209
|
+
from: input.mailFrom,
|
|
210
|
+
host: input.mailHost === '' ? (preset.host ?? '') : input.mailHost,
|
|
211
|
+
port:
|
|
212
|
+
input.mailPort === ''
|
|
213
|
+
? preset.security === security && preset.port !== undefined
|
|
214
|
+
? preset.port
|
|
215
|
+
: defaultPort(security)
|
|
216
|
+
: Number(input.mailPort),
|
|
217
|
+
security,
|
|
218
|
+
username: input.mailUsername === '' ? (preset.username ?? '') : input.mailUsername,
|
|
219
|
+
password: input.mailSecret,
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export function parseInstallInput(
|
|
224
|
+
raw: Record<string, unknown>,
|
|
225
|
+
): { ok: true; value: InstallInput } | { ok: false; errors: Record<string, string> } {
|
|
226
|
+
const parsed = installInputSchema.safeParse(raw)
|
|
227
|
+
if (parsed.success) {
|
|
228
|
+
const problems = mailConfigProblems(mailConfigFromInstallInput(parsed.data))
|
|
229
|
+
if (problems.length > 0) {
|
|
230
|
+
return { ok: false, errors: { mailPreset: 'install.validation.mailConfiguration' } }
|
|
231
|
+
}
|
|
232
|
+
return { ok: true, value: parsed.data }
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const errors: Record<string, string> = {}
|
|
236
|
+
for (const issue of parsed.error.issues) {
|
|
237
|
+
const key = String(issue.path[0] ?? 'form')
|
|
238
|
+
errors[key] ??= issue.message
|
|
239
|
+
}
|
|
240
|
+
return { ok: false, errors }
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export function defaultForumSlug(boardName: string): string {
|
|
244
|
+
const slug = boardName
|
|
245
|
+
.toLowerCase()
|
|
246
|
+
.normalize('NFKD')
|
|
247
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
248
|
+
.replace(/^-+|-+$/g, '')
|
|
249
|
+
.slice(0, 40)
|
|
250
|
+
|
|
251
|
+
return slug === '' ? 'general' : slug
|
|
252
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export {
|
|
2
|
+
defaultForumSlug,
|
|
3
|
+
ECHOED_FIELDS,
|
|
4
|
+
type EnvironmentAnswers,
|
|
5
|
+
type FormLike,
|
|
6
|
+
INSTALL_FIELDS,
|
|
7
|
+
type InstallInput,
|
|
8
|
+
installInputFromForm,
|
|
9
|
+
installInputSchema,
|
|
10
|
+
MAIL_SKIP,
|
|
11
|
+
mailConfigFromInstallInput,
|
|
12
|
+
parseInstallInput,
|
|
13
|
+
SECRET_FIELDS,
|
|
14
|
+
withEnvironmentAnswers,
|
|
15
|
+
} from './form'
|
|
16
|
+
export {
|
|
17
|
+
fieldErrorsFromReport,
|
|
18
|
+
firstFailure,
|
|
19
|
+
freshReport,
|
|
20
|
+
INSTALL_STEPS,
|
|
21
|
+
type InstallStep,
|
|
22
|
+
installed,
|
|
23
|
+
type StepOutcome,
|
|
24
|
+
type StepStatus,
|
|
25
|
+
stepTitleKey,
|
|
26
|
+
} from './plan'
|
|
27
|
+
export {
|
|
28
|
+
blockers,
|
|
29
|
+
type Check,
|
|
30
|
+
canProceed,
|
|
31
|
+
type Level,
|
|
32
|
+
type MailProbe,
|
|
33
|
+
type PreflightProbe,
|
|
34
|
+
preflight,
|
|
35
|
+
warnings,
|
|
36
|
+
} from './preflight'
|
package/src/plan.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export interface InstallStep {
|
|
2
|
+
readonly id: string
|
|
3
|
+
readonly titleKey: string
|
|
4
|
+
readonly detailKey: string
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const INSTALL_STEPS: readonly InstallStep[] = [
|
|
8
|
+
{
|
|
9
|
+
id: 'migrate',
|
|
10
|
+
titleKey: 'install.step.migrate.title',
|
|
11
|
+
detailKey: 'install.step.migrate.detail',
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
id: 'settings',
|
|
15
|
+
titleKey: 'install.step.settings.title',
|
|
16
|
+
detailKey: 'install.step.settings.detail',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
id: 'admin',
|
|
20
|
+
titleKey: 'install.step.admin.title',
|
|
21
|
+
detailKey: 'install.step.admin.detail',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
id: 'forum',
|
|
25
|
+
titleKey: 'install.step.forum.title',
|
|
26
|
+
detailKey: 'install.step.forum.detail',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: 'seal',
|
|
30
|
+
titleKey: 'install.step.seal.title',
|
|
31
|
+
detailKey: 'install.step.seal.detail',
|
|
32
|
+
},
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
export type StepStatus = 'pending' | 'done' | 'failed'
|
|
36
|
+
|
|
37
|
+
export interface StepOutcome {
|
|
38
|
+
readonly id: string
|
|
39
|
+
readonly status: StepStatus
|
|
40
|
+
readonly error?: string
|
|
41
|
+
readonly field?: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function fieldErrorsFromReport(report: readonly StepOutcome[]): Record<string, string> {
|
|
45
|
+
const failure = firstFailure(report)
|
|
46
|
+
if (failure === null || failure.field === undefined) return {}
|
|
47
|
+
return { [failure.field]: failure.error ?? 'installAction.answerRefused' }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function stepTitleKey(id: string): string {
|
|
51
|
+
return INSTALL_STEPS.find((step) => step.id === id)?.titleKey ?? id
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function freshReport(): readonly StepOutcome[] {
|
|
55
|
+
return INSTALL_STEPS.map((step) => ({ id: step.id, status: 'pending' as const }))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function installed(report: readonly StepOutcome[]): boolean {
|
|
59
|
+
return report.length === INSTALL_STEPS.length && report.every((step) => step.status === 'done')
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function firstFailure(report: readonly StepOutcome[]): StepOutcome | null {
|
|
63
|
+
return report.find((step) => step.status === 'failed') ?? null
|
|
64
|
+
}
|
package/src/preflight.ts
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import type { MailSource } from '@meith/settings'
|
|
2
|
+
|
|
3
|
+
export type Level = 'blocker' | 'warning' | 'ok'
|
|
4
|
+
|
|
5
|
+
export interface MailProbe {
|
|
6
|
+
readonly configured: boolean
|
|
7
|
+
readonly source: MailSource
|
|
8
|
+
readonly summary: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface Check {
|
|
12
|
+
readonly id: string
|
|
13
|
+
readonly level: Level
|
|
14
|
+
readonly titleKey: string
|
|
15
|
+
readonly titleArgs?: Readonly<Record<string, string | number>> | undefined
|
|
16
|
+
readonly detailKey?: string | undefined
|
|
17
|
+
readonly detailArgs?: Readonly<Record<string, string | number>> | undefined
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface PreflightProbe {
|
|
21
|
+
readonly dataSource: 'fixture' | 'postgres'
|
|
22
|
+
readonly databaseUrl: string | null
|
|
23
|
+
readonly hasAuthSecret: boolean
|
|
24
|
+
readonly hasTickSecret: boolean
|
|
25
|
+
readonly publicUrl: string | null
|
|
26
|
+
readonly mail: MailProbe
|
|
27
|
+
readonly canConnect: boolean | null
|
|
28
|
+
readonly pendingMigrations: number | null
|
|
29
|
+
readonly userCount: number | null
|
|
30
|
+
readonly alreadyInstalled: boolean
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function ok(
|
|
34
|
+
id: string,
|
|
35
|
+
titleKey: string,
|
|
36
|
+
titleArgs?: Readonly<Record<string, string | number>>,
|
|
37
|
+
): Check {
|
|
38
|
+
return { id, level: 'ok', titleKey, ...(titleArgs === undefined ? {} : { titleArgs }) }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function preflight(probe: PreflightProbe): readonly Check[] {
|
|
42
|
+
const checks: Check[] = []
|
|
43
|
+
|
|
44
|
+
if (probe.alreadyInstalled) {
|
|
45
|
+
checks.push({
|
|
46
|
+
id: 'already-installed',
|
|
47
|
+
level: 'blocker',
|
|
48
|
+
titleKey: 'installPreflight.alreadyInstalled.title',
|
|
49
|
+
detailKey: 'installPreflight.alreadyInstalled.detail',
|
|
50
|
+
})
|
|
51
|
+
} else if (probe.userCount !== null && probe.userCount > 0) {
|
|
52
|
+
checks.push({
|
|
53
|
+
id: 'has-members',
|
|
54
|
+
level: 'blocker',
|
|
55
|
+
titleKey: 'installPreflight.hasMembers.title',
|
|
56
|
+
detailKey: 'installPreflight.hasMembers.detail',
|
|
57
|
+
detailArgs: { count: probe.userCount },
|
|
58
|
+
})
|
|
59
|
+
} else {
|
|
60
|
+
checks.push(ok('fresh', 'installPreflight.fresh.title'))
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (probe.dataSource !== 'postgres') {
|
|
64
|
+
checks.push({
|
|
65
|
+
id: 'data-source',
|
|
66
|
+
level: 'blocker',
|
|
67
|
+
titleKey: 'installPreflight.dataSource.title',
|
|
68
|
+
detailKey: 'installPreflight.dataSource.detail',
|
|
69
|
+
})
|
|
70
|
+
} else if (probe.databaseUrl === null || probe.databaseUrl === '') {
|
|
71
|
+
checks.push({
|
|
72
|
+
id: 'database-url',
|
|
73
|
+
level: 'blocker',
|
|
74
|
+
titleKey: 'installPreflight.databaseUrl.missingTitle',
|
|
75
|
+
detailKey: 'installPreflight.databaseUrl.missingDetail',
|
|
76
|
+
})
|
|
77
|
+
} else {
|
|
78
|
+
checks.push(ok('database-url', 'installPreflight.databaseUrl.setTitle'))
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (probe.canConnect === false) {
|
|
82
|
+
checks.push({
|
|
83
|
+
id: 'connect',
|
|
84
|
+
level: 'blocker',
|
|
85
|
+
titleKey: 'installPreflight.connect.refusedTitle',
|
|
86
|
+
detailKey: 'installPreflight.connect.refusedDetail',
|
|
87
|
+
})
|
|
88
|
+
} else if (probe.canConnect === true) {
|
|
89
|
+
checks.push(ok('connect', 'installPreflight.connect.acceptedTitle'))
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (probe.pendingMigrations !== null && probe.pendingMigrations > 0) {
|
|
93
|
+
checks.push({
|
|
94
|
+
id: 'migrations',
|
|
95
|
+
level: 'ok',
|
|
96
|
+
titleKey: 'installPreflight.migrations.title',
|
|
97
|
+
titleArgs: { count: probe.pendingMigrations },
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!probe.hasAuthSecret) {
|
|
102
|
+
checks.push({
|
|
103
|
+
id: 'auth-secret',
|
|
104
|
+
level: 'blocker',
|
|
105
|
+
titleKey: 'installPreflight.authSecret.missingTitle',
|
|
106
|
+
detailKey: 'installPreflight.authSecret.missingDetail',
|
|
107
|
+
})
|
|
108
|
+
} else {
|
|
109
|
+
checks.push(ok('auth-secret', 'installPreflight.authSecret.setTitle'))
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!probe.hasTickSecret) {
|
|
113
|
+
checks.push({
|
|
114
|
+
id: 'tick-secret',
|
|
115
|
+
level: 'warning',
|
|
116
|
+
titleKey: 'installPreflight.tickSecret.missingTitle',
|
|
117
|
+
detailKey: 'installPreflight.tickSecret.missingDetail',
|
|
118
|
+
})
|
|
119
|
+
} else {
|
|
120
|
+
checks.push(ok('tick-secret', 'installPreflight.tickSecret.setTitle'))
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (probe.publicUrl !== null && probe.publicUrl !== '') {
|
|
124
|
+
checks.push(ok('public-url', 'installPreflight.publicUrl.setTitle', { url: probe.publicUrl }))
|
|
125
|
+
} else {
|
|
126
|
+
checks.push({
|
|
127
|
+
id: 'public-url',
|
|
128
|
+
level: 'ok',
|
|
129
|
+
titleKey: 'installPreflight.publicUrl.formTitle',
|
|
130
|
+
detailKey: 'installPreflight.publicUrl.formDetail',
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (probe.mail.configured) {
|
|
135
|
+
checks.push(
|
|
136
|
+
ok('mail', 'installPreflight.mail.configuredTitle', { summary: probe.mail.summary }),
|
|
137
|
+
)
|
|
138
|
+
} else if (probe.mail.source === 'environment') {
|
|
139
|
+
checks.push({
|
|
140
|
+
id: 'mail',
|
|
141
|
+
level: 'blocker',
|
|
142
|
+
titleKey: 'installPreflight.mail.incompleteTitle',
|
|
143
|
+
detailKey: 'installPreflight.mail.incompleteDetail',
|
|
144
|
+
detailArgs: { summary: probe.mail.summary },
|
|
145
|
+
})
|
|
146
|
+
} else {
|
|
147
|
+
checks.push({
|
|
148
|
+
id: 'mail',
|
|
149
|
+
level: 'warning',
|
|
150
|
+
titleKey: 'installPreflight.mail.unconfiguredTitle',
|
|
151
|
+
detailKey: 'installPreflight.mail.unconfiguredDetail',
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return checks
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function canProceed(checks: readonly Check[]): boolean {
|
|
159
|
+
return !checks.some((check) => check.level === 'blocker')
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function blockers(checks: readonly Check[]): readonly Check[] {
|
|
163
|
+
return checks.filter((check) => check.level === 'blocker')
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function warnings(checks: readonly Check[]): readonly Check[] {
|
|
167
|
+
return checks.filter((check) => check.level === 'warning')
|
|
168
|
+
}
|