import {z} from 'zod' export type GetApiV4KyaScreeningV2ListArgs = {scope?: string | undefined}; export type GetApiV4KyaScreeningV2ListOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const screeningTaskBaseTaskWithID = z.object({address: z.string().optional(), api_key: z.string().optional(), chain: z.string().optional(), created_at: z.string().optional(), error: z.string().optional(), finished_at: z.string().optional(), id: z.string().optional(), org_id: z.string().optional(), retry_count: z.number().int().optional(), rule_set_id: z.string().optional(), started_at: z.string().optional(), status: z.string().optional(), updated_at: z.string().optional()}); export const getApiV4KyaScreeningV2ListResponse = z.object({code: z.number().int().optional(), data: z.array(screeningTaskBaseTaskWithID).nullable().optional(), message: z.string().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 screening task list * * GET /v4/kya/screening_v2/list * * Also accepts auth: ApiSecretAuth */ export const getApiV4KyaScreeningV2List = async (args: GetApiV4KyaScreeningV2ListArgs, options: GetApiV4KyaScreeningV2ListOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.scope != null) query.append("scope", String(args.scope)) if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v4/kya/screening_v2/list${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(getApiV4KyaScreeningV2ListResponse, await res.json()) };