38fb0f586e
ci / changes (push) Successful in 4s
ci / tc_booking (push) Has been skipped
ci / tc_operator (push) Has been skipped
ci / tc_website (push) Has been skipped
ci / tc_platform_api (push) Has been skipped
ci / test_platform_api (push) Has been skipped
ci / build_booking (push) Has been skipped
ci / build_operator (push) Has been skipped
ci / tc_portal (push) Successful in 22s
ci / build_portal (push) Successful in 44s
ci / build_platform_api (push) Has been skipped
ci / deploy (push) Successful in 40s
DomainView.checks was a hardcoded five-kind union, so indexing it with the
new autodiscovery RecordKey failed the portal typecheck (CI red on
f6bac10). Use Record<RecordKind, RecordStatus>.
69 lines
2.2 KiB
TypeScript
69 lines
2.2 KiB
TypeScript
// Customer-admin email-domain data + mutations, backed by platform-api's
|
|
// /api/tenants/:slug/domains endpoints. Reads use useFetch (SSR-friendly list);
|
|
// writes go through useApiFetch so a lapsed session refreshes silently instead
|
|
// of redirecting away mid-action. Mirrors the read/write split in
|
|
// pages/admin/security.vue.
|
|
|
|
export type RecordStatus = 'ok' | 'warn' | 'bad' | 'pending'
|
|
export type DomainStatus = 'pending' | 'verifying' | 'active' | 'error'
|
|
export type RecordKind = 'ownership' | 'mx' | 'spf' | 'dkim' | 'dmarc' | 'autodiscovery'
|
|
export type DmarcPolicy = 'none' | 'quarantine' | 'reject'
|
|
|
|
export interface DomainRecordView {
|
|
kind: RecordKind
|
|
type: string
|
|
host: string
|
|
fqdn: string
|
|
expected: string
|
|
priority?: number
|
|
observed?: string
|
|
status: RecordStatus
|
|
}
|
|
|
|
export interface DomainView {
|
|
id: string
|
|
domain: string
|
|
isPrimary: boolean
|
|
status: DomainStatus
|
|
ownershipVerified: boolean
|
|
verificationToken: string
|
|
dmarcPolicy: DmarcPolicy
|
|
stalwartProvisioned: boolean
|
|
stalwartError?: string
|
|
mailboxes: number
|
|
checks: Record<RecordKind, RecordStatus>
|
|
records: DomainRecordView[]
|
|
lastCheckedAt?: string
|
|
}
|
|
|
|
export function useDomains() {
|
|
const { tenant } = useTenant()
|
|
const slug = computed(() => tenant.value?.slug ?? '')
|
|
const { request } = useApiFetch()
|
|
|
|
const base = () => `/api/tenants/${slug.value}/domains`
|
|
const one = (domain: string) => `${base()}/${encodeURIComponent(domain)}`
|
|
|
|
const { data: domains, refresh, pending } = useFetch<DomainView[]>(base, {
|
|
key: 'admin-domains',
|
|
default: () => [],
|
|
immediate: !!slug.value,
|
|
watch: [slug],
|
|
})
|
|
|
|
const add = (domain: string) =>
|
|
request<DomainView>(base(), { method: 'POST', body: { domain } })
|
|
|
|
const getOne = (domain: string) => request<DomainView>(one(domain))
|
|
|
|
const recheck = (domain: string) =>
|
|
request<DomainView>(`${one(domain)}/recheck`, { method: 'POST' })
|
|
|
|
const setDmarcPolicy = (domain: string, dmarcPolicy: DmarcPolicy) =>
|
|
request<DomainView>(`${one(domain)}/dmarc`, { method: 'PATCH', body: { dmarcPolicy } })
|
|
|
|
const remove = (domain: string) => request(one(domain), { method: 'DELETE' })
|
|
|
|
return { domains, pending, refresh, slug, add, getOne, recheck, setDmarcPolicy, remove }
|
|
}
|