aboutsummaryrefslogblamecommitdiff
path: root/src/gapi.ts
blob: 8e74483443da870497ba269d9dfc2b7a9ee5ddad (plain) (tree)
1
2
3
4
5
6




                                                          
                             







                                          
                                 





                                                                

                                                                      
                                     



                                                                    






                                                                            
                                                       

                          





                                       
     
                    

 



                                                       

 






                                              

 
                                               

                                     

                                                                             





                                        









                              
                                                                 
                               

                                                                               


                                         
                                                              
                               

                                                                


                           
                                                                                      
                               
                                                                                              








                                                 
                                                                        


                                                                     
                                                                                      



























                                                           
                                




                           


                  


              























                                                                 
                                  

                  


















                                                                      

                                        










                                                                                       










                                                                     























                                                                                  














































                                                                                     





































                                                                                       
                            















                                                              
                                                                     

            

                                                                                    
                                             
                                                                                                    



                                  

                                                 











                                                                


                                                                 
                       

                                              













                                                   




                                                 




























                                                                                                      
                                                                                                                    




















                                                                                
                                                 



                                                         






                                                                              
                                                  

















                                                                                  


                                                                    



                                     


                                                                    


         
/* global chrome */

import LRU from "lru-cache";

const gapiBase = 'https://www.googleapis.com/calendar/v3';
let loggedIn: boolean = null;

enum GApiError {
    invalidSyncToken = "invalidSyncToken",
    notLoggedIn = "notLoggedIn",
    notLoggedOut = "notLoggedOut",
    otherError = "otherError",
}

function toParams(dict: Object) {
    return Object.entries(dict).filter(([k, v] : string[]) => v)
        .map(([k, v]: string[]) => (
            `${encodeURIComponent(k)}=${encodeURIComponent(v)}`
        )).join('&');
}

async function _getAuthToken(interactive = false): Promise<string> {
    let [token, ok]: [string, boolean] = await new Promise(resolver =>
        chrome.identity.getAuthToken(
            {