import {z} from 'zod' export type OrdersSwaggerRequest = {chargeback_deadline_at_max?: string | undefined, chargeback_deadline_at_min?: string | undefined, chargeback_status?: string | undefined, created_at_max?: string | undefined, created_at_min?: string | undefined, customer_email?: string | undefined, customer_id?: number | undefined, fields?: string | undefined, filter_order_risk?: boolean | undefined, financial_status?: string | undefined, fulfilled_at_max?: string | undefined, fulfilled_at_min?: string | undefined, fulfillment_service?: string | undefined, fulfillment_status?: string | undefined, ids?: Array | undefined, limit?: number | undefined, not_product_mapping?: boolean | undefined, not_product_name?: string | undefined, not_product_sku?: string | undefined, not_product_type?: string | undefined, not_product_vendor?: string | undefined, order_status?: string | undefined, page?: number | undefined, product_mapping?: boolean | undefined, product_name?: string | undefined, product_sku?: string | undefined, product_type?: string | undefined, product_vendor?: string | undefined, since_id?: number | undefined, tag?: string | undefined, tracking_number?: string | undefined, updated_at_max?: string | undefined, updated_at_min?: string | undefined}; export type GetApiAdminOrdersCountJsonArgs = {body: OrdersSwaggerRequest}; export type GetApiAdminOrdersCountJsonOptions = {baseUrl?: string | undefined, APPACCESSTOKEN?: string | undefined, fetch?: typeof fetch | undefined}; export const countResponse = z.object({count: z.number().int().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 }; /** * Retrieves an order count * * GET /admin/orders/count.json */ export const getApiAdminOrdersCountJson = async (args: GetApiAdminOrdersCountJsonArgs, options?: GetApiAdminOrdersCountJsonOptions) => { const {baseUrl = "https://shop-name.onshopbase.com", fetch: fetchFn = fetch, APPACCESSTOKEN} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (APPACCESSTOKEN !== undefined) headers.set("APP_ACCESS_TOKEN", APPACCESSTOKEN) const url = `${baseUrl.replace(/\/+$/, '')}/admin/orders/count.json${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", 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(countResponse, await res.json()) };