import {z} from "zod" import { ChromePdfRenderOptions, HttpLoginCredentials, WaitFor, WaitForHtmlQuerySelector, WaitForJavaScript, WaitForNetworkIdle0, WaitForNetworkIdle2, WaitForNetworkIdleN, WaitForPageLoad, WaitForRenderDelay, WaitForType } from "../../public/render"; import {cssMediaTypeSchema, fitToPaperModesSchema, marginConfigSchema, useMarginsSchema, tableOfContentsTypesSchema} from "./typeSchema"; import {pdfPaperOrientationSchema, pdfPaperSizeSchema} from "./paperSchema"; import {htmlAffixSchema, textAffixSchema} from "./affixSchema"; export const waitForTypeSchema : z.ZodType = z.nativeEnum(WaitForType) export const waitForRenderDelaySchema: z.ZodType = z.object({ type: z.literal(WaitForType.RenderDelay), delay: z .number() .optional() }) export const waitForJavaScriptSchema: z.ZodType = z.object({ type: z.literal(WaitForType.JavaScript), maxWaitTime: z .number() .optional() }) export const waitForNetworkIdleNSchema : z.ZodType = z.object({ type: z.literal(WaitForType.NetworkIdleN), networkIdleDuration: z.number().optional(), maxNumAllowedInflight: z.number().optional(), maxWaitTime: z.number().optional() }) export const waitForNetworkIdle0Schema : z.ZodType = z.object({ type: z.literal(WaitForType.NetworkIdle0), maxWaitTime: z .number() .optional() }) export const waitForNetworkIdle2Schema : z.ZodType = z.object({ type: z.literal(WaitForType.NetworkIdle2), maxWaitTime: z .number() .optional() }) export const waitForPageLoadSchema : z.ZodType = z.object({ type: z.literal(WaitForType.PageLoad) }) export const waitForHtmlQuerySelectorSchema : z.ZodType = z.object({ type: z.literal(WaitForType.HtmlElement), htmlQueryStr: z.string(), maxWaitTime: z .number() .optional() }) export const waitForSchema : z.ZodType = z.union([ waitForRenderDelaySchema, waitForPageLoadSchema, waitForJavaScriptSchema, waitForNetworkIdleNSchema, waitForNetworkIdle0Schema, waitForNetworkIdle2Schema, waitForHtmlQuerySelectorSchema ]) export const httpLoginCredentialsSchema : z.ZodType = z.object({ custom_cookies: z.map(z.string(),z.string()).optional(), enable_cookies: z.boolean().optional(), network_password: z.string().optional(), network_username: z.string().optional() }) export const chromePdfRenderOptionsSchema : z.ZodType = z.object({ createPdfFormsFromHtml: z.boolean().optional(), customCssUrl: z.string().optional(), enableJavaScript: z.boolean().optional(), fitToPaperMode: fitToPaperModesSchema.optional(), grayScale: z.boolean().optional(), margin: marginConfigSchema.optional(), paperOrientation: pdfPaperOrientationSchema.optional(), paperSize: pdfPaperSizeSchema.optional(), printHtmlBackgrounds: z.boolean().optional(), timeout: z.number().positive().optional(), waitFor: waitForSchema.optional(), title: z.string().optional(), inputEncoding: z.string().optional(), cssMediaType: cssMediaTypeSchema.optional(), javascript: z.string().optional(), firstPageNumber: z.number().optional(), tableOfContents: tableOfContentsTypesSchema.optional(), htmlHeader:htmlAffixSchema.optional(), htmlFooter:htmlAffixSchema.optional(), textHeader:textAffixSchema.optional(), textFooter:textAffixSchema.optional(), useMarginsOnHeaderAndFooter: useMarginsSchema.optional() })