import {z} from 'zod' export type GetApiV1ShopsShopIdFeedbacksFeedbackIdOptions = {baseUrl?: string | undefined, defaultValue?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1ShopsShopIdFeedbacksFeedbackIdResponse = z.object({feedback: z.object({id: z.number().int().optional(), salt: z.string().optional(), shop_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(), edit_count: z.number().int().optional(), reply: z.string().nullable().optional(), dispute_reason: z.string().nullable().optional(), disputed_at: z.string().nullable().optional(), created_at: z.string().optional(), edited_at: z.string().nullable().optional(), updated_at: z.string().optional(), replied_at: z.string().nullable().optional(), deleted_at: z.string().nullable().optional(), image_url: z.string().nullable().optional()}).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 Feedback * * GET /v1/shops/{shopId}/feedbacks/{feedbackId} */ export const getApiV1ShopsShopIdFeedbacksFeedbackId = async (options?: GetApiV1ShopsShopIdFeedbacksFeedbackIdOptions) => { const {baseUrl = "https://api.sellauth.com", fetch: fetchFn = fetch, defaultValue} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (defaultValue !== undefined) headers.set('authorization', `Bearer ${defaultValue}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/shops/${encodeURIComponent(String(args.shopId))}/feedbacks/${encodeURIComponent(String(args.feedbackId))}${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(getApiV1ShopsShopIdFeedbacksFeedbackIdResponse, await res.json()) };