This repository has no description
1import { authedGet, authedPost, type AppviewContext } from "./appview";
2import type { XrpcRequestInit } from "./client";
3
4// org.tangled.temp.site.getDomainClaim — domain is absent when unclaimed.
5interface DomainClaimResponse {
6 domain?: string;
7}
8
9const GET_DOMAIN_CLAIM = "org.tangled.temp.site.getDomainClaim";
10const CLAIM_DOMAIN = "org.tangled.temp.site.claimDomain";
11const RELEASE_DOMAIN = "org.tangled.temp.site.releaseDomain";
12
13// returns the user's active sites domain, or null when none is claimed.
14export const getDomainClaim = async (
15 ctx: AppviewContext,
16 init?: XrpcRequestInit
17): Promise<string | null> => {
18 const res = await authedGet<DomainClaimResponse>(ctx, GET_DOMAIN_CLAIM, undefined, init);
19 return res.domain ?? null;
20};
21
22// claims <subdomain>.<sites domain>; the server appends the configured suffix.
23export const claimDomain = (
24 ctx: AppviewContext,
25 subdomain: string,
26 init?: XrpcRequestInit
27): Promise<void> => authedPost(ctx, CLAIM_DOMAIN, { subdomain }, init).then(() => undefined);
28
29export const releaseDomain = (
30 ctx: AppviewContext,
31 domain: string,
32 init?: XrpcRequestInit
33): Promise<void> => authedPost(ctx, RELEASE_DOMAIN, { domain }, init).then(() => undefined);