import {z} from 'zod' export type GetApiV1ShopsShopIdAntiFraudOverviewArgs = {start?: string | undefined, end?: string | undefined, body: {start?: (string | null) | undefined, end?: (string | null) | undefined, timezone?: (string | null) | undefined}}; export type GetApiV1ShopsShopIdAntiFraudOverviewOptions = {baseUrl?: string | undefined, defaultValue?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1ShopsShopIdAntiFraudOverviewResponse = z.object({window_days: z.number().int().optional(), stats: z.object({active_rules: z.number().int().optional(), total_rules: z.number().int().optional(), rule_limit: z.number().int().optional(), has_advanced_types: z.boolean().optional(), blocked: z.number().int().optional(), blocked_change: z.number().int().optional(), allowed: z.number().int().optional(), allowed_change: z.number().int().optional(), block_rate: z.number().int().optional(), block_rate_change: z.number().int().optional(), blocked_24h: z.number().int().optional()}).optional(), graph: z.object({dateData: z.array(z.string()).optional(), blocksData: z.array(z.number().int()).optional()}).optional(), top_block_reasons: z.array(z.unknown()).optional(), coverage: z.array(z.object({type: z.string().optional(), group: z.string().optional(), active: z.number().int().optional(), total: z.number().int().optional(), available: z.boolean().optional()})).optional(), can_read_logs: z.boolean().optional(), has_risk_signals: z.boolean().optional(), risk_signals: z.array(z.unknown()).optional(), suggestions: z.array(z.object({id: z.string().optional(), severity: z.string().optional(), title: z.string().optional(), body: z.string().optional(), evidence: z.string().nullable().optional(), plan_gated: z.boolean().optional(), review_first: z.boolean().optional(), action: z.object({type: z.string().optional(), payload: z.object({type: z.string().optional(), match_type: z.string().optional(), reason: z.string().optional()}).optional()}).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 Anti-Fraud Overview * * GET /v1/shops/{shopId}/anti-fraud/overview */ export const getApiV1ShopsShopIdAntiFraudOverview = async (args: GetApiV1ShopsShopIdAntiFraudOverviewArgs, options?: GetApiV1ShopsShopIdAntiFraudOverviewOptions) => { 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 (args.start != null) query.append("start", String(args.start)) if (args.end != null) query.append("end", String(args.end)) if (defaultValue !== undefined) headers.set('authorization', `Bearer ${defaultValue}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/shops/${encodeURIComponent(String(args.shopId))}/anti-fraud/overview${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(getApiV1ShopsShopIdAntiFraudOverviewResponse, await res.json()) };