update add lib,

This commit is contained in:
louiscklaw
2025-06-13 13:19:15 +08:00
parent 5b7cf25753
commit 5a531e1288
3 changed files with 118 additions and 0 deletions

View File

@@ -0,0 +1,83 @@
import type { AxiosRequestConfig } from 'axios';
import axios from 'axios';
import { CONFIG } from 'src/global-config';
// ----------------------------------------------------------------------
const axiosInstance = axios.create({ baseURL: CONFIG.serverUrl });
axiosInstance.interceptors.response.use(
(response) => response,
(error) => Promise.reject((error.response && error.response.data) || 'Something went wrong!')
);
export default axiosInstance;
// ----------------------------------------------------------------------
export const fetcher = async (args: string | [string, AxiosRequestConfig]) => {
try {
const [url, config] = Array.isArray(args) ? args : [args];
const res = await axiosInstance.get(url, { ...config });
return res.data;
} catch (error) {
console.error('Failed to fetch:', error);
throw error;
}
};
// ----------------------------------------------------------------------
export const endpoints = {
chat: '/api/chat',
kanban: '/api/kanban',
calendar: '/api/calendar',
auth: {
me: '/api/auth/me',
signIn: '/api/auth/sign-in',
signUp: '/api/auth/sign-up',
},
mail: {
list: '/api/mail/list',
details: '/api/mail/details',
labels: '/api/mail/labels',
},
post: {
list: '/api/post/list',
details: '/api/post/details',
latest: '/api/post/latest',
search: '/api/post/search',
},
product: {
list: '/api/product/list',
details: '/api/product/details',
search: '/api/product/search',
},
user: {
list: '/api/user/list',
profile: '/api/user/profile',
update: '/api/user/update',
settings: '/api/user/settings',
details: '/api/user/details',
},
order: {
list: '/api/order/list',
profile: '/api/order/profile',
update: '/api/order/update',
settings: '/api/order/settings',
details: '/api/order/details',
changeStatus: (orderId: string) => `/api/order/changeStatus?orderId=${orderId}`,
},
invoice: {
list: '/api/invoice/list',
profile: '/api/invoice/profile',
update: '/api/invoice/update',
saveInvoice: (invoiceId: string) => `/api/invoice/saveInvoice?invoiceId=${invoiceId}`,
settings: '/api/invoice/settings',
details: '/api/invoice/details',
changeStatus: (invoiceId: string) => `/api/invoice/changeStatus?invoiceId=${invoiceId}`,
search: '/api/invoice/search',
},
};

View File

@@ -0,0 +1,19 @@
import type { FirebaseApp } from 'firebase/app';
import type { Auth as AuthType } from 'firebase/auth';
import type { Firestore as FirestoreType } from 'firebase/firestore';
import { getAuth } from 'firebase/auth';
import { initializeApp } from 'firebase/app';
import { getFirestore } from 'firebase/firestore';
import { CONFIG } from 'src/global-config';
// ----------------------------------------------------------------------
const isFirebase = CONFIG.auth.method === 'firebase';
export const firebaseApp = isFirebase ? initializeApp(CONFIG.firebase) : ({} as FirebaseApp);
export const AUTH = isFirebase ? getAuth(firebaseApp) : ({} as AuthType);
export const FIRESTORE = isFirebase ? getFirestore(firebaseApp) : ({} as FirestoreType);

View File

@@ -0,0 +1,16 @@
import type { SupabaseClient } from '@supabase/supabase-js';
import { createClient } from '@supabase/supabase-js';
import { CONFIG } from 'src/global-config';
// ----------------------------------------------------------------------
const isSupabase = CONFIG.auth.method === 'supabase';
const supabaseUrl = CONFIG.supabase.url;
const supabaseKey = CONFIG.supabase.key;
export const supabase = isSupabase
? createClient(supabaseUrl, supabaseKey)
: ({} as SupabaseClient<any, 'public', any>);