1- import type { Context } from '@vtex/api'
21
3- import type { Clients } from '../clients'
4-
5- /**
6- * Helper function to execute intsch as primary with intelligentSearchApi as fallback
7- */
8- async function withFallback < T > (
9- primaryFn : ( ) => Promise < T > ,
10- fallbackFn : ( ) => Promise < T > ,
11- logger : any ,
12- operationName : string ,
13- args ?: Record < string , unknown >
14- ) : Promise < T > {
15- try {
16- return await primaryFn ( )
17- } catch ( error ) {
18- logger . warn ( {
19- message : `${ operationName } : Primary call failed, using fallback` ,
20- error : error . message ,
21- args,
22- } )
23-
24- return fallbackFn ( )
25- }
26- }
2+ import { withFallback } from '../utils/with-fallback'
273
284export function fetchAutocompleteSuggestions (
29- ctx : Context < Clients > ,
5+ ctx : Context ,
306 query : string
317) {
328 const { intelligentSearchApi, intsch } = ctx . clients
@@ -40,7 +16,7 @@ export function fetchAutocompleteSuggestions(
4016 )
4117}
4218
43- export function fetchTopSearches ( ctx : Context < Clients > ) {
19+ export function fetchTopSearches ( ctx : Context ) {
4420 const { intelligentSearchApi, intsch } = ctx . clients
4521
4622 return withFallback (
@@ -52,7 +28,7 @@ export function fetchTopSearches(ctx: Context<Clients>) {
5228 )
5329}
5430
55- export function fetchSearchSuggestions ( ctx : Context < Clients > , query : string ) {
31+ export function fetchSearchSuggestions ( ctx : Context , query : string ) {
5632 const { intelligentSearchApi, intsch } = ctx . clients
5733
5834 return withFallback (
@@ -64,7 +40,7 @@ export function fetchSearchSuggestions(ctx: Context<Clients>, query: string) {
6440 )
6541}
6642
67- export function fetchCorrection ( ctx : Context < Clients > , query : string ) {
43+ export function fetchCorrection ( ctx : Context , query : string ) {
6844 const { intelligentSearchApi, intsch } = ctx . clients
6945
7046 return withFallback (
0 commit comments