import {z} from 'zod' export type DateTime = string; export type GtdRegion = {gtdLocationId?: number | undefined, regionName?: string | undefined, regionLabel?: string | undefined}; export type ARecordWithoutIdValues = {id?: number | undefined, ip?: string | undefined, enabled?: boolean | undefined, sortOrder?: number | undefined}; export type ARecordWithoutId = {name?: string | undefined, type?: string | undefined, enabled?: boolean | undefined, createdTs?: DateTime | undefined, modifiedTs?: DateTime | undefined, systemFlag?: boolean | undefined, ttl?: number | undefined, region?: GtdRegion | undefined, values?: Array | undefined}; export type CreateApiDomainsPrimaryDomainIdRecordsAArgs = {domainId: number, body: ARecordWithoutId}; export type CreateApiDomainsPrimaryDomainIdRecordsAOptions = {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 aRecordWithoutIdValues = z.object({id: z.number().int().optional(), ip: z.string().optional(), enabled: z.boolean().optional(), sortOrder: z.number().int().optional()}); export const aRecord = z.object({id: z.number().int().optional(), name: z.string().optional(), type: z.string().optional(), enabled: z.boolean().optional(), createdTs: dateTime.optional(), modifiedTs: dateTime.optional(), systemFlag: z.boolean().optional(), ttl: z.number().int().optional(), region: gtdRegion.optional(), values: z.array(aRecordWithoutIdValues).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 A record for a specific primary domain. * * POST /domains/primary/{domainId}/records/A */ export const createApiDomainsPrimaryDomainIdRecordsA = async (args: CreateApiDomainsPrimaryDomainIdRecordsAArgs, options?: CreateApiDomainsPrimaryDomainIdRecordsAOptions) => { 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/A${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(aRecord, await res.json()) };