Add src/lib/teemdrop-api.ts
This commit is contained in:
24
src/lib/teemdrop-api.ts
Normal file
24
src/lib/teemdrop-api.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
const TEEMDROP_API_URL = process.env.NEXT_PUBLIC_TEEMDROP_API_URL || 'https://api.teemdrop.com';
|
||||||
|
const TEEMDROP_API_KEY = process.env.TEEMDROP_API_KEY;
|
||||||
|
|
||||||
|
export const teemdropRequest = async (endpoint: string, options: RequestInit = {}) => {
|
||||||
|
const headers = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': `Bearer ${TEEMDROP_API_KEY}`,
|
||||||
|
...options.headers,
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await fetch(`${TEEMDROP_API_URL}${endpoint}`, {
|
||||||
|
...options,
|
||||||
|
headers,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Teemdrop API error: ${response.statusText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getProducts = () => teemdropRequest('/products');
|
||||||
|
export const getOrderDetails = (orderId: string) => teemdropRequest(`/orders/${orderId}`);
|
||||||
Reference in New Issue
Block a user