import { authedGet, authedPost, type AppviewContext } from "./appview"; import type { XrpcRequestInit } from "./client"; // org.tangled.temp.site.getDomainClaim — domain is absent when unclaimed. interface DomainClaimResponse { domain?: string; } const GET_DOMAIN_CLAIM = "org.tangled.temp.site.getDomainClaim"; const CLAIM_DOMAIN = "org.tangled.temp.site.claimDomain"; const RELEASE_DOMAIN = "org.tangled.temp.site.releaseDomain"; // returns the user's active sites domain, or null when none is claimed. export const getDomainClaim = async ( ctx: AppviewContext, init?: XrpcRequestInit ): Promise => { const res = await authedGet(ctx, GET_DOMAIN_CLAIM, undefined, init); return res.domain ?? null; }; // claims .; the server appends the configured suffix. export const claimDomain = ( ctx: AppviewContext, subdomain: string, init?: XrpcRequestInit ): Promise => authedPost(ctx, CLAIM_DOMAIN, { subdomain }, init).then(() => undefined); export const releaseDomain = ( ctx: AppviewContext, domain: string, init?: XrpcRequestInit ): Promise => authedPost(ctx, RELEASE_DOMAIN, { domain }, init).then(() => undefined); // --- per-repo static site config (org.tangled.temp.repo.*) --- // mirrors org.tangled.temp.repo.getSiteConfig#siteConfig. an index site is // served at the root of the owner's sites domain; otherwise under the repo name. export interface RepoSiteConfig { branch: string; dir: string; isIndex: boolean; } const GET_SITE_CONFIG = "org.tangled.temp.repo.getSiteConfig"; const UPDATE_SITE_CONFIG = "org.tangled.temp.repo.updateSiteConfig"; const DISABLE_SITE = "org.tangled.temp.repo.disableSite"; // returns the repo's site config, or null when no site is configured. export const getRepoSiteConfig = async ( ctx: AppviewContext, repoDid: string, init?: XrpcRequestInit ): Promise => { const res = await authedGet<{ config?: RepoSiteConfig }>( ctx, GET_SITE_CONFIG, { repoDid }, init ); return res.config ?? null; }; // requires the owner to have an active sites domain claim. export const updateRepoSiteConfig = ( ctx: AppviewContext, repoDid: string, input: { branch: string; dir: string; isIndex?: boolean }, init?: XrpcRequestInit ): Promise => authedPost(ctx, UPDATE_SITE_CONFIG, { repoDid, ...input }, init).then(() => undefined); export const disableRepoSite = ( ctx: AppviewContext, repoDid: string, init?: XrpcRequestInit ): Promise => authedPost(ctx, DISABLE_SITE, { repoDid }, init).then(() => undefined);