import type { AxiosRequestConfig , AxiosResponse } from 'axios' ; import logdown from 'logdown' ; import { Cookie as ToughCookie } from 'tough-cookie' ; import { Cookie } from '../../auth/' ; import { ObfuscationUtil } from '../../obfuscation/' ; import { CookieStore } from '../../auth/CookieStore' ; import type { HttpClient } from '../../http/' ; const logger = logdown ( '@wireapp/api-client/shims/node/cookie' , { logger : console , markdown : false , } ) ; export const retrieveCookie = async < T > ( response ) : Promise < T > => { if ( response . headers ?. [ 'set-cookie' ] ) { const cookies = response . headers [ 'set-cookie' ] . map ( ToughCookie . parse ) ; for ( const cookie of cookies ) { CookieStore . setCookie ( new Cookie ( cookie . value , cookie . expires ) ) ; logger . info ( `Saved internal cookie. It will expire on "${ cookie . expires }".` , ObfuscationUtil . obfuscateCookie ( cookie ) ) ; } } return response . data ; } ; see https export const sendRequestWithCookie = async < T > ( client , config ) : Promise < AxiosResponse < T > > => { const cookie = CookieStore . getCookie ( ) ; if ( cookie && ! cookie . isExpired ) { config . headers = config . headers || { } ; config . headers . Cookie = `zuid=${ cookie . zuid }` ; config . withCredentials = true ; } return client . _sendRequest < T > ( config ) ; } ;