@12-apps/tenant 1.2.0 → 1.4.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/ADOPTING.md +206 -4
- package/README.md +9 -5
- package/package.json +26 -3
- package/src/config.ts +6 -2
- package/src/domains/checks.ts +124 -0
- package/src/domains/dns-names.ts +215 -0
- package/src/domains/engine.ts +309 -0
- package/src/domains/hostname.ts +38 -0
- package/src/domains/index.ts +45 -0
- package/src/domains/plan.ts +273 -0
- package/src/domains/port.ts +105 -0
- package/src/domains/react/card.tsx +216 -0
- package/src/domains/react/context.tsx +102 -0
- package/src/domains/react/copy.ts +151 -0
- package/src/domains/react/index.ts +41 -0
- package/src/domains/react/records.tsx +353 -0
- package/src/domains/react/removed.tsx +133 -0
- package/src/domains/react/row.tsx +335 -0
- package/src/domains/react/screen.ts +92 -0
- package/src/domains/record.ts +141 -0
- package/src/domains/server.ts +70 -0
- package/src/domains/tls.ts +50 -0
- package/src/hono/index.ts +51 -0
- package/src/index.ts +48 -1
- package/src/lifecycle/close.ts +191 -0
- package/src/lifecycle/context.ts +126 -0
- package/src/lifecycle/gates.ts +160 -0
- package/src/lifecycle/index.ts +127 -0
- package/src/lifecycle/pure.ts +56 -0
- package/src/lifecycle/refusal.ts +69 -0
- package/src/lifecycle/sweep.ts +139 -0
- package/src/lifecycle/types.ts +255 -0
- package/src/lifecycle/validate.ts +174 -0
- package/src/port.ts +14 -0
- package/src/server/index.ts +60 -4
- package/src/tree/index.ts +15 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The removed list: each removed domain, who removed it and when, that its
|
|
3
|
+
* name is free, and the restore button, which works while nobody has taken the
|
|
4
|
+
* name; otherwise the refusal is told in that domain's row. Open, as drawn.
|
|
5
|
+
*
|
|
6
|
+
* The toggle is hand-built rather than the library's `CollapsibleTrigger`,
|
|
7
|
+
* which takes no `sx` (so no 44px row), paints the open state with a selected
|
|
8
|
+
* wash and pushes its children apart, and sets neither `type="button"` nor
|
|
9
|
+
* `aria-controls`.
|
|
10
|
+
*/
|
|
11
|
+
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
|
12
|
+
import { useState, type JSX } from 'react';
|
|
13
|
+
|
|
14
|
+
import { Button } from '@12-apps/ui/form/Button';
|
|
15
|
+
import { Collapsible } from '@12-apps/ui/layout/Collapsible';
|
|
16
|
+
import { Box } from '@12-apps/ui/mui/Box';
|
|
17
|
+
import { Stack } from '@12-apps/ui/mui/Stack';
|
|
18
|
+
import { sxRem } from '@12-apps/ui/tokens';
|
|
19
|
+
import { Text } from '@12-apps/ui/typography/Text';
|
|
20
|
+
|
|
21
|
+
import { useDomainsScreen, type TenantDomainItem } from './context';
|
|
22
|
+
import { domainName } from './records';
|
|
23
|
+
import { RowRefusal } from './row';
|
|
24
|
+
|
|
25
|
+
/** The day a domain was removed, as day and month in the pack's language. */
|
|
26
|
+
function removedOn(iso: string | null, locale: string): string {
|
|
27
|
+
if (iso === null) return '';
|
|
28
|
+
return new Intl.DateTimeFormat(locale, { day: '2-digit', month: '2-digit' }).format(new Date(iso));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** One removed domain: its name, who removed it and when, a refused restore's reason, and the restore button. */
|
|
32
|
+
function RemovedRow({
|
|
33
|
+
domain,
|
|
34
|
+
busy,
|
|
35
|
+
refusal,
|
|
36
|
+
onDismissRefusal,
|
|
37
|
+
onRestore,
|
|
38
|
+
}: {
|
|
39
|
+
domain: TenantDomainItem;
|
|
40
|
+
busy: boolean;
|
|
41
|
+
refusal: string | null;
|
|
42
|
+
onDismissRefusal: () => void;
|
|
43
|
+
onRestore: () => void;
|
|
44
|
+
}): JSX.Element {
|
|
45
|
+
const pair = useDomainsScreen().copy.pair;
|
|
46
|
+
const refused = refusal !== null;
|
|
47
|
+
return (
|
|
48
|
+
<Stack
|
|
49
|
+
direction={refused ? 'column' : 'row'}
|
|
50
|
+
useFlexGap
|
|
51
|
+
spacing={refused ? 1 : 2}
|
|
52
|
+
sx={{ alignItems: refused ? 'flex-start' : 'center', justifyContent: 'space-between', flexWrap: 'wrap' }}
|
|
53
|
+
data-testid="domain-removed-row"
|
|
54
|
+
>
|
|
55
|
+
<Stack spacing={0.25} sx={{ minWidth: 0 }}>
|
|
56
|
+
<Text variant="body" size="sm" as="span" style={{ overflowWrap: 'anywhere' }}>
|
|
57
|
+
{domainName(domain, pair)}
|
|
58
|
+
</Text>
|
|
59
|
+
<Text variant="caption" size="xs" as="span">
|
|
60
|
+
{pair.removedLine(removedOn(domain.archivedAt, pair.locale), domain.archivedBy?.name ?? null)}
|
|
61
|
+
</Text>
|
|
62
|
+
</Stack>
|
|
63
|
+
{/* Told here, under the name and above the button tapped. */}
|
|
64
|
+
{refusal !== null ? <RowRefusal message={refusal} testId="domain-restore-error" onDismiss={onDismissRefusal} /> : null}
|
|
65
|
+
<Button variant="outline" color="primary" size="sm" disabled={busy} onClick={onRestore} dataTestId="domain-restore">
|
|
66
|
+
{pair.restore}
|
|
67
|
+
</Button>
|
|
68
|
+
</Stack>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function RemovedList<D extends TenantDomainItem>({
|
|
73
|
+
removed,
|
|
74
|
+
isBusy,
|
|
75
|
+
refusalOf,
|
|
76
|
+
onDismissRefusal,
|
|
77
|
+
onRestore,
|
|
78
|
+
}: {
|
|
79
|
+
removed: D[];
|
|
80
|
+
isBusy: (domain: D) => boolean;
|
|
81
|
+
/** A refused restore's sentence for this domain, or null. */
|
|
82
|
+
refusalOf: (domain: D) => string | null;
|
|
83
|
+
onDismissRefusal: (domain: D) => void;
|
|
84
|
+
onRestore: (domain: D) => void;
|
|
85
|
+
}): JSX.Element | null {
|
|
86
|
+
const pair = useDomainsScreen().copy.pair;
|
|
87
|
+
const [open, setOpen] = useState(true);
|
|
88
|
+
if (removed.length === 0) return null;
|
|
89
|
+
return (
|
|
90
|
+
<Box sx={{ border: 1, borderColor: 'divider', borderRadius: 1, px: 2, py: 0.5 }} data-testid="domains-removed">
|
|
91
|
+
<Box
|
|
92
|
+
component="button"
|
|
93
|
+
type="button"
|
|
94
|
+
aria-expanded={open}
|
|
95
|
+
aria-controls="domains-removed-list"
|
|
96
|
+
onClick={() => setOpen(!open)}
|
|
97
|
+
data-testid="domains-removed-toggle"
|
|
98
|
+
sx={{
|
|
99
|
+
display: 'flex',
|
|
100
|
+
alignItems: 'center',
|
|
101
|
+
gap: 1,
|
|
102
|
+
width: '100%',
|
|
103
|
+
minHeight: sxRem(44),
|
|
104
|
+
p: 0,
|
|
105
|
+
border: 0,
|
|
106
|
+
bgcolor: 'transparent',
|
|
107
|
+
color: 'text.primary',
|
|
108
|
+
font: 'inherit',
|
|
109
|
+
fontWeight: 600,
|
|
110
|
+
cursor: 'pointer',
|
|
111
|
+
textAlign: 'left',
|
|
112
|
+
}}
|
|
113
|
+
>
|
|
114
|
+
<ExpandMoreIcon fontSize="small" sx={{ transform: open ? 'none' : 'rotate(-90deg)', transition: 'transform .15s' }} />
|
|
115
|
+
{pair.removedTitle(removed.length)}
|
|
116
|
+
</Box>
|
|
117
|
+
<Collapsible open={open} keepMounted>
|
|
118
|
+
<Stack id="domains-removed-list" spacing={1.5} sx={{ pb: 1.5 }}>
|
|
119
|
+
{removed.map((domain) => (
|
|
120
|
+
<RemovedRow
|
|
121
|
+
key={domain.id}
|
|
122
|
+
domain={domain}
|
|
123
|
+
busy={isBusy(domain)}
|
|
124
|
+
refusal={refusalOf(domain)}
|
|
125
|
+
onDismissRefusal={() => onDismissRefusal(domain)}
|
|
126
|
+
onRestore={() => onRestore(domain)}
|
|
127
|
+
/>
|
|
128
|
+
))}
|
|
129
|
+
</Stack>
|
|
130
|
+
</Collapsible>
|
|
131
|
+
</Box>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One claimed domain: its name and status, a pair's principal address
|
|
3
|
+
* (pending or active), the records to publish, the pointing warning, where an
|
|
4
|
+
* active one answers, and the verify / remove buttons.
|
|
5
|
+
*/
|
|
6
|
+
import { useEffect, useRef, type JSX } from 'react';
|
|
7
|
+
|
|
8
|
+
import { Alert } from '@12-apps/ui/data-display/Alert';
|
|
9
|
+
import { Chip } from '@12-apps/ui/data-display/Chip';
|
|
10
|
+
import { Button } from '@12-apps/ui/form/Button';
|
|
11
|
+
import { Box } from '@12-apps/ui/mui/Box';
|
|
12
|
+
import { Stack } from '@12-apps/ui/mui/Stack';
|
|
13
|
+
import { Text } from '@12-apps/ui/typography/Text';
|
|
14
|
+
|
|
15
|
+
import { usePhoneCopy, useDomainsScreen, type TenantDomainItem } from './context';
|
|
16
|
+
import {
|
|
17
|
+
PairPointingRecord,
|
|
18
|
+
PointingRecord,
|
|
19
|
+
PointingWarning,
|
|
20
|
+
VerificationRecord,
|
|
21
|
+
domainName,
|
|
22
|
+
removalConsequence,
|
|
23
|
+
statusLabelFor,
|
|
24
|
+
} from './records';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* One domain's refused write, told INSIDE that domain's row, by the control
|
|
28
|
+
* that was tapped: at the head of the card it sat a phone's height above the
|
|
29
|
+
* tap, and the tap looked like it did nothing. It comes into view as it
|
|
30
|
+
* appears (nearest, with room for the control under it). No title: the row's
|
|
31
|
+
* own heading already names the domain.
|
|
32
|
+
*/
|
|
33
|
+
export function RowRefusal({
|
|
34
|
+
message,
|
|
35
|
+
testId,
|
|
36
|
+
onDismiss,
|
|
37
|
+
}: {
|
|
38
|
+
message: string;
|
|
39
|
+
testId: string;
|
|
40
|
+
onDismiss: () => void;
|
|
41
|
+
}): JSX.Element {
|
|
42
|
+
const { copy } = useDomainsScreen();
|
|
43
|
+
const told = useRef<HTMLDivElement>(null);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
told.current?.scrollIntoView?.({ block: 'nearest' });
|
|
46
|
+
}, [message]);
|
|
47
|
+
return (
|
|
48
|
+
<Box ref={told} sx={{ alignSelf: 'stretch', scrollMarginBottom: (theme) => theme.spacing(7) }}>
|
|
49
|
+
<Alert
|
|
50
|
+
variant="danger"
|
|
51
|
+
description={message}
|
|
52
|
+
closable
|
|
53
|
+
closeLabel={copy.closeAlert}
|
|
54
|
+
onClose={onDismiss}
|
|
55
|
+
data-testid={testId}
|
|
56
|
+
/>
|
|
57
|
+
</Box>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The row's action buttons: verify (while pending) and the confirm-gated
|
|
63
|
+
* remove, from the left, the primary solid and the secondary its inverse.
|
|
64
|
+
*/
|
|
65
|
+
function DomainActions({
|
|
66
|
+
domain,
|
|
67
|
+
pending,
|
|
68
|
+
busy,
|
|
69
|
+
disabled,
|
|
70
|
+
onVerify,
|
|
71
|
+
onRemove,
|
|
72
|
+
}: {
|
|
73
|
+
domain: TenantDomainItem;
|
|
74
|
+
pending: boolean;
|
|
75
|
+
busy: boolean;
|
|
76
|
+
disabled: boolean;
|
|
77
|
+
onVerify: () => void;
|
|
78
|
+
onRemove: () => Promise<void>;
|
|
79
|
+
}): JSX.Element {
|
|
80
|
+
const { copy, components } = useDomainsScreen();
|
|
81
|
+
const { ConfirmButton } = components;
|
|
82
|
+
return (
|
|
83
|
+
<Stack direction="row" spacing={1}>
|
|
84
|
+
{pending ? (
|
|
85
|
+
<Button
|
|
86
|
+
variant="solid"
|
|
87
|
+
color="primary"
|
|
88
|
+
size="sm"
|
|
89
|
+
disabled={disabled || busy}
|
|
90
|
+
onClick={onVerify}
|
|
91
|
+
dataTestId="domain-verify"
|
|
92
|
+
>
|
|
93
|
+
{copy.records.verifyAction}
|
|
94
|
+
</Button>
|
|
95
|
+
) : null}
|
|
96
|
+
{/* Confirm-gated: it archives the domain and frees its name, which the popup says. */}
|
|
97
|
+
<ConfirmButton
|
|
98
|
+
variant="outline"
|
|
99
|
+
color="primary"
|
|
100
|
+
size="sm"
|
|
101
|
+
disabled={busy}
|
|
102
|
+
onClick={onRemove}
|
|
103
|
+
confirm={{
|
|
104
|
+
title: copy.records.removeTitle,
|
|
105
|
+
entityName: domainName(domain, copy.pair),
|
|
106
|
+
description: removalConsequence(pending, copy.pair),
|
|
107
|
+
confirmText: copy.records.removeAction,
|
|
108
|
+
}}
|
|
109
|
+
dataTestId="domain-remove"
|
|
110
|
+
>
|
|
111
|
+
{copy.records.removeAction}
|
|
112
|
+
</ConfirmButton>
|
|
113
|
+
</Stack>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* A pair's one-line choice of its principal address, the current one
|
|
119
|
+
* selected. On a pending pair, and on an ACTIVE one too, with one line saying
|
|
120
|
+
* the change applies at once: it flips the redirect, and tapping back undoes
|
|
121
|
+
* it, so no confirmation.
|
|
122
|
+
*/
|
|
123
|
+
function PrincipalChoice({
|
|
124
|
+
domain,
|
|
125
|
+
busy,
|
|
126
|
+
disabled,
|
|
127
|
+
onPick,
|
|
128
|
+
}: {
|
|
129
|
+
domain: TenantDomainItem;
|
|
130
|
+
busy: boolean;
|
|
131
|
+
disabled: boolean;
|
|
132
|
+
onPick: (principal: 'root' | 'www') => void;
|
|
133
|
+
}): JSX.Element {
|
|
134
|
+
const { copy, components } = useDomainsScreen();
|
|
135
|
+
const { Segmented } = components;
|
|
136
|
+
const pair = copy.pair;
|
|
137
|
+
const phone = usePhoneCopy();
|
|
138
|
+
const active = domain.status === 'ACTIVE';
|
|
139
|
+
// Said only while the pair answers here: with its DNS elsewhere, no request reaches the redirect yet.
|
|
140
|
+
const saysAtOnce = active && domain.dnsPointsHere !== false;
|
|
141
|
+
return (
|
|
142
|
+
<Stack spacing={0.75} sx={{ maxWidth: '35rem' }} data-testid={active ? 'domain-principal-active' : undefined}>
|
|
143
|
+
<Text variant="caption" size="xs" as="span">
|
|
144
|
+
{pair.principalQuestion}
|
|
145
|
+
</Text>
|
|
146
|
+
<Segmented
|
|
147
|
+
label={pair.principalQuestion}
|
|
148
|
+
value={domain.principal}
|
|
149
|
+
options={[
|
|
150
|
+
{ value: 'root', label: phone ? pair.principalRootPhone : domain.hostname },
|
|
151
|
+
{ value: 'www', label: phone ? pair.principalWwwPhone : (domain.wwwHostname ?? '') },
|
|
152
|
+
]}
|
|
153
|
+
disabled={disabled}
|
|
154
|
+
busy={busy}
|
|
155
|
+
dataTestId="domain-principal"
|
|
156
|
+
onPick={onPick}
|
|
157
|
+
/>
|
|
158
|
+
{saysAtOnce ? (
|
|
159
|
+
<Text variant="caption" size="xs" as="span" data-testid="domain-principal-change">
|
|
160
|
+
{pair.principalChangeActive}
|
|
161
|
+
</Text>
|
|
162
|
+
) : null}
|
|
163
|
+
</Stack>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* An active domain's one line: where the tenant answers and what is sent
|
|
169
|
+
* there (the pair's other name, and the platform's address when this is the
|
|
170
|
+
* main domain). Silent while the DNS is known to point elsewhere: the warning
|
|
171
|
+
* says what is true then.
|
|
172
|
+
*/
|
|
173
|
+
function AnswersLine({ domain }: { domain: TenantDomainItem }): JSX.Element | null {
|
|
174
|
+
const { copy } = useDomainsScreen();
|
|
175
|
+
const pair = copy.pair;
|
|
176
|
+
const phone = usePhoneCopy();
|
|
177
|
+
if (domain.status !== 'ACTIVE' || domain.dnsPointsHere === false) return null;
|
|
178
|
+
const other = domain.wwwHostname === null ? null : domain.principal === 'root' ? domain.wwwHostname : domain.hostname;
|
|
179
|
+
const answers = pair.answersAt(domain.principalHostname);
|
|
180
|
+
const redirects = pair.redirectsFrom(other, domain.canonical);
|
|
181
|
+
const strong = (text: string) => (
|
|
182
|
+
<Text as="span" variant="body" size="sm" weight="semibold">
|
|
183
|
+
{text}
|
|
184
|
+
</Text>
|
|
185
|
+
);
|
|
186
|
+
return (
|
|
187
|
+
<Text variant="body" size="sm" data-testid="domain-answers" style={{ overflowWrap: 'anywhere' }}>
|
|
188
|
+
{answers.before}
|
|
189
|
+
{strong(domain.principalHostname)}
|
|
190
|
+
{answers.after}
|
|
191
|
+
{redirects.before}
|
|
192
|
+
{other === null ? null : phone ? pair.otherNamePhone(domain.principal) : strong(other)}
|
|
193
|
+
{redirects.after}
|
|
194
|
+
</Text>
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** The chip may take a second line rather than lose its end; its title carries the words whole as well. */
|
|
199
|
+
const STATUS_CHIP_SX = {
|
|
200
|
+
display: 'inline-flex',
|
|
201
|
+
maxWidth: '100%',
|
|
202
|
+
'& .MuiChip-root': { height: 'auto', maxWidth: '100%' },
|
|
203
|
+
'& .MuiChip-label': { whiteSpace: 'normal', overflowWrap: 'anywhere', py: 0.25 },
|
|
204
|
+
} as const;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* The status pill: amber while it waits or does not answer here yet, green
|
|
208
|
+
* once it serves. OUTLINED, not `soft`: the soft chip inks its label with the
|
|
209
|
+
* colour's dark step, which sinks on a night ground; the outline inks it with
|
|
210
|
+
* the colour's main, measured for text on both grounds.
|
|
211
|
+
*/
|
|
212
|
+
function StatusChip({ domain }: { domain: TenantDomainItem }): JSX.Element {
|
|
213
|
+
const { copy } = useDomainsScreen();
|
|
214
|
+
const serving = domain.status === 'ACTIVE' && domain.dnsPointsHere !== false;
|
|
215
|
+
const label = statusLabelFor(domain, copy.records);
|
|
216
|
+
return (
|
|
217
|
+
<Box component="span" title={label} sx={STATUS_CHIP_SX}>
|
|
218
|
+
<Chip label={label} size="sm" variant="outlined" color={serving ? 'success' : 'warning'} dataTestId="domain-status" />
|
|
219
|
+
</Box>
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** The records a row still needs published, and the pointing warning. */
|
|
224
|
+
function RowRecords({ domain, dnsTargets }: { domain: TenantDomainItem; dnsTargets: string[] }): JSX.Element {
|
|
225
|
+
const { copy } = useDomainsScreen();
|
|
226
|
+
const pending = domain.status !== 'ACTIVE';
|
|
227
|
+
return (
|
|
228
|
+
<>
|
|
229
|
+
{pending ? <VerificationRecord domain={domain} /> : null}
|
|
230
|
+
{/* The pointing record stays on screen while the name still resolves
|
|
231
|
+
elsewhere: an ACTIVE domain that is not pointed here is exactly the
|
|
232
|
+
one whose owner needs it, and the warning below sends them to it. */}
|
|
233
|
+
{pending || domain.dnsPointsHere === false ? (
|
|
234
|
+
domain.wwwHostname !== null ? (
|
|
235
|
+
<PairPointingRecord domain={domain} dnsTargets={dnsTargets} numbered={pending} />
|
|
236
|
+
) : (
|
|
237
|
+
<PointingRecord dnsTargets={dnsTargets} hostname={domain.hostname} numbered={pending} copy={copy.records} />
|
|
238
|
+
)
|
|
239
|
+
) : null}
|
|
240
|
+
<PointingWarning domain={domain} copy={copy.records} />
|
|
241
|
+
</>
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/** This row's own refused write: where it is told, and how it closes. */
|
|
246
|
+
export interface RowRefusalState {
|
|
247
|
+
/** What was refused: the principal is told under its control, anything else above the buttons. */
|
|
248
|
+
kind: 'principal' | 'other';
|
|
249
|
+
message: string;
|
|
250
|
+
testId: string;
|
|
251
|
+
onDismiss: () => void;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** A restored row is brought into view and focused once the list shows it. */
|
|
255
|
+
function useReveal(reveal: boolean, onRevealed: () => void) {
|
|
256
|
+
const row = useRef<HTMLElement>(null);
|
|
257
|
+
useEffect(() => {
|
|
258
|
+
if (!reveal) return;
|
|
259
|
+
// Head first (its name and status), the scroll margin above it: on a narrow phone a restored row is taller than the screen.
|
|
260
|
+
row.current?.scrollIntoView?.({ block: 'start' });
|
|
261
|
+
row.current?.focus({ preventScroll: true });
|
|
262
|
+
onRevealed();
|
|
263
|
+
}, [reveal, onRevealed]);
|
|
264
|
+
return row;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function DomainRow({
|
|
268
|
+
domain,
|
|
269
|
+
dnsTargets,
|
|
270
|
+
disabled,
|
|
271
|
+
busy,
|
|
272
|
+
refusal = null,
|
|
273
|
+
reveal = false,
|
|
274
|
+
onRevealed = () => undefined,
|
|
275
|
+
onVerify,
|
|
276
|
+
onPrincipal,
|
|
277
|
+
onRemove,
|
|
278
|
+
}: {
|
|
279
|
+
domain: TenantDomainItem;
|
|
280
|
+
dnsTargets: string[];
|
|
281
|
+
disabled: boolean;
|
|
282
|
+
/** THIS domain's write is in flight, never another domain's. */
|
|
283
|
+
busy: boolean;
|
|
284
|
+
refusal?: RowRefusalState | null;
|
|
285
|
+
/** Just restored: scroll it into view and focus it. */
|
|
286
|
+
reveal?: boolean;
|
|
287
|
+
onRevealed?: () => void;
|
|
288
|
+
onVerify: () => void;
|
|
289
|
+
onPrincipal: (principal: 'root' | 'www') => void;
|
|
290
|
+
onRemove: () => Promise<void>;
|
|
291
|
+
}): JSX.Element {
|
|
292
|
+
const { copy } = useDomainsScreen();
|
|
293
|
+
const pending = domain.status !== 'ACTIVE';
|
|
294
|
+
const isPair = domain.wwwHostname !== null;
|
|
295
|
+
const row = useReveal(reveal, onRevealed);
|
|
296
|
+
const told = (kind: RowRefusalState['kind']) =>
|
|
297
|
+
refusal !== null && refusal.kind === kind ? (
|
|
298
|
+
<RowRefusal message={refusal.message} testId={refusal.testId} onDismiss={refusal.onDismiss} />
|
|
299
|
+
) : null;
|
|
300
|
+
|
|
301
|
+
return (
|
|
302
|
+
<Box
|
|
303
|
+
ref={row}
|
|
304
|
+
component="section"
|
|
305
|
+
tabIndex={-1}
|
|
306
|
+
aria-label={domainName(domain, copy.pair)}
|
|
307
|
+
sx={{ border: 1, borderColor: 'divider', borderRadius: 1, p: 2, scrollMarginBlock: (theme) => theme.spacing(2) }}
|
|
308
|
+
data-testid="domain-row"
|
|
309
|
+
>
|
|
310
|
+
<Stack spacing={1.5}>
|
|
311
|
+
<Stack direction="row" spacing={1.5} useFlexGap sx={{ alignItems: 'baseline', flexWrap: 'wrap' }}>
|
|
312
|
+
<Text variant="body" size="sm" weight="semibold" as="span" style={{ overflowWrap: 'anywhere' }}>
|
|
313
|
+
{domainName(domain, copy.pair)}
|
|
314
|
+
</Text>
|
|
315
|
+
<StatusChip domain={domain} />
|
|
316
|
+
</Stack>
|
|
317
|
+
|
|
318
|
+
{isPair ? <PrincipalChoice domain={domain} busy={busy} disabled={disabled} onPick={onPrincipal} /> : null}
|
|
319
|
+
{told('principal')}
|
|
320
|
+
<RowRecords domain={domain} dnsTargets={dnsTargets} />
|
|
321
|
+
<AnswersLine domain={domain} />
|
|
322
|
+
|
|
323
|
+
{told('other')}
|
|
324
|
+
<DomainActions
|
|
325
|
+
domain={domain}
|
|
326
|
+
pending={pending}
|
|
327
|
+
busy={busy}
|
|
328
|
+
disabled={disabled}
|
|
329
|
+
onVerify={onVerify}
|
|
330
|
+
onRemove={onRemove}
|
|
331
|
+
/>
|
|
332
|
+
</Stack>
|
|
333
|
+
</Box>
|
|
334
|
+
);
|
|
335
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createDomainsScreen`: the host's packs and widgets, checked at startup.
|
|
3
|
+
* A pack missing a key, or a widget left out, fails when the host boots,
|
|
4
|
+
* named (`domainsScreen.copy.locales.<tag>.records.<key>`), instead of a blank
|
|
5
|
+
* line on screen.
|
|
6
|
+
*/
|
|
7
|
+
import { TenantConfigError } from '../../validate';
|
|
8
|
+
import { PairAnnouncement, makeDomainsCard } from './card';
|
|
9
|
+
import type { TenantDomainsComponents } from './context';
|
|
10
|
+
import { TENANT_DOMAINS_COPY_SHAPE, type TenantDomainsCopy } from './copy';
|
|
11
|
+
|
|
12
|
+
export interface TenantDomainsScreenConfig {
|
|
13
|
+
copy: { locales: Record<string, TenantDomainsCopy>; defaultLocale: string };
|
|
14
|
+
components: TenantDomainsComponents;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type Bag = Record<string, unknown>;
|
|
18
|
+
const isBag = (value: unknown): value is Bag => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
19
|
+
|
|
20
|
+
function requireBag(value: unknown, key: string): Bag {
|
|
21
|
+
if (value === undefined || value === null) throw new TenantConfigError(key, 'is required and missing');
|
|
22
|
+
if (!isBag(value)) throw new TenantConfigError(key, 'must be an object');
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function checkEntry(value: unknown, kind: 'text' | 'sentence', key: string): void {
|
|
27
|
+
if (value === undefined || value === null) throw new TenantConfigError(key, 'is required and missing');
|
|
28
|
+
if (kind === 'text' && (typeof value !== 'string' || value.trim() === '')) {
|
|
29
|
+
throw new TenantConfigError(key, 'must be a non-empty string');
|
|
30
|
+
}
|
|
31
|
+
if (kind === 'sentence' && typeof value !== 'function') {
|
|
32
|
+
throw new TenantConfigError(key, 'must be a function that writes the whole sentence');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Every grouped key of a pack, once: `[group, name, kind]`. */
|
|
37
|
+
const GROUPED_KEYS = (['records', 'pair'] as const).flatMap((group) =>
|
|
38
|
+
Object.entries(TENANT_DOMAINS_COPY_SHAPE[group]).map(([name, kind]) => [group, name, kind] as const),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
function checkPack(value: unknown, key: string): void {
|
|
42
|
+
const pack = requireBag(value, key);
|
|
43
|
+
const groups = { records: requireBag(pack.records, `${key}.records`), pair: requireBag(pack.pair, `${key}.pair`) };
|
|
44
|
+
for (const [group, name, kind] of GROUPED_KEYS) checkEntry(groups[group][name], kind, `${key}.${group}.${name}`);
|
|
45
|
+
checkEntry(pack.closeAlert, TENANT_DOMAINS_COPY_SHAPE.closeAlert, `${key}.closeAlert`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function checkCopy(value: unknown): void {
|
|
49
|
+
const copy = requireBag(value, 'domainsScreen.copy');
|
|
50
|
+
const locales = requireBag(copy.locales, 'domainsScreen.copy.locales');
|
|
51
|
+
const tags = Object.keys(locales);
|
|
52
|
+
if (tags.length === 0) throw new TenantConfigError('domainsScreen.copy.locales', 'must hold at least one locale pack');
|
|
53
|
+
for (const tag of tags) checkPack(locales[tag], `domainsScreen.copy.locales.${tag}`);
|
|
54
|
+
const fallback = copy.defaultLocale;
|
|
55
|
+
if (typeof fallback !== 'string' || fallback === '') {
|
|
56
|
+
throw new TenantConfigError('domainsScreen.copy.defaultLocale', 'is required and missing');
|
|
57
|
+
}
|
|
58
|
+
if (!tags.includes(fallback)) {
|
|
59
|
+
throw new TenantConfigError('domainsScreen.copy.defaultLocale', `names "${fallback}", which copy.locales does not hold`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function checkComponents(value: unknown): void {
|
|
64
|
+
const components = requireBag(value, 'domainsScreen.components');
|
|
65
|
+
for (const name of ['ConfirmButton', 'Segmented'] as const) {
|
|
66
|
+
const component = components[name];
|
|
67
|
+
if (component === undefined || component === null) {
|
|
68
|
+
throw new TenantConfigError(`domainsScreen.components.${name}`, 'is required and missing');
|
|
69
|
+
}
|
|
70
|
+
// A function component, or an exotic one (memo, forwardRef): an object with `$$typeof`.
|
|
71
|
+
if (typeof component !== 'function' && !(isBag(component) && '$$typeof' in component)) {
|
|
72
|
+
throw new TenantConfigError(`domainsScreen.components.${name}`, 'must be a React component');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Check the screen's config. Throws {@link TenantConfigError}. */
|
|
78
|
+
export function validateDomainsScreen(config: unknown): void {
|
|
79
|
+
const bag = requireBag(config, 'domainsScreen');
|
|
80
|
+
checkCopy(bag.copy);
|
|
81
|
+
checkComponents(bag.components);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function createDomainsScreen(config: TenantDomainsScreenConfig) {
|
|
85
|
+
validateDomainsScreen(config);
|
|
86
|
+
return {
|
|
87
|
+
/** The claims, the records, verify / remove and the removed list; `copy` is this render's resolved pack. */
|
|
88
|
+
DomainsCard: makeDomainsCard(config.components),
|
|
89
|
+
/** The claim field's note that a root is claimed with its `www.`. */
|
|
90
|
+
PairAnnouncement,
|
|
91
|
+
};
|
|
92
|
+
}
|