import {z} from 'zod' export type GetApiV1HostingZoneZoneIdRecordsArgs = {zone_id: number, 'x-api-key': string}; export type GetApiV1HostingZoneZoneIdRecordsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const record = z.object({id: z.number().int().optional(), name: z.string().optional(), value: z.string().optional(), type: z.enum(["SOA", "A", "TXT", "NS", "CNAME", "MX", "NAPTR", "PTR", "SRV", "SPF", "AAAA", "CAA"]).optional(), ttl: z.number().int().optional(), priority: z.number().int().nullable().optional(), port: z.number().int().nullable().optional(), weight: z.number().int().nullable().optional()}); export const getApiV1HostingZoneZoneIdRecordsResponse = z.object({status: z.enum(["ok", "error"]).optional(), data: z.array(record).optional()}); 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 }; /** * Get all DNS records for a zone * * GET /v1/hosting/zone/{zone_id}/records */ export const getApiV1HostingZoneZoneIdRecords = async (args: GetApiV1HostingZoneZoneIdRecordsArgs, options?: GetApiV1HostingZoneZoneIdRecordsOptions) => { const {baseUrl = "https://api.10web.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['x-api-key'] != null) headers.set("x-api-key", String(args['x-api-key'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/hosting/zone/${encodeURIComponent(String(args.zone_id))}/records${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV1HostingZoneZoneIdRecordsResponse, await res.json()) };