diff --git a/packages/sfcc/src/api/operations/get-product.ts b/packages/sfcc/src/api/operations/get-product.ts index 5858a63e2..971a5c7be 100644 --- a/packages/sfcc/src/api/operations/get-product.ts +++ b/packages/sfcc/src/api/operations/get-product.ts @@ -25,9 +25,8 @@ export default function getProductOperation({ const product = await shopperProductsClient.getProduct({parameters: {id: variables?.slug as string}}); const normalizedProduct = normalizeProduct(product) - const singleProduct = staticData.products.find(({ slug }) => slug === "new-short-sleeve-t-shirt"); - // TODO: add dummy data + const singleProduct = staticData.products.find(({ slug }) => slug === "new-short-sleeve-t-shirt"); if (singleProduct) { console.log(" == API == operations == getProductOperation = singleProduct: ", singleProduct) // normalizedProduct['images'] = singleProduct['images'] diff --git a/packages/sfcc/src/api/utils/get-auth-token.ts b/packages/sfcc/src/api/utils/get-auth-token.ts index 4b19939c1..d9adadf44 100644 --- a/packages/sfcc/src/api/utils/get-auth-token.ts +++ b/packages/sfcc/src/api/utils/get-auth-token.ts @@ -32,4 +32,12 @@ export async function getGuestUserAuthToken(): Promise { + const shopperToken = await getGuestUserAuthToken(); + const configAuth = { + ...clientConfig, + headers: {"authorization":`Bearer ${shopperToken.access_token}`} + }; + return configAuth; +} diff --git a/packages/sfcc/src/api/utils/sfcc-sdk.ts b/packages/sfcc/src/api/utils/sfcc-sdk.ts index 3ef459df7..7f2e5cb6a 100644 --- a/packages/sfcc/src/api/utils/sfcc-sdk.ts +++ b/packages/sfcc/src/api/utils/sfcc-sdk.ts @@ -1,19 +1,19 @@ -import { Product } from "commerce-sdk"; -import { clientConfig, getGuestUserAuthToken } from "./get-auth-token"; +import { Product, Search } from "commerce-sdk"; +import { getConfigAuth } from "./get-auth-token"; -const getshopperProductsClient = async () => { - const shopperToken = await getGuestUserAuthToken(); - const configAuth = { - ...clientConfig, - headers: {"authorization":`Bearer ${shopperToken.access_token}`} - }; - const ShopperProducts = new Product.ShopperProducts(configAuth) - return ShopperProducts +const getSearchClient = async () => { + const configAuth = await getConfigAuth(); + return new Search.ShopperSearch(configAuth); } +const getshopperProductsClient = async () => { + const configAuth = await getConfigAuth(); + return new Product.ShopperProducts(configAuth) +} export const sdk = { - getshopperProductsClient + getshopperProductsClient, + getSearchClient } export type Sdk = typeof sdk export default sdk \ No newline at end of file