spb/vquant Public MIT
VibeQuant — AI-powered institutional-grade financial intelligence platform.
TypeScript 84.3%
Python 11.7%
JavaScript 1.6%
CSS 1.5%
HTML 0.7%
1/*2 * =============================================================================3 * VibeQuant (vquant) — AI-Powered Financial Intelligence Platform4 * -----------------------------------------------------------------------------5 * File: client/src/lib/queryClient.ts6 *7 * Author: Simon-Pierre Boucher8 * Contact: contact@spboucher.ai9 * Website: https://www.spboucher.ai10 * Demo: https://www.vquant.ai11 * License: MIT (see LICENSE)12 *13 * Copyright © 2026 Simon-Pierre Boucher. All rights reserved.14 * =============================================================================15 */1617import { QueryClient, type QueryFunction } from "@tanstack/react-query";1819async function throwIfResNotOk(res: Response) {20 if (!res.ok) {21 const text = (await res.text()) || res.statusText;22 throw new Error(`${res.status}: ${text}`);23 }24}2526export async function apiRequest(27 method: string,28 url: string,29 data?: unknown,30): Promise<Response> {31 const res = await fetch(url, {32 method,33 headers: data ? { "Content-Type": "application/json" } : {},34 body: data ? JSON.stringify(data) : undefined,35 credentials: "include",36 });3738 await throwIfResNotOk(res);39 return res;40}4142type UnauthorizedBehavior = "returnNull" | "throw";4344export const getQueryFn: <T>(options: {45 on401: UnauthorizedBehavior;46}) => QueryFunction<T> =47 ({ on401: unauthorizedBehavior }) =>48 async ({ queryKey }) => {49 const res = await fetch(queryKey.join("/") as string, {50 credentials: "include",51 });5253 if (unauthorizedBehavior === "returnNull" && res.status === 401) {54 return null;55 }5657 await throwIfResNotOk(res);58 return await res.json();59 };6061export const queryClient = new QueryClient({62 defaultOptions: {63 queries: {64 queryFn: getQueryFn({ on401: "returnNull" }),65 refetchOnWindowFocus: false,66 staleTime: 5 * 60 * 1000, // 5 minutes — reasonable for financial data67 gcTime: 30 * 60 * 1000, // 30 minutes garbage collection68 retry: 1, // 1 retry on transient failures69 },70 mutations: {71 retry: false,72 },73 },74});75