import {z} from 'zod' export type GetApiV1ShopsShopIdWhitelistArgs = {body: {page?: (number | null) | undefined, perPage?: (number | null) | undefined, orderColumn?: ('id' | 'value' | 'type' | 'reason' | 'enabled' | 'created_at' | null) | undefined, orderDirection?: ('asc' | 'desc' | null) | undefined, id?: (string | null) | undefined, types?: (Array<'email' | 'email_domain' | 'discord_id' | 'country_code' | 'city' | 'ip' | 'ip_range' | 'isp' | 'asn' | 'user_agent'>) | undefined, value?: (string | null) | undefined, reason?: (string | null) | undefined, payment_method_ids?: (Record | null) | undefined, enabled?: (boolean | null) | undefined, active_from?: (string | null) | undefined, active_to?: (string | null) | undefined, created_at_from?: (string | null) | undefined, created_at_to?: (string | null) | undefined}}; export type GetApiV1ShopsShopIdWhitelistOptions = {baseUrl?: string | undefined, defaultValue?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1ShopsShopIdWhitelistResponse = z.object({current_page: z.number().int().optional(), data: z.array(z.object({id: z.number().int().optional(), shop_id: z.number().int().optional(), type: z.string().optional(), value: z.string().optional(), payment_method_ids: z.string().nullable().optional(), reason: z.string().optional(), enabled: z.boolean().optional(), active_from: z.string().nullable().optional(), active_to: z.string().nullable().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), deleted_at: z.string().nullable().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 Whitelist * * GET /v1/shops/{shopId}/whitelist */ export const getApiV1ShopsShopIdWhitelist = async (args: GetApiV1ShopsShopIdWhitelistArgs, options?: GetApiV1ShopsShopIdWhitelistOptions) => { 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))}/whitelist${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(getApiV1ShopsShopIdWhitelistResponse, await res.json()) };