import {z} from 'zod' export type DeleteApiV1ClientDomainsClientDomainIdArgs = {client_domain_id: string, force?: boolean | undefined}; export type DeleteApiV1ClientDomainsClientDomainIdOptions = {baseUrl?: string | undefined, HEADER?: string | undefined, fetch?: typeof fetch | undefined}; export const clientDomainGlobPatternResponse = z.object({pattern: z.string().optional(), regex: z.string().optional(), type: z.enum(["DOMAIN", "GLOB", "SUB_DOMAIN"]).optional()}); export const clientDomainResponse = z.object({cname_target: z.string(), domain: z.string(), id: z.string(), is_extole_domain: z.boolean(), name: z.string(), proxy: z.boolean(), redirect_client_domain_id: z.string(), secure: z.boolean(), share_uri: z.string(), site_patterns: z.array(clientDomainGlobPatternResponse), ssl_certificate: z.string(), ssl_certificate_chain: z.string(), ssl_generation_policy: z.enum(["DISABLED", "GENERATE", "GENERATE_FORCE", "PROVIDED"]), ssl_private_key: z.string()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Archive client domain * * DELETE /v1/client-domains/{client_domain_id} * * Also accepts auth: QUERY, COOKIE */ export const deleteApiV1ClientDomainsClientDomainId = async (args: DeleteApiV1ClientDomainsClientDomainIdArgs, options?: DeleteApiV1ClientDomainsClientDomainIdOptions) => { const {baseUrl = "https://api.extole.io", fetch: fetchFn = fetch, HEADER} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.force != null) query.append("force", String(args.force)) if (HEADER !== undefined) headers.set("Authorization", HEADER) const url = `${baseUrl.replace(/\/+$/, '')}/v1/client-domains/${encodeURIComponent(String(args.client_domain_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(clientDomainResponse, await res.json()) };