import {z} from 'zod' export type CreateApiDomainsIdDkimRotateActivateArgs = {id: string, force?: ('true' | 'false') | undefined}; export type CreateApiDomainsIdDkimRotateActivateOptions = {baseUrl?: string | undefined, bearerApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const dkimRotation = z.object({domainId: z.number().int(), state: z.enum(["idle", "pending_dns", "ready", "retiring"]), activeSelector: z.string().nullable().optional(), pendingSelector: z.string().nullable().optional(), pendingPublicKey: z.string().nullable().optional(), pendingRecordName: z.string().nullable().optional(), pendingRecordValue: z.string().nullable().optional(), startedAt: z.string().nullable().optional(), publishedAt: z.string().nullable().optional(), activatesAfter: z.string().nullable().optional(), retiredSelector: z.string().nullable().optional(), retireAfter: z.string().nullable().optional()}); export const createApiDomainsIdDkimRotateActivateResponse = z.object({rotation: dkimRotation}); 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 }; /** * Activate the staged DKIM key * * POST /domains/{id}/dkim/rotate/activate * * Also accepts auth: bearerOAuth */ export const createApiDomainsIdDkimRotateActivate = async (args: CreateApiDomainsIdDkimRotateActivateArgs, options?: CreateApiDomainsIdDkimRotateActivateOptions) => { const {baseUrl = "https://api.poststack.dev", fetch: fetchFn = fetch, bearerApiKey} = 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 (bearerApiKey !== undefined) headers.set('authorization', `Bearer ${bearerApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/domains/${encodeURIComponent(String(args.id))}/dkim/rotate/activate${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiDomainsIdDkimRotateActivateResponse, await res.json()) };