add search

This commit is contained in:
Dom Sip 2022-04-04 15:34:48 +01:00
parent b5d57b636a
commit 16cbec52cb
3 changed files with 20 additions and 13 deletions

View File

@ -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']

View File

@ -32,4 +32,12 @@ export async function getGuestUserAuthToken(): Promise<Customer.ShopperLogin.Tok
});
}
export const getConfigAuth = async () => {
const shopperToken = await getGuestUserAuthToken();
const configAuth = {
...clientConfig,
headers: {"authorization":`Bearer ${shopperToken.access_token}`}
};
return configAuth;
}

View File

@ -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