@12-apps/tenant 1.3.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 +94 -0
- package/README.md +4 -2
- package/package.json +26 -3
- 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/index.ts +28 -1
- package/src/server/index.ts +45 -3
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ports a host gives custom domains. The domain table is the HOST's: the
|
|
3
|
+
* package maps no table and names no column, so every read and write goes
|
|
4
|
+
* through {@link TenantDomainPort}, and the plan's quota through
|
|
5
|
+
* {@link TenantDomainQuota}. Both are required, every member.
|
|
6
|
+
*/
|
|
7
|
+
import type { TenantDomainRecord, TenantDomainRow } from './record';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The host's domain rows. Statement budget (ADOPTING.md, "Custom domains"):
|
|
11
|
+
* `rows` and `holders` are ONE read each; a member that adds a read is a defect.
|
|
12
|
+
*/
|
|
13
|
+
export interface TenantDomainPort<Tx = unknown> {
|
|
14
|
+
/** EVERY row of the tenant, removed ones included, newest first (`createdAt` desc, `hostname` asc). One read. */
|
|
15
|
+
rows(tenantId: string, tx?: Tx): Promise<TenantDomainRow[]>;
|
|
16
|
+
/** The live rows of ANY tenant holding any of `hostnames`. One read. */
|
|
17
|
+
holders(hostnames: readonly string[], tx?: Tx): Promise<{ hostname: string; tenantId: string }[]>;
|
|
18
|
+
/** Run `work` in ONE transaction at SERIALIZABLE isolation. */
|
|
19
|
+
transaction<T>(work: (tx: Tx) => Promise<T>): Promise<T>;
|
|
20
|
+
/**
|
|
21
|
+
* What a thrown error means: `'retry'` a serializable transaction that lost
|
|
22
|
+
* to a concurrent one (nothing was written), `'taken'` a unique-index
|
|
23
|
+
* violation on a hostname (a race claimed it first), `null` anything else,
|
|
24
|
+
* which the engine rethrows.
|
|
25
|
+
*/
|
|
26
|
+
failure(error: unknown): 'retry' | 'taken' | null;
|
|
27
|
+
/**
|
|
28
|
+
* Write a claim's rows: the name, and for a zone apex its `www.` too (one
|
|
29
|
+
* domain, ONE token, which the host mints and which must be unguessable).
|
|
30
|
+
*/
|
|
31
|
+
claim(tx: Tx, tenantId: string, hostname: string, principal: 'root' | 'www'): Promise<TenantDomainRecord>;
|
|
32
|
+
/** Make `principal` the pair's principal address. */
|
|
33
|
+
setPrincipal(tx: Tx, tenantId: string, id: string, principal: 'root' | 'www'): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Record a check on every name of the domain, by each name's row id: verified
|
|
36
|
+
* moves the rows to ACTIVE, else FAILED; a `null` pointing answer leaves the
|
|
37
|
+
* stored one as it is.
|
|
38
|
+
*/
|
|
39
|
+
recordCheck(
|
|
40
|
+
tx: Tx,
|
|
41
|
+
tenantId: string,
|
|
42
|
+
domain: TenantDomainRecord,
|
|
43
|
+
outcome: { verified: boolean; pointsHere: Readonly<Record<string, boolean | null>> },
|
|
44
|
+
at: Date,
|
|
45
|
+
): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Remove the pair (root and `www.`): archived, AND made unservable, so a
|
|
48
|
+
* release that cannot read the archive column (a rollback) still never serves it.
|
|
49
|
+
*/
|
|
50
|
+
archive(tx: Tx, tenantId: string, id: string, at: Date, by: string | null): Promise<void>;
|
|
51
|
+
/** Bring the pair back, unverified: ownership is proven again with the same token. */
|
|
52
|
+
restore(tx: Tx, tenantId: string, id: string): Promise<void>;
|
|
53
|
+
/** One audit line per removal and restore, in the host's own ids and words. */
|
|
54
|
+
audit(
|
|
55
|
+
tx: Tx,
|
|
56
|
+
line: { act: 'archive' | 'restore'; tenantId: string; domain: TenantDomainRecord; reason: string | null; via: string },
|
|
57
|
+
): Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const TENANT_DOMAIN_PORT_METHODS = [
|
|
61
|
+
'rows',
|
|
62
|
+
'holders',
|
|
63
|
+
'transaction',
|
|
64
|
+
'failure',
|
|
65
|
+
'claim',
|
|
66
|
+
'setPrincipal',
|
|
67
|
+
'recordCheck',
|
|
68
|
+
'archive',
|
|
69
|
+
'restore',
|
|
70
|
+
'audit',
|
|
71
|
+
] as const satisfies readonly (keyof TenantDomainPort)[];
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The host's plan for custom domains. `via` is whatever the host put on the
|
|
75
|
+
* context (where the call came from); the package never reads it, so a host
|
|
76
|
+
* that answers one caller with its own refusal (a thrown platform error) and
|
|
77
|
+
* another with a problem decides that here.
|
|
78
|
+
*/
|
|
79
|
+
export interface TenantDomainQuota<Tx = unknown> {
|
|
80
|
+
/** Whether a `verify` may run at all. Asked only when the call has one; may throw the host's own refusal. */
|
|
81
|
+
mayVerify(tenantId: string, via: string): Promise<boolean>;
|
|
82
|
+
/**
|
|
83
|
+
* Reserve `units` (> 0) new domains: the limit to re-check in the
|
|
84
|
+
* transaction (`null` = unlimited), or which refusal. May throw the host's own.
|
|
85
|
+
*/
|
|
86
|
+
reserve(
|
|
87
|
+
tenantId: string,
|
|
88
|
+
units: number,
|
|
89
|
+
via: string,
|
|
90
|
+
): Promise<{ limit: number | null } | { refused: 'planRequired' | 'planLimit' }>;
|
|
91
|
+
/** The tenant's domains counted against the plan, re-read on `tx`. */
|
|
92
|
+
used(tenantId: string, tx: Tx): Promise<number>;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export const TENANT_DOMAIN_QUOTA_METHODS = ['mayVerify', 'reserve', 'used'] as const satisfies readonly (keyof TenantDomainQuota)[];
|
|
96
|
+
|
|
97
|
+
/** How the host resolves names. Its own, so its tests can replace it. */
|
|
98
|
+
export interface TenantDomainResolver {
|
|
99
|
+
/** TXT records, each as its chunks. */
|
|
100
|
+
txt(name: string): Promise<string[][]>;
|
|
101
|
+
ipv4(name: string): Promise<string[]>;
|
|
102
|
+
ipv6(name: string): Promise<string[]>;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export const TENANT_DOMAIN_RESOLVER_METHODS = ['txt', 'ipv4', 'ipv6'] as const satisfies readonly (keyof TenantDomainResolver)[];
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The claims already made: each one's state, the records it still needs, and
|
|
3
|
+
* verify / remove, or, with none yet, the address to have ready; then the
|
|
4
|
+
* removed list. The flow the screen has to make obvious: claim a hostname,
|
|
5
|
+
* publish the TXT record shown, point the domain here, verify. A domain does
|
|
6
|
+
* NOT serve until the TXT check passes, because pointing DNS proves nothing
|
|
7
|
+
* about ownership. BOTH halves are on screen: ownership and pointing are
|
|
8
|
+
* independent, and a green status over a dead site is worse than a red one.
|
|
9
|
+
*
|
|
10
|
+
* The writes are the host's (its API, its keyed mutation, its refusal words);
|
|
11
|
+
* the card only routes each refusal to where it is told.
|
|
12
|
+
*/
|
|
13
|
+
import { useCallback, useState, type JSX, type ReactNode } from 'react';
|
|
14
|
+
|
|
15
|
+
import { Alert } from '@12-apps/ui/data-display/Alert';
|
|
16
|
+
import { EmptyState } from '@12-apps/ui/data-display/EmptyState';
|
|
17
|
+
import { Box } from '@12-apps/ui/mui/Box';
|
|
18
|
+
import { Stack } from '@12-apps/ui/mui/Stack';
|
|
19
|
+
import { Text } from '@12-apps/ui/typography/Text';
|
|
20
|
+
|
|
21
|
+
import { DomainsScreenProvider, useDomainsScreen, type TenantDomainItem, type TenantDomainsComponents } from './context';
|
|
22
|
+
import type { TenantDomainPairCopy, TenantDomainsCopy } from './copy';
|
|
23
|
+
import { PointingRecord, domainName } from './records';
|
|
24
|
+
import { RemovedList } from './removed';
|
|
25
|
+
import { DomainRow, type RowRefusalState } from './row';
|
|
26
|
+
|
|
27
|
+
/** One write on one domain. `settled` answers after the host's re-read: a restore reveals its row. */
|
|
28
|
+
export type TenantDomainWrite<D extends TenantDomainItem> =
|
|
29
|
+
| { kind: 'verify'; domain: D }
|
|
30
|
+
| { kind: 'restore'; domain: D; settled?: (refusal: string | null) => void }
|
|
31
|
+
| { kind: 'principal'; domain: D; principal: 'root' | 'www' };
|
|
32
|
+
|
|
33
|
+
/** A standing refusal of one domain's write, with the write that was refused. */
|
|
34
|
+
export interface TenantDomainRefusal<D extends TenantDomainItem> {
|
|
35
|
+
key: string;
|
|
36
|
+
message: string;
|
|
37
|
+
input: { kind: 'verify' | 'restore' | 'principal' | 'remove'; domain: D };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The host's writes, ONE PER DOMAIN: their state, a write, and the confirm-gated remove (it rejects with the refusal). */
|
|
41
|
+
export interface TenantDomainWrites<D extends TenantDomainItem> {
|
|
42
|
+
writes: {
|
|
43
|
+
errors: readonly TenantDomainRefusal<D>[];
|
|
44
|
+
isPending(id: string): boolean;
|
|
45
|
+
dismiss(id: string): void;
|
|
46
|
+
};
|
|
47
|
+
run(write: TenantDomainWrite<D>): void;
|
|
48
|
+
remove(domain: D): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface DomainsCardProps<D extends TenantDomainItem> {
|
|
52
|
+
domains: D[];
|
|
53
|
+
/** The removed (archived) domains. */
|
|
54
|
+
removed: D[];
|
|
55
|
+
dnsTargets: string[];
|
|
56
|
+
disabled: boolean;
|
|
57
|
+
/** The resolved pack for this render. */
|
|
58
|
+
copy: TenantDomainsCopy;
|
|
59
|
+
writes: TenantDomainWrites<D>;
|
|
60
|
+
/**
|
|
61
|
+
* The host's own empty state, drawn in place of the package's (an
|
|
62
|
+
* `EmptyState` titled `records.emptyTitle`, test id `domains-empty`) when
|
|
63
|
+
* there is no domain yet: for a host whose tooling reads its own JSX, such
|
|
64
|
+
* as a search index that files the card under its test id.
|
|
65
|
+
*/
|
|
66
|
+
emptyState?: ReactNode;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** No domain yet: the invitation, and the address to have ready. */
|
|
70
|
+
function NoDomainsYet({ dnsTargets, emptyState }: { dnsTargets: string[]; emptyState?: ReactNode }): JSX.Element {
|
|
71
|
+
const records = useDomainsScreen().copy.records;
|
|
72
|
+
return (
|
|
73
|
+
<>
|
|
74
|
+
{/* An invitation rather than a statement of absence: the state a tenant
|
|
75
|
+
is in when it arrives on this screen for the first time. */}
|
|
76
|
+
{emptyState ?? (
|
|
77
|
+
<EmptyState variant="minimal" title={records.emptyTitle} description={records.emptyBody} dataTestId="domains-empty" />
|
|
78
|
+
)}
|
|
79
|
+
{/* Unnumbered: with no domain there is no TXT record yet, so this is not
|
|
80
|
+
step 2 of anything; it is the address to have ready. */}
|
|
81
|
+
<PointingRecord dnsTargets={dnsTargets} numbered={false} copy={records} />
|
|
82
|
+
</>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** A refused restore's sentence for this removed domain, or null. */
|
|
87
|
+
function restoreRefusalOf<D extends TenantDomainItem>(errors: readonly TenantDomainRefusal<D>[], domain: D): string | null {
|
|
88
|
+
return errors.find((refusal) => refusal.key === domain.id && refusal.input.kind === 'restore')?.message ?? null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** A live row's own refused write, told in that row. The first refusal on screen is `domains-error`. */
|
|
92
|
+
function rowRefusalOf<D extends TenantDomainItem>(writes: TenantDomainWrites<D>['writes'], domain: D): RowRefusalState | null {
|
|
93
|
+
const told = writes.errors.filter((refusal) => refusal.input.kind !== 'restore');
|
|
94
|
+
const at = told.findIndex((refusal) => refusal.key === domain.id);
|
|
95
|
+
const refusal = told[at];
|
|
96
|
+
if (refusal === undefined) return null;
|
|
97
|
+
return {
|
|
98
|
+
kind: refusal.input.kind === 'principal' ? 'principal' : 'other',
|
|
99
|
+
message: refusal.message,
|
|
100
|
+
testId: at === 0 ? 'domains-error' : `domains-error-${refusal.key}`,
|
|
101
|
+
onDismiss: () => writes.dismiss(refusal.key),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function CardBody<D extends TenantDomainItem>({
|
|
106
|
+
domains,
|
|
107
|
+
removed,
|
|
108
|
+
dnsTargets,
|
|
109
|
+
disabled,
|
|
110
|
+
writes: host,
|
|
111
|
+
emptyState,
|
|
112
|
+
}: DomainsCardProps<D>): JSX.Element {
|
|
113
|
+
const { copy } = useDomainsScreen();
|
|
114
|
+
const { writes, run, remove } = host;
|
|
115
|
+
const [revealed, setRevealed] = useState<string | null>(null);
|
|
116
|
+
const doneRevealing = useCallback(() => setRevealed(null), []);
|
|
117
|
+
// Each refusal is told in its own row; only one whose domain has left the
|
|
118
|
+
// list meanwhile is told at the head, named after it.
|
|
119
|
+
const live = new Set(domains.map((domain) => domain.id));
|
|
120
|
+
const headRefusals = writes.errors.filter((refusal) => refusal.input.kind !== 'restore' && !live.has(refusal.key));
|
|
121
|
+
|
|
122
|
+
return (
|
|
123
|
+
<Stack spacing={2} data-testid="domains-card">
|
|
124
|
+
{headRefusals.map((refusal) => (
|
|
125
|
+
<Alert
|
|
126
|
+
key={refusal.key}
|
|
127
|
+
variant="danger"
|
|
128
|
+
// Named after its domain: two rows can be refused at once.
|
|
129
|
+
title={domainName(refusal.input.domain, copy.pair)}
|
|
130
|
+
description={refusal.message}
|
|
131
|
+
closable
|
|
132
|
+
closeLabel={copy.closeAlert}
|
|
133
|
+
onClose={() => writes.dismiss(refusal.key)}
|
|
134
|
+
data-testid={
|
|
135
|
+
writes.errors.find((told) => told.input.kind !== 'restore')?.key === refusal.key
|
|
136
|
+
? 'domains-error'
|
|
137
|
+
: `domains-error-${refusal.key}`
|
|
138
|
+
}
|
|
139
|
+
/>
|
|
140
|
+
))}
|
|
141
|
+
|
|
142
|
+
{domains.length === 0 ? (
|
|
143
|
+
<NoDomainsYet dnsTargets={dnsTargets} emptyState={emptyState} />
|
|
144
|
+
) : (
|
|
145
|
+
domains.map((domain) => (
|
|
146
|
+
<DomainRow
|
|
147
|
+
key={domain.id}
|
|
148
|
+
domain={domain}
|
|
149
|
+
dnsTargets={dnsTargets}
|
|
150
|
+
disabled={disabled}
|
|
151
|
+
busy={writes.isPending(domain.id)}
|
|
152
|
+
refusal={rowRefusalOf(writes, domain)}
|
|
153
|
+
reveal={revealed === domain.id}
|
|
154
|
+
onRevealed={doneRevealing}
|
|
155
|
+
onVerify={() => run({ kind: 'verify', domain })}
|
|
156
|
+
onPrincipal={(principal) => run({ kind: 'principal', domain, principal })}
|
|
157
|
+
onRemove={() => remove(domain)}
|
|
158
|
+
/>
|
|
159
|
+
))
|
|
160
|
+
)}
|
|
161
|
+
|
|
162
|
+
<RemovedList
|
|
163
|
+
removed={removed}
|
|
164
|
+
isBusy={(domain) => disabled || writes.isPending(domain.id)}
|
|
165
|
+
refusalOf={(domain) => restoreRefusalOf(writes.errors, domain)}
|
|
166
|
+
onDismissRefusal={(domain) => writes.dismiss(domain.id)}
|
|
167
|
+
onRestore={(domain) =>
|
|
168
|
+
run({ kind: 'restore', domain, settled: (refusal) => refusal === null && setRevealed(domain.id) })
|
|
169
|
+
}
|
|
170
|
+
/>
|
|
171
|
+
</Stack>
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** The card, its pack and the host's widgets provided to every part. */
|
|
176
|
+
export function makeDomainsCard(components: TenantDomainsComponents) {
|
|
177
|
+
return function DomainsCard<D extends TenantDomainItem>(props: DomainsCardProps<D>): JSX.Element {
|
|
178
|
+
return (
|
|
179
|
+
<DomainsScreenProvider value={{ copy: props.copy, components }}>
|
|
180
|
+
<CardBody {...props} />
|
|
181
|
+
</DomainsScreenProvider>
|
|
182
|
+
);
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Under the claim field, before saving, when the typed address is a root domain: it is claimed with its `www.`. */
|
|
187
|
+
export function PairAnnouncement({
|
|
188
|
+
root,
|
|
189
|
+
www,
|
|
190
|
+
copy,
|
|
191
|
+
}: {
|
|
192
|
+
root: string;
|
|
193
|
+
www: string;
|
|
194
|
+
copy: Pick<TenantDomainPairCopy, 'pairAnnouncement'>;
|
|
195
|
+
}): JSX.Element {
|
|
196
|
+
const words = copy.pairAnnouncement(root, www);
|
|
197
|
+
const strong = (text: string) => (
|
|
198
|
+
<Text as="span" variant="body" size="sm" weight="semibold">
|
|
199
|
+
{text}
|
|
200
|
+
</Text>
|
|
201
|
+
);
|
|
202
|
+
return (
|
|
203
|
+
<Box
|
|
204
|
+
sx={{ bgcolor: 'action.hover', borderRadius: 1, px: 1.5, py: 1.25, maxWidth: '40rem' }}
|
|
205
|
+
data-testid="domain-pair-announcement"
|
|
206
|
+
>
|
|
207
|
+
<Text variant="body" size="sm" style={{ overflowWrap: 'anywhere' }}>
|
|
208
|
+
{words.before}
|
|
209
|
+
{strong(root)}
|
|
210
|
+
{words.and}
|
|
211
|
+
{strong(www)}
|
|
212
|
+
{words.after}
|
|
213
|
+
</Text>
|
|
214
|
+
</Box>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What every part of the screen reads without a prop: the resolved pack and
|
|
3
|
+
* the host's two widgets. The card provides it; a part rendered outside the
|
|
4
|
+
* card (the records, standalone) takes its copy as a prop instead.
|
|
5
|
+
*/
|
|
6
|
+
import { createContext, useContext, type JSXElementConstructor, type ReactNode } from 'react';
|
|
7
|
+
|
|
8
|
+
import { useTheme } from '@12-apps/ui/mui/styles';
|
|
9
|
+
import useMediaQuery from '@12-apps/ui/mui/useMediaQuery';
|
|
10
|
+
|
|
11
|
+
import type { TenantDomainsCopy } from './copy';
|
|
12
|
+
|
|
13
|
+
/** One record as the host's wire sends it (the type as a plain string). */
|
|
14
|
+
export interface TenantDomainItemRecord {
|
|
15
|
+
type: string;
|
|
16
|
+
name: string;
|
|
17
|
+
fqdn: string;
|
|
18
|
+
values: string[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** A domain as the screen reads it: the host's wire view (dates as ISO strings). */
|
|
22
|
+
export interface TenantDomainItem {
|
|
23
|
+
id: string;
|
|
24
|
+
/** The claimed name: the root of a pair, or the one subdomain. */
|
|
25
|
+
hostname: string;
|
|
26
|
+
/** A root claim's `www.` companion; null for a subdomain. */
|
|
27
|
+
wwwHostname: string | null;
|
|
28
|
+
principal: 'root' | 'www';
|
|
29
|
+
principalHostname: string;
|
|
30
|
+
status: string;
|
|
31
|
+
/** The FQDN the verification TXT record is published at. */
|
|
32
|
+
recordName: string;
|
|
33
|
+
dnsRecords: { verification: TenantDomainItemRecord; pointing: TenantDomainItemRecord[] };
|
|
34
|
+
/** `null` is unknown and is never told as a problem; only `false` is. */
|
|
35
|
+
dnsPointsHere: boolean | null;
|
|
36
|
+
/** The tenant's main domain: the platform address redirects to its principal name. */
|
|
37
|
+
canonical: boolean;
|
|
38
|
+
archived: boolean;
|
|
39
|
+
archivedAt: string | null;
|
|
40
|
+
archivedBy: { userId: string; name: string | null } | null;
|
|
41
|
+
verifiedAt: string | null;
|
|
42
|
+
createdAt: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The host's confirm-gated button (its own words for the popup's chrome). A
|
|
47
|
+
* constructor of these props, so a host's wider button (more variants, more
|
|
48
|
+
* props) fits.
|
|
49
|
+
*/
|
|
50
|
+
export type TenantDomainsConfirmButton = JSXElementConstructor<{
|
|
51
|
+
variant: 'outline';
|
|
52
|
+
color: 'primary';
|
|
53
|
+
size: 'sm';
|
|
54
|
+
disabled?: boolean;
|
|
55
|
+
onClick: () => Promise<void>;
|
|
56
|
+
confirm: { title: string; entityName: string; description: string; confirmText: string };
|
|
57
|
+
dataTestId?: string;
|
|
58
|
+
children?: ReactNode;
|
|
59
|
+
}>;
|
|
60
|
+
|
|
61
|
+
/** The host's one-line choice of equal parts. */
|
|
62
|
+
export type TenantDomainsSegmented = JSXElementConstructor<{
|
|
63
|
+
label: string;
|
|
64
|
+
value: 'root' | 'www';
|
|
65
|
+
options: readonly { value: 'root' | 'www'; label: string }[];
|
|
66
|
+
disabled?: boolean;
|
|
67
|
+
busy?: boolean;
|
|
68
|
+
dataTestId: string;
|
|
69
|
+
onPick: (next: 'root' | 'www') => void;
|
|
70
|
+
}>;
|
|
71
|
+
|
|
72
|
+
/** The widgets the host binds to its own words and look, injected rather than copied. */
|
|
73
|
+
export interface TenantDomainsComponents {
|
|
74
|
+
ConfirmButton: TenantDomainsConfirmButton;
|
|
75
|
+
Segmented: TenantDomainsSegmented;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface ScreenContext {
|
|
79
|
+
copy: TenantDomainsCopy;
|
|
80
|
+
components: TenantDomainsComponents;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const DomainsScreenContext = createContext<ScreenContext | null>(null);
|
|
84
|
+
|
|
85
|
+
export const DomainsScreenProvider = DomainsScreenContext.Provider;
|
|
86
|
+
|
|
87
|
+
/** The screen's pack and widgets; only inside the card. */
|
|
88
|
+
export function useDomainsScreen(): ScreenContext {
|
|
89
|
+
const screen = useContext(DomainsScreenContext);
|
|
90
|
+
if (screen === null) {
|
|
91
|
+
throw new Error('@12-apps/tenant: a domains screen part was rendered outside its DomainsCard.');
|
|
92
|
+
}
|
|
93
|
+
return screen;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Below `sm` the phone says some lines shorter: the principal control's parts,
|
|
98
|
+
* step 1's lead-in, the delete advice and the active line. One question, asked once.
|
|
99
|
+
*/
|
|
100
|
+
export function usePhoneCopy(): boolean {
|
|
101
|
+
return useMediaQuery(useTheme().breakpoints.down('sm'));
|
|
102
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The words of the custom-domains screen: ALL of them are the host's. The
|
|
3
|
+
* package names each key and its kind (`text`, or `sentence`: a function that
|
|
4
|
+
* writes the whole sentence, so a language's grammar stays the host's), and
|
|
5
|
+
* `createDomainsScreen` refuses a pack missing one.
|
|
6
|
+
*
|
|
7
|
+
* Two groups on purpose: both say "remove from the list" and "what removing
|
|
8
|
+
* costs", in different words, and the row uses the PAIR's. Flattening them
|
|
9
|
+
* would silently swap sentences.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** The records, the statuses, the empty state and the row's own buttons. */
|
|
13
|
+
export interface TenantDomainRecordsCopy {
|
|
14
|
+
readonly awaitingVerification: string;
|
|
15
|
+
readonly verificationFailed: string;
|
|
16
|
+
readonly verified: string;
|
|
17
|
+
readonly active: string;
|
|
18
|
+
readonly disabled: string;
|
|
19
|
+
/** An ACTIVE domain whose DNS answers elsewhere: the status word, qualified. */
|
|
20
|
+
dnsNotHereYet(base: string): string;
|
|
21
|
+
/** The removal confirmation's title. */
|
|
22
|
+
readonly removeTitle: string;
|
|
23
|
+
/** The field's placeholder, also the example address of the empty state. */
|
|
24
|
+
readonly placeholder: string;
|
|
25
|
+
readonly emptyTitle: string;
|
|
26
|
+
readonly emptyBody: string;
|
|
27
|
+
readonly recordType: string;
|
|
28
|
+
readonly recordName: string;
|
|
29
|
+
readonly recordValue: string;
|
|
30
|
+
/** Step 1 for a lone subdomain: the TXT record. */
|
|
31
|
+
readonly txtStep: string;
|
|
32
|
+
readonly kindApex: string;
|
|
33
|
+
readonly kindSubdomain: string;
|
|
34
|
+
/** Marks the kind the row's own address is. */
|
|
35
|
+
readonly yourCase: string;
|
|
36
|
+
apexGuide(example: string): string;
|
|
37
|
+
subdomainGuide(example: string, label: string): string;
|
|
38
|
+
/** The kind the row is NOT: an offer, never an order. */
|
|
39
|
+
otherApexGuide(example: string): string;
|
|
40
|
+
otherSubdomainGuide(example: string, label: string): string;
|
|
41
|
+
fullNameFallback(fqdn: string): string;
|
|
42
|
+
pointWithRecord(recordType: string): string;
|
|
43
|
+
readonly pointWithRecords: string;
|
|
44
|
+
recordLabel(recordType: string): string;
|
|
45
|
+
readonly notPointedWarning: string;
|
|
46
|
+
readonly copyValue: string;
|
|
47
|
+
readonly copiedValue: string;
|
|
48
|
+
copyValueLabel(value: string): string;
|
|
49
|
+
/** The verify button. */
|
|
50
|
+
readonly verifyAction: string;
|
|
51
|
+
/** The remove button, and its confirmation's button. */
|
|
52
|
+
readonly removeAction: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The root + `www` pair, the principal address and the removed list. */
|
|
56
|
+
export interface TenantDomainPairCopy {
|
|
57
|
+
pairAnnouncement(root: string, www: string): { before: string; and: string; after: string };
|
|
58
|
+
pairName(root: string): string;
|
|
59
|
+
readonly principalQuestion: string;
|
|
60
|
+
readonly principalRootPhone: string;
|
|
61
|
+
readonly principalWwwPhone: string;
|
|
62
|
+
readonly principalChangeActive: string;
|
|
63
|
+
readonly txtStepPair: string;
|
|
64
|
+
readonly txtStepPairPhone: string;
|
|
65
|
+
readonly pointBothNames: string;
|
|
66
|
+
readonly replaceOldRecords: string;
|
|
67
|
+
readonly replaceOldRecordsPhone: string;
|
|
68
|
+
answersAt(principal: string): { before: string; after: string };
|
|
69
|
+
redirectsFrom(other: string | null, platform: boolean): { before: string; after: string };
|
|
70
|
+
otherNamePhone(principal: 'root' | 'www'): string;
|
|
71
|
+
removedTitle(count: number): string;
|
|
72
|
+
removedLine(date: string, by: string | null): string;
|
|
73
|
+
readonly restore: string;
|
|
74
|
+
/** The language the removal date is written in (a BCP 47 tag). */
|
|
75
|
+
readonly locale: string;
|
|
76
|
+
readonly removeFromList: string;
|
|
77
|
+
readonly removeConsequence: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** One language's pack for the screen. */
|
|
81
|
+
export interface TenantDomainsCopy {
|
|
82
|
+
records: TenantDomainRecordsCopy;
|
|
83
|
+
pair: TenantDomainPairCopy;
|
|
84
|
+
/** The accessible name of an alert's close button. */
|
|
85
|
+
closeAlert: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
type Kind = 'text' | 'sentence';
|
|
89
|
+
|
|
90
|
+
export const TENANT_DOMAINS_COPY_SHAPE = {
|
|
91
|
+
records: {
|
|
92
|
+
awaitingVerification: 'text',
|
|
93
|
+
verificationFailed: 'text',
|
|
94
|
+
verified: 'text',
|
|
95
|
+
active: 'text',
|
|
96
|
+
disabled: 'text',
|
|
97
|
+
dnsNotHereYet: 'sentence',
|
|
98
|
+
removeTitle: 'text',
|
|
99
|
+
placeholder: 'text',
|
|
100
|
+
emptyTitle: 'text',
|
|
101
|
+
emptyBody: 'text',
|
|
102
|
+
recordType: 'text',
|
|
103
|
+
recordName: 'text',
|
|
104
|
+
recordValue: 'text',
|
|
105
|
+
txtStep: 'text',
|
|
106
|
+
kindApex: 'text',
|
|
107
|
+
kindSubdomain: 'text',
|
|
108
|
+
yourCase: 'text',
|
|
109
|
+
apexGuide: 'sentence',
|
|
110
|
+
subdomainGuide: 'sentence',
|
|
111
|
+
otherApexGuide: 'sentence',
|
|
112
|
+
otherSubdomainGuide: 'sentence',
|
|
113
|
+
fullNameFallback: 'sentence',
|
|
114
|
+
pointWithRecord: 'sentence',
|
|
115
|
+
pointWithRecords: 'text',
|
|
116
|
+
recordLabel: 'sentence',
|
|
117
|
+
notPointedWarning: 'text',
|
|
118
|
+
copyValue: 'text',
|
|
119
|
+
copiedValue: 'text',
|
|
120
|
+
copyValueLabel: 'sentence',
|
|
121
|
+
verifyAction: 'text',
|
|
122
|
+
removeAction: 'text',
|
|
123
|
+
},
|
|
124
|
+
pair: {
|
|
125
|
+
pairAnnouncement: 'sentence',
|
|
126
|
+
pairName: 'sentence',
|
|
127
|
+
principalQuestion: 'text',
|
|
128
|
+
principalRootPhone: 'text',
|
|
129
|
+
principalWwwPhone: 'text',
|
|
130
|
+
principalChangeActive: 'text',
|
|
131
|
+
txtStepPair: 'text',
|
|
132
|
+
txtStepPairPhone: 'text',
|
|
133
|
+
pointBothNames: 'text',
|
|
134
|
+
replaceOldRecords: 'text',
|
|
135
|
+
replaceOldRecordsPhone: 'text',
|
|
136
|
+
answersAt: 'sentence',
|
|
137
|
+
redirectsFrom: 'sentence',
|
|
138
|
+
otherNamePhone: 'sentence',
|
|
139
|
+
removedTitle: 'sentence',
|
|
140
|
+
removedLine: 'sentence',
|
|
141
|
+
restore: 'text',
|
|
142
|
+
locale: 'text',
|
|
143
|
+
removeFromList: 'text',
|
|
144
|
+
removeConsequence: 'text',
|
|
145
|
+
},
|
|
146
|
+
closeAlert: 'text',
|
|
147
|
+
} as const satisfies {
|
|
148
|
+
records: { [K in keyof TenantDomainRecordsCopy]-?: Kind };
|
|
149
|
+
pair: { [K in keyof TenantDomainPairCopy]-?: Kind };
|
|
150
|
+
closeAlert: Kind;
|
|
151
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@12-apps/tenant/domains/react`: the custom-domains screen. Every word is
|
|
3
|
+
* the host's pack and the two widgets that carry the host's own words and look
|
|
4
|
+
* (a confirm-gated button, a one-line choice) are injected, so the package
|
|
5
|
+
* ships the screen's structure, not its language or chrome.
|
|
6
|
+
*
|
|
7
|
+
* Needs `react`, `@12-apps/ui` and `@mui/icons-material` (optional peers);
|
|
8
|
+
* `@12-apps/tenant/react` keeps needing none of them.
|
|
9
|
+
*/
|
|
10
|
+
export { createDomainsScreen, validateDomainsScreen, type TenantDomainsScreenConfig } from './screen';
|
|
11
|
+
export {
|
|
12
|
+
PairAnnouncement,
|
|
13
|
+
type DomainsCardProps,
|
|
14
|
+
type TenantDomainRefusal,
|
|
15
|
+
type TenantDomainWrite,
|
|
16
|
+
type TenantDomainWrites,
|
|
17
|
+
} from './card';
|
|
18
|
+
export {
|
|
19
|
+
type TenantDomainItem,
|
|
20
|
+
type TenantDomainItemRecord,
|
|
21
|
+
type TenantDomainsComponents,
|
|
22
|
+
type TenantDomainsConfirmButton,
|
|
23
|
+
type TenantDomainsSegmented,
|
|
24
|
+
} from './context';
|
|
25
|
+
export {
|
|
26
|
+
TENANT_DOMAINS_COPY_SHAPE,
|
|
27
|
+
type TenantDomainPairCopy,
|
|
28
|
+
type TenantDomainRecordsCopy,
|
|
29
|
+
type TenantDomainsCopy,
|
|
30
|
+
} from './copy';
|
|
31
|
+
export {
|
|
32
|
+
PairPointingRecord,
|
|
33
|
+
PointingRecord,
|
|
34
|
+
PointingWarning,
|
|
35
|
+
VerificationRecord,
|
|
36
|
+
domainName,
|
|
37
|
+
pointingRecordType,
|
|
38
|
+
removalConsequence,
|
|
39
|
+
statusLabelFor,
|
|
40
|
+
type PointingRecordType,
|
|
41
|
+
} from './records';
|