param url function getQueryStringLength ( url ) { const queryParamStart = url . indexOf ( "?" ) ; if ( queryParamStart === - 1 ) { return 0 ; } return url . length - queryParamStart - 1 ; } export function getUrlAndHeadersWithAuth ( url , token ) { if ( ! token || token . length === 0 ) { return { url , headers : { } } ; } const queryParamStart = url . indexOf ( "?" ) ; let tokenQueryParam = queryParamStart === - 1 ? "?" : ( queryParamStart !== url . length - 1 ? `&` : "" ) ; const tokenIsQueryParam = token . startsWith ( "?" ) ; if ( tokenIsQueryParam ) { tokenQueryParam += token . substring ( 1 ) ; } else { tokenQueryParam += `access_token=${ encodeURIComponent ( token ) }` ; } if ( tokenIsQueryParam || getQueryStringLength ( url + tokenQueryParam ) <= 2048 ) { return { headers : { } , url : url + tokenQueryParam } ; } return { headers : { Authorization : `Bearer ${ token }` } , url } ; }