export type CreateDomainDto = {domainName: string, clientId: string}; export type CreateApiApiDomainsArgs = {body: CreateDomainDto}; export type CreateApiApiDomainsOptions = {baseUrl: string, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create a new domain with access key * * POST /api/domains */ export const createApiApiDomains = async (args: CreateApiApiDomainsArgs, options: CreateApiApiDomainsOptions) => { const {baseUrl, fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (apiKey !== undefined) headers.set("X-API-Key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/domains${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };