UNPKG

@scayle/storefront-core

Version:

Collection of essential utilities to work with the Storefront API

32 lines (31 loc) 954 B
import { mapSAPIFetchErrorToResponse } from "../../utils/sapi.mjs"; import { defineRpcHandler } from "../../utils/index.mjs"; export const getSearchSuggestions = defineRpcHandler( async ({ term, with: _with, categoryId }, context) => { const { sapiClient, withParams } = context; return await mapSAPIFetchErrorToResponse(sapiClient.searchv2.suggestions)( term, { categoryId, with: _with ?? withParams?.searchV2 } ); }, { method: "GET" } ); export const resolveSearch = defineRpcHandler( async ({ term, with: _with, categoryId }, context) => { const { cached, sapiClient, withParams } = context; const resolvedEntity = await cached(sapiClient.searchv2.resolve, { cacheKeyPrefix: `resolve-${term}` })(term, { categoryId, with: _with ?? withParams?.searchV2 }); if (!resolvedEntity) { return null; } return resolvedEntity; }, { method: "GET" } );