import { fetch } from "./fetch" ; import { IOdspAuthRequestInfo , authRequestWithRetry , } from "./odspAuth" ; export async function getAsync ( url , authRequestInfo ) { return authRequest ( authRequestInfo , async ( config ) => fetch ( url , config ) ) ; } export async function putAsync ( url , authRequestInfo ) { return authRequest ( authRequestInfo , async ( config ) => { const putConfig = { ... config , method : "PUT" } ; return fetch ( url , putConfig ) ; } ) ; } export async function postAsync ( url , body , authRequestInfo ) { return authRequest ( authRequestInfo , async ( config ) => { const postConfig = { ... config , body , method : "POST" } ; return fetch ( url , postConfig ) ; } ) ; } export async function unauthPostAsync ( url , body ) { return safeRequestCore ( async ( ) => { return fetch ( url , { body , method : "POST" } ) ; } ) ; } async function authRequest ( authRequestInfo , requestCallback ) { return authRequestWithRetry ( authRequestInfo , async ( config ) => safeRequestCore ( async ( ) => requestCallback ( config ) ) ) ; } async function safeRequestCore ( requestCallback ) { let response ; try { response = await requestCallback ( ) ; } catch ( error ) { if ( error ?. response ?. status ) { response = error . response ; } else { throw error ; } } return response ; }