diff --git a/packages/sn/bun.lockb b/packages/sn/bun.lockb index ef154a0..05716fe 100755 Binary files a/packages/sn/bun.lockb and b/packages/sn/bun.lockb differ diff --git a/packages/sn/package.json b/packages/sn/package.json index 8ac21df..5c36d0c 100644 --- a/packages/sn/package.json +++ b/packages/sn/package.json @@ -25,7 +25,6 @@ }, "dependencies": { "axios": "^1.7.9", - "axios-case-converter": "^1.1.1", "universal-cookie": "^7.2.2", "zustand": "^5.0.3" } diff --git a/packages/sn/src/network.ts b/packages/sn/src/network.ts index d08a952..970a537 100644 --- a/packages/sn/src/network.ts +++ b/packages/sn/src/network.ts @@ -1,8 +1,33 @@ import axios, { type AxiosInstance } from 'axios' -import applyCaseMiddleware from 'axios-case-converter' import Cookies from 'universal-cookie' import { setTokenCookies } from './auth' +function toCamelCase(obj: any): any { + if (Array.isArray(obj)) { + return obj.map(toCamelCase) + } else if (obj && typeof obj === 'object') { + return Object.keys(obj).reduce((result: any, key) => { + const camelKey = key.replace(/_([a-z])/g, (_, char) => char.toUpperCase()) + result[camelKey] = toCamelCase(obj[key]) + return result + }, {}) + } + return obj +} + +// function toSnakeCase(obj: any): any { +// if (Array.isArray(obj)) { +// return obj.map(toSnakeCase) +// } else if (obj && typeof obj === 'object') { +// return Object.keys(obj).reduce((result: any, key) => { +// const snakeKey = key.replace(/[A-Z]/g, (char) => `_${char.toLowerCase()}`) +// result[snakeKey] = toSnakeCase(obj[key]) +// return result +// }, {}) +// } +// return obj +// } + const baseURL = 'https://api.sn.solsynth.dev' export const sni: AxiosInstance = (() => { @@ -18,11 +43,21 @@ export const sni: AxiosInstance = (() => { }, (error) => error, ) + inst.interceptors.response.use( + (response) => { + if (response.data) { + response.data = toCamelCase(response.data) + } + return response + }, + (error) => { + if (error.response && error.response.data) { + error.response.data = toCamelCase(error.response.data) + } + return Promise.reject(error) + }, + ) - applyCaseMiddleware(inst, { - ignoreParams: true, - ignoreHeaders: true, - }) return inst })()