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);
34
35// --- per-repo static site config (org.tangled.temp.repo.*) ---
36
37// mirrors org.tangled.temp.repo.getSiteConfig#siteConfig. an index site is
38// served at the root of the owner's sites domain; otherwise under the repo name.
39export interface RepoSiteConfig {
40 branch: string;
41 dir: string;
42 isIndex: boolean;
43}
44
45const GET_SITE_CONFIG = "org.tangled.temp.repo.getSiteConfig";
46const UPDATE_SITE_CONFIG = "org.tangled.temp.repo.updateSiteConfig";
47const DISABLE_SITE = "org.tangled.temp.repo.disableSite";
48
49// returns the repo's site config, or null when no site is configured.
50export const getRepoSiteConfig = async (
51 ctx: AppviewContext,
52 repoDid: string,
53 init?: XrpcRequestInit
54): Promise<RepoSiteConfig | null> => {
55 const res = await authedGet<{ config?: RepoSiteConfig }>(
56 ctx,
57 GET_SITE_CONFIG,
58 { repoDid },
59 init
60 );
61 return res.config ?? null;
62};
63
64// requires the owner to have an active sites domain claim.
65export const updateRepoSiteConfig = (
66 ctx: AppviewContext,
67 repoDid: string,
68 input: { branch: string; dir: string; isIndex?: boolean },
69 init?: XrpcRequestInit
70): Promise<void> =>
71 authedPost(ctx, UPDATE_SITE_CONFIG, { repoDid, ...input }, init).then(() => undefined);
72
73export const disableRepoSite = (
74 ctx: AppviewContext,
75 repoDid: string,
76 init?: XrpcRequestInit
77): Promise<void> => authedPost(ctx, DISABLE_SITE, { repoDid }, init).then(() => undefined);