import {z} from 'zod' export type GetApiAdminPagesPlusBaseJsonArgs = {limit?: number | undefined, since_id?: number | undefined, title?: string | undefined, handle?: string | undefined, created_at_min?: string | undefined, created_at_max?: string | undefined, updated_at_min?: string | undefined, updated_at_max?: string | undefined, published_at_min?: string | undefined, fields?: string | undefined, published_status?: string | undefined}; export type GetApiAdminPagesPlusBaseJsonOptions = {baseUrl?: string | undefined, APPACCESSTOKEN?: string | undefined, fetch?: typeof fetch | undefined}; export const page = z.object({body_html: z.string().optional(), handle: z.string().optional(), id: z.number().int().optional(), is_show_in_search: z.boolean().optional(), publish: z.boolean().optional(), search_engine_image: z.string().optional(), search_engine_meta_description: z.string().optional(), search_engine_title: z.string().optional(), tags: z.string().optional(), template: z.string().optional(), title: z.string().optional()}); export const listPagesSwaggerResponse = z.object({pages: z.array(page).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 }; /** * Retrieve a list of all pages * * GET /admin/pages/plus-base.json */ export const getApiAdminPagesPlusBaseJson = async (args: GetApiAdminPagesPlusBaseJsonArgs, options?: GetApiAdminPagesPlusBaseJsonOptions) => { const {baseUrl = "https://shop-name.onshopbase.com", fetch: fetchFn = fetch, APPACCESSTOKEN} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.since_id != null) query.append("since_id", String(args.since_id)) if (args.title != null) query.append("title", String(args.title)) if (args.handle != null) query.append("handle", String(args.handle)) if (args.created_at_min != null) query.append("created_at_min", String(args.created_at_min)) if (args.created_at_max != null) query.append("created_at_max", String(args.created_at_max)) if (args.updated_at_min != null) query.append("updated_at_min", String(args.updated_at_min)) if (args.updated_at_max != null) query.append("updated_at_max", String(args.updated_at_max)) if (args.updated_at_max != null) query.append("updated_at_max", String(args.updated_at_max)) if (args.published_at_min != null) query.append("published_at_min", String(args.published_at_min)) if (args.fields != null) query.append("fields", String(args.fields)) if (args.published_status != null) query.append("published_status", String(args.published_status)) if (APPACCESSTOKEN !== undefined) headers.set("APP_ACCESS_TOKEN", APPACCESSTOKEN) const url = `${baseUrl.replace(/\/+$/, '')}/admin/pages/plus-base.json${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(listPagesSwaggerResponse, await res.json()) };