import {z} from 'zod' export type GetApiAccountAccountIdArgs = {account_id: string}; export type GetApiAccountAccountIdOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const accountResponse = z.object({project_id: z.string().optional(), request_id: z.string().optional(), account: z.object({id: z.string().optional(), email: z.string().optional(), phone: z.string().optional(), first_name: z.string().optional(), last_name: z.string().optional(), username: z.string().optional(), expected_countries: z.array(z.string()).optional(), metadata: z.record(z.string(), z.unknown()).optional(), group: z.string().optional()}).optional(), num_sessions: z.number().int().optional(), first_seen: z.string().optional(), last_seen: z.string().optional(), last_session: z.string().optional(), decision: z.string().optional(), account_score: z.number().optional(), bot: z.number().optional(), multiple_accounts: z.number().optional(), risk_signals: z.number().optional(), accounts_linked: z.number().int().optional(), country: z.string().optional(), lists: z.array(z.string()).optional(), unique_devices: z.object({"1_day": z.number().int().optional(), "7_day": z.number().int().optional()}).optional(), unique_networks: z.object({"1_day": z.number().int().optional(), "7_day": z.number().int().optional()}).optional(), email: z.object({email: z.string().optional(), disposable: z.boolean().optional(), personal: z.boolean().optional(), valid: z.boolean().optional(), domain_type: z.enum(["relay", "personal", "disposable", "business", "government", "education", "invalid", "not_active"]).optional(), email_score: z.number().optional(), trust_signals: z.array(z.string()).optional(), risk_signals: z.array(z.string()).optional(), num_account_from_domain: z.number().int().optional()}).optional(), risk_signal_average: z.object({device_risk: z.number().optional(), proxy: z.number().optional(), vpn: z.number().optional(), datacenter: z.number().optional(), tor: z.number().optional(), spoofed_ip: z.number().optional(), recent_fraud_ip: z.number().optional(), impossible_travel: z.number().optional(), device_network_mismatch: z.number().optional(), location_spoofing: z.number().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 }; /** * Returns detailed information about a specific account * * GET /account/{account_id} */ export const getApiAccountAccountId = async (args: GetApiAccountAccountIdArgs, options?: GetApiAccountAccountIdOptions) => { const {baseUrl = "https://api.sandbox.verisoul.ai", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKeyAuth !== undefined) headers.set("x-api-key", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/account/${encodeURIComponent(String(args.account_id))}${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(accountResponse, await res.json()) };