11import 'es6-promise/auto' ;
22import { apiInstance , RESPONSE_BAD_REQUEST , RESPONSE_SERVER_ERROR } from './api' ;
3- import { Settings , SortByOptions , SortOrder , SortOrderOptions } from './settings' ;
3+ import { Settings } from './settings' ;
44import { AxiosResponse } from 'axios' ;
55import { isEmptyObject } from './util' ;
66
@@ -184,8 +184,8 @@ const executeApiFetch: ExecuteApiFetch = function (
184184 requestPayloadObject = {
185185 ...requestPayloadObject ,
186186 language : settings ?. lang ,
187- fuzzy : fuzzy !== true && fuzzy !== false ? fuzzy : JSON . stringify ( fuzzy ) ,
188- // fuzzy: fuzzy,
187+ // fuzzy: fuzzy !== true && fuzzy !== false ? fuzzy : JSON.stringify(fuzzy),
188+ fuzzy : fuzzy ,
189189 collectAnalytics : settings ?. collectAnalytics ,
190190 postfixWildcard : settings ?. postfixWildcard ,
191191 categories : settings ?. categories ? settings ?. categories . split ( ',' ) : undefined ,
@@ -194,33 +194,28 @@ const executeApiFetch: ExecuteApiFetch = function (
194194 dateFrom : settings ?. dateFrom ,
195195 dateTo : settings ?. dateTo ,
196196 paging : {
197- page : settings ?. paging . page ? settings ?. paging . page : 1 ,
198- pageSize : settings ?. paging . pageSize ? settings ?. paging . pageSize : 10 ,
199- shuffleAndLimitTo : settings ?. shuffleAndLimitTo || undefined ,
197+ page : settings ?. paging . page ?? 1 ,
198+ pageSize : settings ?. paging . pageSize ?? 10 ,
199+ shuffleAndLimitTo : settings ?. shuffleAndLimitTo ?? undefined ,
200200 sortByField : settings ?. paging . sortBy ,
201201 sortOrder : settings ?. paging . sortOrder
202202 } ,
203203 jwt : settings ?. jwt ,
204204 resultType : settings ?. resultType ,
205- userToken : settings ?. userToken || undefined ,
205+ userToken : settings ?. userToken ?? undefined ,
206206 numFacets : settings ?. numFacets ,
207- cacheResponseWithTtlSeconds : settings ?. cacheResponseTime || undefined ,
208- defaultOperator : settings ?. searchOperator || undefined ,
207+ cacheResponseWithTtlSeconds : settings ?. cacheResponseTime ?? undefined ,
208+ defaultOperator : settings ?. searchOperator ?? undefined ,
209209 analyticsTag : settings ?. analyticsTag
210210 } ;
211211
212212 // Add sortBy and sortOrder
213213 if ( Array . isArray ( settings ?. paging . sortBy ) && settings ?. paging . sortBy . length > 1 ) {
214- const sortByValues : SortByOptions = [ ] ;
215- const sortOrderValues : SortOrderOptions [ ] = [ ] ;
216214 settings ?. paging . sortBy . forEach ( function ( value , index ) {
217215 queryParamsString =
218216 queryParamsString +
219217 settingToQueryParam ( value , 'sort' ) +
220218 settingToQueryParam ( settings ?. paging . sortOrder [ index ] , 'order' ) ;
221-
222- sortByValues . push ( value ) ;
223- sortOrderValues . push ( settings ?. paging . sortOrder [ index ] as SortOrder ) ;
224219 } ) ;
225220 } else {
226221 queryParamsString =
@@ -235,10 +230,10 @@ const executeApiFetch: ExecuteApiFetch = function (
235230 for ( let i = 0 ; i < settings ?. customFieldFilters . length ; i ++ ) {
236231 queryParamsString = queryParamsString + '&customField=' + settings ?. customFieldFilters [ i ] ;
237232
238- var decodedCustomFieldFilter = decodeURIComponent ( settings ?. customFieldFilters [ i ] ) ;
239- var customFieldFilterPair = decodedCustomFieldFilter . split ( '=' ) ;
240- var customFieldName = customFieldFilterPair [ 0 ] ;
241- var customFieldValue = customFieldFilterPair [ 1 ] ;
233+ const decodedCustomFieldFilter = decodeURIComponent ( settings ?. customFieldFilters [ i ] ) ;
234+ const customFieldFilterPair = decodedCustomFieldFilter . split ( '=' ) ;
235+ const customFieldName = customFieldFilterPair [ 0 ] ;
236+ const customFieldValue = customFieldFilterPair [ 1 ] ;
242237 customFieldFiltersValues [ customFieldName ] = customFieldValue ;
243238 }
244239
@@ -434,7 +429,7 @@ const executeApiFetch: ExecuteApiFetch = function (
434429
435430 requestPayloadObject = {
436431 ...requestPayloadObject ,
437- itemId : recommendOptions . itemId ? recommendOptions . itemId : undefined ,
432+ itemId : recommendOptions . itemId ?? undefined ,
438433 blockId : recommendOptions . blockId
439434 } ;
440435 } else if ( recommendOptions ?. type === 'FREQUENTLY_BOUGHT_TOGETHER' ) {
@@ -448,7 +443,7 @@ const executeApiFetch: ExecuteApiFetch = function (
448443
449444 requestPayloadObject = {
450445 ...requestPayloadObject ,
451- itemId : recommendOptions . itemId ? recommendOptions . itemId : undefined ,
446+ itemId : recommendOptions . itemId ?? undefined ,
452447 configurationKey : recommendOptions . configurationKey
453448 } ;
454449 }
@@ -495,7 +490,7 @@ const executeApiFetch: ExecuteApiFetch = function (
495490 if ( settings ?. apiMethod === 'POST' && [ 'search' , 'suggest' , 'autocomplete' ] . includes ( type ) ) {
496491 apiEndpoint = 'https://' + apiHostname + '/v1/' + apiPath + '/' + sitekey ;
497492 requestPayloadObject = {
498- term : keyword ,
493+ term : decodeURIComponent ( keyword ) ,
499494 ...requestPayloadObject
500495 } ;
501496 apiInstance
0 commit comments