The keen observer might notice that the displays lack one key ingredient: page urls (URL to the product page).

If you correctly add the display type to the DepictCategoryProvider, you should also encounter a type error due to this. This happens because the Depict backend omits the page_url for performance reasons. We need to add it back in. If you need to add additional data to the product data you can also do so in this step. The advantage of doing it in the DisplayTransformers compared to the productCard is that the former is only ran once per server response, making it more suitable for making other API requests.

Adding page urls

Provide DisplayTransformers to your DepictCategoryProvider like in the example below:

import { DepictCategoryProvider } from "@depict-ai/js-ui";
import { en_GB } from "@depict-ai/js-ui/locales";
import { YourDisplay } from "./display-types.ts";

const categoryProvider = new DepictCategoryProvider<YourDisplay>({
  merchant: "MERCHANT_ID",
  market: "MARKET",
  listingQuery: { type: "listingId", id: "5d34fd35-5169-4d2f-aa7f-7571f93ae90d" },
  locale: en_GB,
  displayTransformers: {
    products: options => { // the functions in displayTransformers can be async
      return options.displays.map(display => ({
        ...display,
        variant_displays: display.variant_displays.map(variant => ({
          ...variant, // here you can add any extra data you want, but must add page_url
          page_url: "/" + context.market.name + "/p/" + variant.uri, // <- Change this
        })),
      }));
    },
    categories: options => {
      return options.data.map(categoryDisplay => ({
        ...categoryDisplay,
        page_url: "/" + context.market.name + "/c/" + categoryDisplay.uri // <- Change this
      }));
    }
  },
});
For more in-depth information and examples, check out the reference