@@ -296,6 +296,27 @@ export default {
296296        auth, 
297297      } ) ; 
298298    } , 
299+     retryWithExponentialBackoff ( func ,  maxAttempts  =  3 ,  baseDelayS  =  2 )  { 
300+       let  attempt  =  0 ; 
301+ 
302+       const  execute  =  async  ( )  =>  { 
303+         try  { 
304+           return  await  func ( ) ; 
305+         }  catch  ( error )  { 
306+           if  ( attempt  >=  maxAttempts )  { 
307+             throw  error ; 
308+           } 
309+ 
310+           const  delayMs  =  Math . pow ( baseDelayS ,  attempt )  *  1000 ; 
311+           await  new  Promise ( ( resolve )  =>  setTimeout ( resolve ,  delayMs ) ) ; 
312+ 
313+           attempt ++ ; 
314+           return  execute ( ) ; 
315+         } 
316+       } ; 
317+ 
318+       return  execute ( ) ; 
319+     } , 
299320    async  requestHandler ( { 
300321      api,  method,  args =  { } , 
301322    } )  { 
@@ -305,7 +326,8 @@ export default {
305326      }  =  args ; 
306327      try  { 
307328        const  calendar  =  this . client ( ) ; 
308-         const  response  =  await  calendar [ api ] [ method ] ( otherArgs ) ; 
329+         const  fn  =  ( )  =>  calendar [ api ] [ method ] ( otherArgs ) ; 
330+         const  response  =  await  this . retryWithExponentialBackoff ( fn ) ; 
309331        return  returnOnlyData 
310332          ? response . data 
311333          : response ; 
@@ -454,6 +476,9 @@ export default {
454476        args, 
455477      } ) ; 
456478    } , 
479+     // Used to get the nextSyncToken. Since we don't need 
480+     // to actually retrieve any events, we set "updatedMin" 
481+     // to the current timestamp 
457482    async  fullSync ( calendarId )  { 
458483      let  nextSyncToken  =  null ; 
459484      let  nextPageToken  =  null ; 
@@ -462,6 +487,8 @@ export default {
462487          await  this . listEvents ( { 
463488            calendarId, 
464489            pageToken : nextPageToken , 
490+             orderBy : "updated" , 
491+             updatedMin : new  Date ( ) . toISOString ( ) , 
465492          } ) ; 
466493        nextPageToken  =  syncResp ?. nextPageToken ; 
467494        nextSyncToken  =  syncResp ?. nextSyncToken ; 
0 commit comments