Deploy
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
// src/lib/cms.ts — server-side Vula CMS fetch helpers (do not import on client)
|
||||
const VULA_CMS_URL = process.env.VULA_CMS_URL || 'https://ide.vulai.co.za'
|
||||
const VULA_CMS_PROJECT_ID = process.env.VULA_CMS_PROJECT_ID || 'e9195bbc-f558-441e-b69d-2874af86ac58'
|
||||
|
||||
export interface CmsItem {
|
||||
id: string
|
||||
collection: string
|
||||
title: string | null
|
||||
data: Record<string, unknown>
|
||||
status: string
|
||||
sortOrder: number
|
||||
scheduledAt: string | null
|
||||
expiresAt: string | null
|
||||
publishedAt: string | null
|
||||
createdAt: string
|
||||
}
|
||||
|
||||
async function fetchCollection(collection: string, limit = 20): Promise<CmsItem[]> {
|
||||
if (!VULA_CMS_PROJECT_ID) return []
|
||||
try {
|
||||
const url = `${VULA_CMS_URL}/api/public/cms/${VULA_CMS_PROJECT_ID}/${collection}?status=published&limit=${limit}`
|
||||
const res = await fetch(url, { next: { revalidate: 60 } })
|
||||
if (!res.ok) return []
|
||||
const json = await res.json() as { items?: CmsItem[] }
|
||||
return json.items ?? []
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
export const getCampaigns = () => fetchCollection('campaigns')
|
||||
export const getSpecials = () => fetchCollection('specials')
|
||||
export const getBusinessHours = () => fetchCollection('business_hours', 7)
|
||||
export const getPromotions = () => fetchCollection('promotions')
|
||||
export const getFeaturedProductIds = async (): Promise<string[]> => {
|
||||
const items = await fetchCollection('featured_products', 10)
|
||||
return items.flatMap(i => {
|
||||
const ids = i.data.product_ids
|
||||
return Array.isArray(ids) ? ids as string[] : []
|
||||
})
|
||||
}
|
||||
export const getBlogPosts = (limit = 10) => fetchCollection('posts', limit)
|
||||
export const getAdvertBanners = () => fetchCollection('advert_banners')
|
||||
export const getProductCarousels = () => fetchCollection('product_carousels')
|
||||
Reference in New Issue
Block a user