import {z} from 'zod' export type PageParametersUpdate = {name?: string | undefined, description?: (string | null) | undefined, sort_order?: number | undefined, funnel?: ({show_page_step_id?: (number | string) | undefined}) | undefined, current_path?: string | undefined, custom_html?: string | undefined, seo_title?: (string | null) | undefined, seo_description?: (string | null) | undefined, seo_index?: boolean | undefined, block_ai_crawler?: boolean | undefined, block_ai_search?: boolean | undefined, block_ai_assistant?: boolean | undefined, head_code?: (string | null) | undefined, head_code_mode?: ('append' | 'replace') | undefined, footer_code?: (string | null) | undefined, footer_code_mode?: ('append' | 'replace') | undefined, custom_css?: (string | null) | undefined, custom_css_mode?: ('append' | 'replace') | undefined, markup?: string | undefined, external_url?: string | undefined, show_page_step?: ({product_ids?: Array | undefined, bumps?: (Array<{product_id: string, preheadline?: string | undefined}>) | undefined}) | undefined}; export type UpdateApiPagesIdArgs = {id: string, 'expand[]'?: (Array<'head_code' | 'footer_code' | 'custom_css' | 'markup'>) | undefined, body: {page?: PageParametersUpdate | undefined}}; export type UpdateApiPagesIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const pageAttributes = z.object({id: z.number().int().optional(), public_id: z.string().optional(), workspace_id: z.number().int().optional(), name: z.string().optional(), description: z.string().nullable().optional(), theme_id: z.number().int().nullable().optional(), created_at: z.string().optional(), seo_title: z.string().nullable().optional(), seo_description: z.string().nullable().optional(), seo_index: z.boolean().optional(), block_ai_crawler: z.boolean().optional(), block_ai_search: z.boolean().optional(), block_ai_assistant: z.boolean().optional(), updated_at: z.string().optional(), type: z.enum(["landing_page", "site_page", "funnel_page", "theme_page", "null"]).nullable().optional(), custom_html_page: z.boolean().optional(), current_path: z.string().nullable().optional(), url: z.string().nullable().optional(), show_page_step: z.object({id: z.number().int().optional(), public_id: z.string().optional(), name: z.string().optional(), current_path: z.string().nullable().optional(), sort_order: z.number().int().optional(), products: z.array(z.object({id: z.number().int().optional(), public_id: z.string().optional(), name: z.string().optional(), bump: z.boolean().optional(), bump_preheadline: z.string().nullable().optional()})).optional()}).nullable().optional(), funnel: z.object({id: z.number().int().optional(), public_id: z.string().optional(), name: z.string().optional()}).nullable().optional(), sdk: z.object({token: z.string().optional(), external_url: z.string().optional()}).nullable().optional(), head_code: z.string().nullable().optional(), footer_code: z.string().nullable().optional(), custom_css: z.string().nullable().optional(), markup: z.string().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 }; /** * Update Page * * PUT /pages/{id} * * Also accepts auth: OAuth2 */ export const updateApiPagesId = async (args: UpdateApiPagesIdArgs, options?: UpdateApiPagesIdOptions) => { const {baseUrl = "https://myworkspace.myclickfunnels.com/api/v2", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") for (const item of args['expand[]'] ?? []) query.append("expand[]", String(item)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/pages/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(pageAttributes, await res.json()) };