import {z} from 'zod' export type CreateApiV1AiGenerateSitemapArgs = {'x-api-key': string, body: {website_id: number, params: {business_type: string, business_name: string, business_description: string}}}; export type CreateApiV1AiGenerateSitemapOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1AiGenerateSitemapResponse = z.object({msg: z.string().optional(), status: z.number().int().optional(), data: z.object({business_description: z.string().optional(), business_name: z.string().optional(), business_type: z.string().optional(), colors: z.object({background_dark: z.string().optional(), primary_color: z.string().optional(), secondary_color: z.string().optional()}).optional(), website_id: z.number().int().optional(), fonts: z.object({primary_font: z.string().optional()}).optional(), pages_meta: z.array(z.object({description: z.string().optional(), sections: z.array(z.object({section_description: z.string().optional(), section_title: z.string().optional()})).optional(), title: z.string().optional()})).optional(), unique_id: z.string().optional(), website_description: z.string().optional(), website_keyphrase: z.string().optional(), website_title: z.string().optional(), website_type: z.string().optional()}).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 }; /** * Generate outline, styles, and secondary pages from a given business description * * POST /v1/ai/generate_sitemap */ export const createApiV1AiGenerateSitemap = async (args: CreateApiV1AiGenerateSitemapArgs, options?: CreateApiV1AiGenerateSitemapOptions) => { const {baseUrl = "https://api.10web.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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/ai/generate_sitemap${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(createApiV1AiGenerateSitemapResponse, await res.json()) };