import {z} from 'zod' export type DateTime = string; export type GtdRegion = {gtdLocationId?: number | undefined, regionName?: string | undefined, regionLabel?: string | undefined}; export type AAAARecordWithoutIdValues = {id?: number | undefined, ip?: string | undefined, enabled?: boolean | undefined, sortOrder?: number | undefined}; export type AAAARecordWithoutId = {name?: string | undefined, type?: string | undefined, enabled?: boolean | undefined, ttl?: number | undefined, createdTs?: DateTime | undefined, modifiedTs?: DateTime | undefined, systemFlag?: boolean | undefined, region?: GtdRegion | undefined, values?: Array | undefined}; export type CreateApiDomainsPrimaryDomainIdRecordsAAAAArgs = {domainId: number, body: AAAARecordWithoutId}; export type CreateApiDomainsPrimaryDomainIdRecordsAAAAOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const dateTime = z.string(); export const gtdRegion = z.object({gtdLocationId: z.number().int().optional(), regionName: z.string().optional(), regionLabel: z.string().optional()}); export const aAAARecordWithoutIdValues = z.object({id: z.number().int().optional(), ip: z.string().optional(), enabled: z.boolean().optional(), sortOrder: z.number().int().optional()}); export const aAAARecord = z.object({id: z.number().int().optional(), name: z.string().optional(), type: z.string().optional(), enabled: z.boolean().optional(), ttl: z.number().int().optional(), createdTs: dateTime.optional(), modifiedTs: dateTime.optional(), systemFlag: z.boolean().optional(), region: gtdRegion.optional(), values: z.array(aAAARecordWithoutIdValues).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 }; /** * Creates an AAAA record for a specific primary domain. * * POST /domains/primary/{domainId}/records/AAAA */ export const createApiDomainsPrimaryDomainIdRecordsAAAA = async (args: CreateApiDomainsPrimaryDomainIdRecordsAAAAArgs, options?: CreateApiDomainsPrimaryDomainIdRecordsAAAAOptions) => { const {baseUrl = "https://manager.digicertdns.com/v1", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/domains/primary/${encodeURIComponent(String(args.domainId))}/records/AAAA${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 validateResponse(aAAARecord, await res.json()) };