import {z} from 'zod' export type GetApiV1ShopsShopIdCouponsCouponIdOptions = {baseUrl?: string | undefined, defaultValue?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1ShopsShopIdCouponsCouponIdResponse = z.object({id: z.number().int().optional(), code: z.string().optional(), salt: z.string().optional(), global: z.boolean().optional(), discount: z.string().optional(), uses: z.number().int().optional(), max_uses: z.string().nullable().optional(), max_uses_per_customer: z.string().nullable().optional(), min_invoice_price: z.string().nullable().optional(), allowed_emails: z.string().nullable().optional(), payment_method_ids: z.string().nullable().optional(), disable_if_volume_discount: z.boolean().optional(), disable_if_bundle_offer: z.boolean().optional(), disable_if_quantity_deal: z.boolean().optional(), disable_if_gateway_discount: z.boolean().optional(), disable_if_affiliate_discount: z.boolean().optional(), disable_if_reseller_discount: z.boolean().optional(), uses_count_mode: z.string().optional(), type: z.string().optional(), start_date: z.string().nullable().optional(), expiration_date: z.string().nullable().optional(), shop_id: z.number().int().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), applies_to_renewals: z.boolean().optional(), items: z.array(z.unknown()).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 Coupon * * GET /v1/shops/{shopId}/coupons/{couponId} */ export const getApiV1ShopsShopIdCouponsCouponId = async (options?: GetApiV1ShopsShopIdCouponsCouponIdOptions) => { 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))}/coupons/${encodeURIComponent(String(args.couponId))}${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(getApiV1ShopsShopIdCouponsCouponIdResponse, await res.json()) };