mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 07:26:59 +00:00
add search
This commit is contained in:
parent
b5d57b636a
commit
16cbec52cb
@ -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']
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user