Add test code to index.js and replace client creds
import * as CommerceSdk from "commerce-sdk";
const { slasHelpers, Customer, Product } = CommerceSdk;
// demo client credentials, if you have access to your own please replace them below.
const CLIENT_ID = "";
const ORG_ID = "";
const SHORT_CODE = "";
const SITE_ID = "";
// must be registered in SLAS. On server, redirectURI is never called
const redirectURI = "http://localhost:3000/callback";
This PR adds support for custom query parameters as SCAPI now supports SCAPI hooks: https://developer.salesforce.com/docs/commerce/commerce-api/references/about-commerce-api/about.html#08302023
Query params that begin with
c_
are considered custom query parameters and are passed onto the underlying SCAPI call.This PR also:
typescript
andts-node
packages and fixes respective typescript errors due to upgradeTo test this PR, you can build a local version of the
commerce-sdk
and use that as a package for manual testing:git clone -b feat/support-custom-params git@github.com:SalesforceCommerceCloud/commerce-sdk.git
cd commerce-sdk
npm install --legacy-peer-deps
console.log
totemplates/operations.ts.hbs
to see query params in console output when testingnpm run build
commerce-sdk
to local directory in dependencies section and add "type": "module"npm install
index.js
and replace client creds// demo client credentials, if you have access to your own please replace them below. const CLIENT_ID = "";
const ORG_ID = "";
const SHORT_CODE = "";
const SITE_ID = "";
// must be registered in SLAS. On server, redirectURI is never called const redirectURI = "http://localhost:3000/callback";
// client configuration parameters const clientConfig = { parameters: { clientId: CLIENT_ID, organizationId: ORG_ID, shortCode: SHORT_CODE, siteId: SITE_ID, }, };
const slasClient = new Customer.ShopperLogin(clientConfig);
// GUEST LOGIN const guestTokenResponse = await slasHelpers .loginGuestUser(slasClient, { redirectURI }) .then((guestTokenResponse) => { console.log("Guest Token Response: ", guestTokenResponse); return guestTokenResponse; }) .catch((error) => console.log("Error fetching token for guest login: ", error) );
const shopperProducts = new Product.ShopperProducts({ ...clientConfig, headers: {authorization:
Bearer ${guestTokenResponse.access_token}
} });const productsResult = await shopperProducts.getProducts({ parameters: { ids: "25720044M,25686395M", expand: ["promotions", "images", "prices"], invalid_query: 'invalidQueryParameter', c_customQuery: 'validQueryParameter' } })
console.log("productsResult: ", productsResult)