import {z} from 'zod' export type FaqReorderItem = {id: number, display_order: number}; export type FaqReorderRequest = {language?: string | undefined, items: Array}; export type CreateApiPagesFaqReorderArgs = {body: FaqReorderRequest}; export type CreateApiPagesFaqReorderOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const appWebapiSchemasPagesFaqPageResponse = z.object({id: z.number().int(), language: z.string(), title: z.string(), content: z.string(), content_pages: z.array(z.string()).optional(), display_order: z.number().int(), is_active: z.boolean(), created_at: z.string(), updated_at: z.string()}); export const faqPageListResponse = z.object({requested_language: z.string(), language: z.string(), is_enabled: z.boolean(), total: z.number().int(), items: z.array(appWebapiSchemasPagesFaqPageResponse)}); 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 }; /** * Reorder Faq Pages * * POST /pages/faq/reorder */ export const createApiPagesFaqReorder = async (args: CreateApiPagesFaqReorderArgs, options: CreateApiPagesFaqReorderOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (APIKeyHeader !== undefined) headers.set("X-API-Key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/pages/faq/reorder${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(faqPageListResponse, await res.json()) };