4466ba436b
## Description This PR ensures that the default prettier config is used for examples and templates. This config is compatible with `prettier@3` as well (upgrading prettier is bigger change that can be a future PR). ## Changes - Updated `.prettierrc.json` in root with `"trailingComma": "es5"` (will be needed upgrading to prettier@3) - Added `examples/.prettierrc.json` with default config (this will change every example) - Added `packages/create-next-app/templates/.prettierrc.json` with default config (this will change every template) ## Related - Fixes #54402 - Closes #54409
57 lines
1.6 KiB
JavaScript
57 lines
1.6 KiB
JavaScript
import { Customer, Product, Search } from "commerce-sdk";
|
|
|
|
export default async function getProducts(searchQuery) {
|
|
const clientConfig = {
|
|
headers: {
|
|
authorization: ``,
|
|
},
|
|
parameters: {
|
|
clientId: process.env.SFDC_CLIENT_ID,
|
|
secret: process.env.SFDC_SECRET,
|
|
organizationId: process.env.SFDC_ORGANIZATIONID,
|
|
shortCode: process.env.SFDC_SHORTCODE,
|
|
siteId: process.env.SFDC_SITEID,
|
|
},
|
|
};
|
|
|
|
const credentials = `${clientConfig.parameters.clientId}:${clientConfig.parameters.secret}`;
|
|
const base64data = Buffer.from(credentials).toString("base64");
|
|
const headers = { Authorization: `Basic ${base64data}` };
|
|
const client = new Customer.ShopperLogin(clientConfig);
|
|
|
|
const shopperToken = await client.getAccessToken({
|
|
headers,
|
|
body: {
|
|
grant_type: "client_credentials",
|
|
},
|
|
});
|
|
|
|
const configWithAuth = {
|
|
...clientConfig,
|
|
headers: { authorization: `Bearer ${shopperToken.access_token}` },
|
|
};
|
|
|
|
const searchClient = new Search.ShopperSearch(configWithAuth);
|
|
const searchResults = await searchClient.productSearch({
|
|
parameters: { q: searchQuery },
|
|
});
|
|
|
|
const results = [];
|
|
|
|
const productsClient = new Product.ShopperProducts(configWithAuth);
|
|
await Promise.all(
|
|
searchResults.hits.map(async (product) => {
|
|
const productResults = await productsClient.getProduct({
|
|
parameters: {
|
|
organizationId: clientConfig.parameters.organizationId,
|
|
siteId: clientConfig.parameters.siteId,
|
|
id: product.productId,
|
|
},
|
|
});
|
|
|
|
results.push(productResults);
|
|
}),
|
|
);
|
|
|
|
return results;
|
|
}
|