11import { mainConfig } from "@/lib/config" ;
22
3+ type LumaGeoAddress = {
4+ city : string ;
5+ type : "google" | "string" ;
6+ country : string ;
7+ latitude : number ;
8+ longitude : number ;
9+ place_id : string ;
10+ address : string ;
11+ description : string ;
12+ city_state : string ;
13+ full_address : string ;
14+ } ;
15+
316export type LumaEvent = {
4- app_id : string ;
17+ api_id ?: string ;
18+ app_id ?: string ;
19+ calendar_api_id ?: string ;
520 created_at : string ;
6- cover_url : string ;
21+ cover_url ? : string | null ;
722 name : string ;
8- description : string ;
9- description_md : string ;
23+ description ? : string | null ;
24+ description_md ? : string | null ;
1025 series_api_id ?: string ;
1126 start_at : string ;
1227 duration_interval : string ;
1328 end_at : string ;
14- geo_address_json : {
15- city : string ;
16- type : "google" | "string" ;
17- country : string ;
18- latitude : number ;
19- longitude : number ;
20- place_id : string ;
21- address : string ;
22- description : string ;
23- city_state : string ;
24- full_address : string ;
25- } ;
26- geo_latitude : number ;
27- geo_longitude : number ;
29+ geo_address_json ?: LumaGeoAddress | null ;
30+ geo_latitude ?: number | null ;
31+ geo_longitude ?: number | null ;
2832 url : string ;
2933 timezone : string ;
3034 event_type : "independent" | "series" ;
3135 user_api_id : string ;
3236 visibility : "public" | "private" ;
33- zoom_meeting_url : string ;
34- meeting_url : string ;
37+ zoom_meeting_url ? : string | null ;
38+ meeting_url ? : string | null ;
3539} ;
3640
3741export type LumaHost = {
@@ -75,6 +79,12 @@ export const createLumaClient = () => {
7579 ) ;
7680 return [ ] ;
7781 } ,
82+ getCalendarEvents : async ( ) => {
83+ console . warn (
84+ "Did not fetch calendar events because LUMA_API_KEY is not set" ,
85+ ) ;
86+ return [ ] ;
87+ } ,
7888 getEvent : async ( ) => {
7989 console . warn ( "Did not fetch event because LUMA_API_KEY is not set" ) ;
8090 return null ;
@@ -107,8 +117,44 @@ export const createLumaClient = () => {
107117 "x-luma-api-key" : apiKey ,
108118 } ;
109119
110- const getUpcomingEvents = async ( ) => {
111- const url = `https://api.lu.ma/public/v1/calendar/list-events?pagination_limit=50&after=${ new Date ( ) . toISOString ( ) } ` ;
120+ const parseCalendarEventsResponse = ( resData : any ) : LumaEvent [ ] => {
121+ const entries = resData ?. entries ?? resData ?. events ?. entries ?? [ ] ;
122+ if ( ! Array . isArray ( entries ) ) return [ ] ;
123+ return entries
124+ . map ( ( entry : any ) => entry ?. event ?? entry )
125+ . filter ( Boolean ) as LumaEvent [ ] ;
126+ } ;
127+
128+ const getCalendarEvents = async ( {
129+ limit = 10 ,
130+ after,
131+ before,
132+ calendarApiId,
133+ calendarHandle,
134+ } : {
135+ limit ?: number ;
136+ after ?: string ;
137+ before ?: string ;
138+ calendarApiId ?: string ;
139+ calendarHandle ?: string ;
140+ } = { } ) => {
141+ const searchParams = new URLSearchParams ( {
142+ pagination_limit : String ( limit ) ,
143+ } ) ;
144+ if ( after ) {
145+ searchParams . append ( "after" , after ) ;
146+ }
147+ if ( before ) {
148+ searchParams . append ( "before" , before ) ;
149+ }
150+ if ( calendarApiId ) {
151+ searchParams . append ( "calendar_api_id" , calendarApiId ) ;
152+ }
153+ if ( calendarHandle ) {
154+ searchParams . append ( "calendar_handle" , calendarHandle ) ;
155+ }
156+
157+ const url = `https://api.lu.ma/public/v1/calendar/list-events?${ searchParams . toString ( ) } ` ;
112158 const res = await fetch ( url , {
113159 method : "GET" ,
114160 headers,
@@ -119,7 +165,14 @@ export const createLumaClient = () => {
119165 ) ;
120166 }
121167 const resData = await res . json ( ) ;
122- return resData . events . entries . map ( ( e : any ) => e . event ) ;
168+ return parseCalendarEventsResponse ( resData ) ;
169+ } ;
170+
171+ const getUpcomingEvents = async ( ) => {
172+ return getCalendarEvents ( {
173+ limit : 50 ,
174+ after : new Date ( ) . toISOString ( ) ,
175+ } ) ;
123176 } ;
124177
125178 const getEvent = async ( eventId : string ) : Promise < LumaEventPayload > => {
@@ -228,6 +281,7 @@ export const createLumaClient = () => {
228281
229282 return {
230283 getUpcomingEvents,
284+ getCalendarEvents,
231285 getEvent,
232286 getAttendees,
233287 getAllAttendees,
0 commit comments