import {z} from 'zod' export type GetApiPagesFaqArgs = {language?: string | undefined, include_inactive?: boolean | undefined, fallback?: boolean | undefined}; export type GetApiPagesFaqOptions = {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 }; /** * List Faq Pages * * GET /pages/faq */ export const getApiPagesFaq = async (args: GetApiPagesFaqArgs, options: GetApiPagesFaqOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.language != null) query.append("language", String(args.language)) if (args.include_inactive != null) query.append("include_inactive", String(args.include_inactive)) if (args.fallback != null) query.append("fallback", String(args.fallback)) if (APIKeyHeader !== undefined) headers.set("X-API-Key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/pages/faq${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) 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()) };