import {z} from 'zod' export type GetApiV1ShopsShopIdFeedbacksArgs = {body: {page?: (number | null) | undefined, perPage?: (number | null) | undefined, orderColumn?: ('status' | 'rating' | 'reply' | 'created_at' | 'updated_at' | null) | undefined, orderDirection?: ('asc' | 'desc' | null) | undefined, id?: (string | null) | undefined, statuses?: (Array<'published' | 'disputed' | 'removed'>) | undefined, invoice_id?: (string | null) | undefined, rating?: (number | null) | undefined, invoice_email?: (string | null) | undefined, message_keyword?: (string | null) | undefined, is_automatic?: (boolean | null) | undefined, created_at_start?: (string | null) | undefined, created_at_end?: (string | null) | undefined, reply_keyword?: (string | null) | undefined, has_reply?: (boolean | null) | undefined, product_name?: (string | null) | undefined, variant_name?: (string | null) | undefined, product_id?: (string | null) | undefined, variant_id?: (string | null) | undefined}}; export type GetApiV1ShopsShopIdFeedbacksOptions = {baseUrl?: string | undefined, defaultValue?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1ShopsShopIdFeedbacksResponse = z.object({current_page: z.number().int().optional(), data: z.array(z.object({id: z.number().int().optional(), invoice_id: z.number().int().optional(), status: z.string().optional(), message: z.string().optional(), image: z.string().nullable().optional(), rating: z.number().int().optional(), is_automatic: z.boolean().optional(), reply: z.string().nullable().optional(), dispute_reason: z.string().nullable().optional(), disputed_at: z.string().nullable().optional(), replied_at: z.string().nullable().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), deleted_at: z.string().nullable().optional(), image_url: z.string().nullable().optional(), invoice: z.object({id: z.number().int().optional(), salt: z.string().optional(), email: z.string().optional(), shop_customer_id: z.number().int().optional(), unique_id: z.string().optional(), customer: z.object({id: z.number().int().optional(), username: z.string().nullable().optional(), anonymous_feedback: z.boolean().optional(), username_locked_at: z.string().nullable().optional()}).optional(), items: z.array(z.object({id: z.number().int().optional(), invoice_id: z.number().int().optional(), product_id: z.number().int().optional(), variant_id: z.number().int().optional(), custom_name: z.string().nullable().optional(), product: z.object({id: z.number().int().optional(), name: z.string().optional()}).optional(), variant: z.object({id: z.number().int().optional(), name: z.string().optional()}).optional()})).optional()}).optional()})).optional(), first_page_url: z.string().optional(), from: z.number().int().optional(), last_page: z.number().int().optional(), last_page_url: z.string().optional(), links: z.array(z.object({url: z.string().nullable().optional(), label: z.string().optional(), page: z.string().nullable().optional(), active: z.boolean().optional()})).optional(), next_page_url: z.string().nullable().optional(), path: z.string().optional(), per_page: z.number().int().optional(), prev_page_url: z.string().nullable().optional(), to: z.number().int().optional(), total: 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 }; /** * Get Feedbacks * * GET /v1/shops/{shopId}/feedbacks */ export const getApiV1ShopsShopIdFeedbacks = async (args: GetApiV1ShopsShopIdFeedbacksArgs, options?: GetApiV1ShopsShopIdFeedbacksOptions) => { const {baseUrl = "https://api.sellauth.com", fetch: fetchFn = fetch, defaultValue} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (defaultValue !== undefined) headers.set('authorization', `Bearer ${defaultValue}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/shops/${encodeURIComponent(String(args.shopId))}/feedbacks${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(getApiV1ShopsShopIdFeedbacksResponse, await res.json()) };