# ns-product-recommendation

Client SDK for retrieving Nu Skin product recommendations.

## Installing

To install with npm:

```sh
npm install @nuskin/ns-product-recommendation
```

To install with Yarn:

```sh
yarn add @nuskin/ns-product-recommendation
```

## Dependencies

`@nuskin/ns-util^3.0.0` is a peer dependency of this package.

## Using the SDK

Use the SDK to get product recommendations as follows:

```js
import { getRecommendations } from "@nuskin/ns-product-recommendation";

const options = {
  country: "MX",
  productSkus: ["01234567", "89012345"]
};

getRecommendations(options).then(recommendations => {
  /* ... */
});
```

The function resolves to a list of [ProductRecommendation](#productrecommendation) objects.

These are the available request options:

```ts
{
  // (OPTIONAL) `country` is the market country to get recommendations for.
  // If not provided, defaults to the current market country provided by ns-util.
  country: string;

  // (OPTIONAL) `productSkus` is a list of product SKUs to get recommendations for.
  // Recommendations are for products commonly purchased together with the given 
  // SKUs.
  productSkus: string[];

  // (OPTIONAL) `locale` determines the language of any error messages returned by 
  // the product recommendation service. Must be of the form "en_US" or "es_MX".
  // If not provided, defaults to the current market locale provided by ns-util.
  locale: string;
}
```

## Data Types

The Product Recommendation SDK returns the following data type.

### ProductRecommendation

```ts
{
  // Product SKU ID
  sku: string;

  // Type of recommendation:
  // "popular_product" - the product is popular in the given market
  // "common_together" - the product is commonly purchased together with one or more 
  //                     of the given product SKUs
  type: "popular_product" | "common_together";
}
```
