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 product = await shopperProductsClient.getProduct({parameters: {id: variables?.slug as string}});
|
||||||
const normalizedProduct = normalizeProduct(product)
|
const normalizedProduct = normalizeProduct(product)
|
||||||
|
|
||||||
const singleProduct = staticData.products.find(({ slug }) => slug === "new-short-sleeve-t-shirt");
|
|
||||||
|
|
||||||
// TODO: add dummy data
|
// TODO: add dummy data
|
||||||
|
const singleProduct = staticData.products.find(({ slug }) => slug === "new-short-sleeve-t-shirt");
|
||||||
if (singleProduct) {
|
if (singleProduct) {
|
||||||
console.log(" == API == operations == getProductOperation = singleProduct: ", singleProduct)
|
console.log(" == API == operations == getProductOperation = singleProduct: ", singleProduct)
|
||||||
// normalizedProduct['images'] = singleProduct['images']
|
// 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 { Product, Search } from "commerce-sdk";
|
||||||
import { clientConfig, getGuestUserAuthToken } from "./get-auth-token";
|
import { getConfigAuth } from "./get-auth-token";
|
||||||
|
|
||||||
const getshopperProductsClient = async () => {
|
const getSearchClient = async () => {
|
||||||
const shopperToken = await getGuestUserAuthToken();
|
const configAuth = await getConfigAuth();
|
||||||
const configAuth = {
|
return new Search.ShopperSearch(configAuth);
|
||||||
...clientConfig,
|
|
||||||
headers: {"authorization":`Bearer ${shopperToken.access_token}`}
|
|
||||||
};
|
|
||||||
const ShopperProducts = new Product.ShopperProducts(configAuth)
|
|
||||||
return ShopperProducts
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getshopperProductsClient = async () => {
|
||||||
|
const configAuth = await getConfigAuth();
|
||||||
|
return new Product.ShopperProducts(configAuth)
|
||||||
|
}
|
||||||
|
|
||||||
export const sdk = {
|
export const sdk = {
|
||||||
getshopperProductsClient
|
getshopperProductsClient,
|
||||||
|
getSearchClient
|
||||||
}
|
}
|
||||||
export type Sdk = typeof sdk
|
export type Sdk = typeof sdk
|
||||||
export default sdk
|
export default sdk
|
Loading…
x
Reference in New Issue
Block a user