11import { z } from "zod" ;
22
33import dayjs from "@calcom/dayjs" ;
4- import prisma from "@calcom/prisma" ;
4+ import logger from "@calcom/lib/logger" ;
5+ import { prisma } from "@calcom/prisma" ;
56import type { Credential } from "@calcom/prisma/client" ;
67import type { CalendarEvent } from "@calcom/types/Calendar" ;
78import type { CredentialPayload } from "@calcom/types/Credential" ;
@@ -170,47 +171,43 @@ const WebexVideoApiAdapter = (credential: CredentialPayload): VideoApiAdapter =>
170171 start : meeting . start ,
171172 end : meeting . end ,
172173 } ) ) ;
173- } catch ( err ) {
174- console . error ( err ) ;
175-
174+ } catch {
175+ logger . error ( "Error fetching Webex availability" ) ;
176176 return [ ] ;
177177 }
178178 } ,
179179 createMeeting : async ( event : CalendarEvent ) : Promise < VideoCallData > => {
180180 /** @link https://developer.webex.com/docs/api/v1/meetings/create-a-meeting */
181- try {
182- const response = await fetchWebexApi ( "meetings" , {
183- method : "POST" ,
184- headers : {
185- "Content-Type" : "application/json" ,
186- } ,
187- body : JSON . stringify ( translateEvent ( event ) ) ,
188- } ) ;
189- if ( response . error ) {
190- if ( response . error === "invalid_grant" ) {
191- await invalidateCredential ( credential . id ) ;
192- return Promise . reject ( new Error ( "Invalid grant for Cal.com webex app" ) ) ;
193- }
181+ const response = await fetchWebexApi ( "meetings" , {
182+ method : "POST" ,
183+ headers : {
184+ "Content-Type" : "application/json" ,
185+ } ,
186+ body : JSON . stringify ( translateEvent ( event ) ) ,
187+ } ) ;
188+ if ( response . error ) {
189+ if ( response . error === "invalid_grant" ) {
190+ await invalidateCredential ( credential . id ) ;
191+ return Promise . reject ( new Error ( "Invalid grant for Cal.com webex app" ) ) ;
194192 }
193+ }
195194
196- const result = webexEventResultSchema . parse ( response ) ;
197- if ( result . id && result . webLink ) {
198- return {
199- type : "webex_video" ,
200- id : result . id . toString ( ) ,
201- password : result . password || "" ,
202- url : result . webLink ,
203- } ;
204- }
205- throw new Error ( `Failed to create meeting. Response is ${ JSON . stringify ( result ) } ` ) ;
206- } catch ( err ) {
207- console . error ( err ) ;
208- throw new Error ( "Unexpected error" ) ;
195+ const result = webexEventResultSchema . parse ( response ) ;
196+ if ( result . id && result . webLink ) {
197+ logger . debug ( "Webex meeting created" , { meetingId : result . id } ) ;
198+ return {
199+ type : "webex_video" ,
200+ id : result . id . toString ( ) ,
201+ password : result . password || "" ,
202+ url : result . webLink ,
203+ } ;
209204 }
205+ throw new Error ( "Failed to create meeting: missing id or webLink in response" ) ;
210206 } ,
211207 deleteMeeting : async ( uid : string ) : Promise < void > => {
212208 /** @link https://developer.webex.com/docs/api/v1/meetings/delete-a-meeting */
213209 try {
210+ logger . debug ( "Deleting Webex meeting" , { meetingId : uid } ) ;
214211 const response = await fetchWebexApi ( `meetings/${ uid } ` , {
215212 method : "DELETE" ,
216213 } ) ;
@@ -220,42 +217,38 @@ const WebexVideoApiAdapter = (credential: CredentialPayload): VideoApiAdapter =>
220217 return Promise . reject ( new Error ( "Invalid grant for Cal.com webex app" ) ) ;
221218 }
222219 }
220+ logger . debug ( "Webex meeting deleted" , { meetingId : uid } ) ;
223221 return Promise . resolve ( ) ;
224222 } catch {
225223 return Promise . reject ( new Error ( "Failed to delete meeting" ) ) ;
226224 }
227225 } ,
228226 updateMeeting : async ( bookingRef : PartialReference , event : CalendarEvent ) : Promise < VideoCallData > => {
229227 /** @link https://developer.webex.com/docs/api/v1/meetings/update-a-meeting */
230- try {
231- const response = await fetchWebexApi ( `meetings/${ bookingRef . uid } ` , {
232- method : "PATCH" ,
233- headers : {
234- "Content-Type" : "application/json" ,
235- } ,
236- body : JSON . stringify ( translateEvent ( event ) ) ,
237- } ) ;
238- if ( response . error ) {
239- if ( response . error === "invalid_grant" ) {
240- await invalidateCredential ( credential . id ) ;
241- return Promise . reject ( new Error ( "Invalid grant for Cal.com webex app" ) ) ;
242- }
228+ const response = await fetchWebexApi ( `meetings/${ bookingRef . uid } ` , {
229+ method : "PATCH" ,
230+ headers : {
231+ "Content-Type" : "application/json" ,
232+ } ,
233+ body : JSON . stringify ( translateEvent ( event ) ) ,
234+ } ) ;
235+ if ( response . error ) {
236+ if ( response . error === "invalid_grant" ) {
237+ await invalidateCredential ( credential . id ) ;
238+ return Promise . reject ( new Error ( "Invalid grant for Cal.com webex app" ) ) ;
243239 }
240+ }
244241
245- const result = webexEventResultSchema . parse ( response ) ;
246- if ( result . id && result . webLink ) {
247- return {
248- type : "webex_video" ,
249- id : bookingRef . meetingId as string ,
250- password : result . password || "" ,
251- url : result . webLink ,
252- } ;
253- }
254- throw new Error ( `Failed to create meeting. Response is ${ JSON . stringify ( result ) } ` ) ;
255- } catch ( err ) {
256- console . error ( err ) ;
257- throw new Error ( "Unexpected error" ) ;
242+ const result = webexEventResultSchema . parse ( response ) ;
243+ if ( result . id && result . webLink ) {
244+ return {
245+ type : "webex_video" ,
246+ id : bookingRef . meetingId as string ,
247+ password : result . password || "" ,
248+ url : result . webLink ,
249+ } ;
258250 }
251+ throw new Error ( "Failed to update meeting: missing id or webLink in response" ) ;
259252 } ,
260253 } ;
261254} ;
0 commit comments