import {z} from 'zod' export type CustomUiNavItem = {label?: string | undefined, url?: string | undefined}; export type CustomUiUpdateRequest = {banner_url?: (string | null) | undefined, banner_style?: (string | null) | undefined, banner_title?: (string | null) | undefined, banner_subtext?: (string | null) | undefined, banner_title_color?: (string | null) | undefined, banner_bg_color?: (string | null) | undefined, header_nav_items?: (Array | null) | undefined, footer_text?: (string | null) | undefined}; export type PatchApiBlogsCustomUiArgs = {body: CustomUiUpdateRequest}; export type PatchApiBlogsCustomUiOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const customUiNavItem = z.object({label: z.string().optional(), url: z.string().optional()}); export const customUiResponse = z.object({banner_url: z.string().nullable().optional(), banner_style: z.string().nullable().optional(), banner_title: z.string().nullable().optional(), banner_subtext: z.string().nullable().optional(), banner_title_color: z.string().nullable().optional(), banner_bg_color: z.string().nullable().optional(), header_nav_items: z.array(customUiNavItem).nullable().optional(), footer_text: z.string().nullable().optional()}); export const customUiEnvelopeResponse = z.object({data: customUiResponse.nullable()}); 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 Banner & UI Settings * * PATCH /blogs/custom-ui */ export const patchApiBlogsCustomUi = async (args: PatchApiBlogsCustomUiArgs, options?: PatchApiBlogsCustomUiOptions) => { const {baseUrl = "https://inblog.ai/api/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(/\/+$/, '')}/blogs/custom-ui${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(customUiEnvelopeResponse, await res.json()) };