@@ -132,13 +132,9 @@ export const getHeaders = async <T>(
132132 options : ApiRequestOptions < T > ,
133133) : Promise < Record < string , string > > => {
134134 const [ token , username , password , additionalHeaders ] = await Promise . all ( [
135- // @ts -ignore
136135 resolve ( options , config . TOKEN ) ,
137- // @ts -ignore
138136 resolve ( options , config . USERNAME ) ,
139- // @ts -ignore
140137 resolve ( options , config . PASSWORD ) ,
141- // @ts -ignore
142138 resolve ( options , config . HEADERS ) ,
143139 ] )
144140
@@ -178,6 +174,8 @@ export const getHeaders = async <T>(
178174 } else if ( options . formData !== undefined ) {
179175 if ( options . mediaType ) {
180176 headers [ "Content-Type" ] = options . mediaType
177+ } else {
178+ headers [ "Content-Type" ] = "application/x-www-form-urlencoded"
181179 }
182180 }
183181
@@ -203,15 +201,41 @@ export const sendRequest = async <T>(
203201) : Promise < AxiosResponse < T > > => {
204202 const controller = new AbortController ( )
205203
204+ // Properly handle form data for URL-encoded submissions
205+ let data = body ;
206+
207+ // If we have formData but it's not a FormData instance,
208+ // and Content-Type is application/x-www-form-urlencoded
209+ if ( options . formData && ! isFormData ( options . formData ) &&
210+ headers [ "Content-Type" ] === "application/x-www-form-urlencoded" ) {
211+ // Use URLSearchParams or axios's built-in handling for url-encoded data
212+ const params = new URLSearchParams ( ) ;
213+ Object . entries ( options . formData ) . forEach ( ( [ key , value ] ) => {
214+ if ( value !== undefined && value !== null ) {
215+ params . append ( key , String ( value ) ) ;
216+ }
217+ } ) ;
218+ data = params ;
219+ } else {
220+ data = body ?? formData ;
221+ }
222+
206223 let requestConfig : AxiosRequestConfig = {
207- data : body ?? formData ,
224+ data : data ,
208225 headers,
209226 method : options . method ,
210227 signal : controller . signal ,
211228 url,
212- withCredentials : config . WITH_CREDENTIALS ,
229+ withCredentials : options . withCredentials ?? config . WITH_CREDENTIALS ,
213230 }
214231
232+ console . log ( "Request config:" , JSON . stringify ( {
233+ url : requestConfig . url ,
234+ method : requestConfig . method ,
235+ headers : requestConfig . headers ,
236+ withCredentials : requestConfig . withCredentials
237+ } ) ) ;
238+
215239 onCancel ( ( ) => controller . abort ( ) )
216240
217241 for ( const fn of config . interceptors . request . _fns ) {
@@ -367,15 +391,14 @@ export const request = <T>(
367391 if ( options . responseTransformer && isSuccess ( response . status ) ) {
368392 transformedBody = await options . responseTransformer ( responseBody )
369393 }
370-
371394 const result : ApiResult = {
372395 url,
373396 ok : isSuccess ( response . status ) ,
374397 status : response . status ,
375398 statusText : response . statusText ,
376399 body : responseHeader ?? transformedBody ,
377400 }
378-
401+ console . log ( result )
379402 catchErrorCodes ( options , result )
380403
381404 resolve ( result . body )
0 commit comments