README
Product Service Client
JavaScript client for the Nu Skin Product Service web API
Installation
Using NPM
$ npm install @nuskin/product-client
Using Yarn
$ yarn add @nuskin/product-client
Initializing the Client
Initialize a new instance of the client by providing a settings object containing the following:
{
// Product Service base URL.
// This should be the Nu Skin website base URL.
baseURL: "https://www.nuskin.com",
// Product Status Service base URL.
// This should be the Nu Skin cloud services base URL.
productStatusBaseURL: "https://api.cloud.nuskin.com",
// Nu Skin web API client ID.
clientID: "0123...aeae",
// Nu Skin web API client secret.
clientSecret: "8888...aa00",
// Country code.
country: "US",
// Language code.
language: "en"
}
The following settings can optionally be provided as well:
{
// Additional query parameters to include in product status requests.
productStatusParams: {
paramName: "paramValue",
otherParamName: 12345
},
// The requested product quantity.
// By default, the requested product quantity is 1000.
requestedQuantity: 1000, // Default
// Storage provider for locally caching product status data.
// Provider must expose get and set methods.
// See the section on status caching for further details.
store: {
// Key argument is string
get: function(key) {
// Retrieve value for given key
return value;
},
// Key and value arguments are strings
set: function(key, value) {
/* ... */
}
},
// Array of time-to-live settings for cached product status data.
// Each entry should have a minimum quantity and a time-to-live value
// in seconds for that quantity.
// See the section on status caching for further details.
ttl: [
{ qty: 100, ttl: 60 },
{ qty: 250, ttl: 300 }
]
}
Example:
import { ProductClient } from "@nuskin/product-client";
const client = new ProductClient({
baseURL: "https://www.nuskin.com",
productStatusBaseURL: "https://api.cloud.nuskin.com",
clientID: "0123...aeae",
clientSecret: "8888...aa00",
country: "US",
language: "en",
productStatusParams: { filter: "pricing" }
});
Using the Client
Call .getProduct(sku)
to retrieve product information for the given product SKU ID.
The method returns a promise that resolves to a Product class object.
Example:
import {ProductClient} from "@nuskin/product-client";
const client = new ProductClient({...});
client.getProduct("12345678")
.then(product => {
/* ... */
});
The Product Object
The Product
class object contains pricing data and localized information for a Nu Skin product SKU.
It exposes the following properties and methods.
Product Basic Properties
The sku
property identifies the product, while the country
and language
properties identify the market and localization to which this product information applies.
sku
- String- Product SKU ID.
country
- String- Country code.
language
- String- Language code.
Product Availability
The following properties provide availability information relevant to product orders.
marketAttributes
-{[attribute: string]: boolean}
- Market-specific order attribute flags.
status
- String- Product availability status.
availableQuantity
- Number- Product available quantity.
maxQuantity
- Number- Maximum allowable product quantity.
scanQualifiedCount
- Number- Number of scan cards the product can qualify for.
customerTypes
- Array of Strings- Customer type codes of customer types that can purchase this product.
orderTypes
- Array of Strings- Order types that can include this product.
Product Images
The following properties provide product image data.
thumbnail
- String - Optional- URL of product thumbnail image.
image
- String - Optional- URL of product full image.
imageAltText
- String - Optional- Alt text of product image.
carouselImages
- Array of Objects- List of product carousel images.
- Carousel image object:
contentType
- String - Optional- Carousel image content type.
src
- String - Optional- Carousel image source URL.
alt
- String - Optional- Carousel image alt text.
Product Text and Content
The following properties provide localized product text and additional content.
title
- String- Product title.
shortDescription
- String - Optional- Product short description. Plain text.
longDescription
- String - Optional- Product long description. HTML rich text.
sizeWeight
- String - Optional- Product size/weight text.
nettoWeight
- String - Optional- Product net weight text.
disclaimerText
- String - Optional- Product disclaimer text.
disclaimerURL
- String - Optional- Product disclaimer link URL.
benefits
- Object - Optional- Product benefits section object:
benefitsText
- String - Optional- Product benefits plain text.
benefitsHTML
- String - Optional- Product benefits HTML rich text.
benefitItems
- Array of Strings - Optional- Product benefits list.
benefitsVideoUrl
- String - Optional- URL of benefits video.
benefitsPdfUrl
- String - Optional- URL of benefits PDF.
- Product benefits section object:
usage
- Object - Optional- Product usage section object:
usageText
- String - Optional- Product usage plain text.
usageHTML
- String - Optional- Product usage HTML rich text.
usageVideoUrl
- String - Optional- URL of product usage video.
usagePdfUrl
- String - Optional- URL of product usage PDF.
imageUrl
- String - Optional
- Product usage section object:
ingredients
- Object - Optional- Product ingredients section object:
ingredients
- Array of Strings - Optional- Product ingredients list.
ingredientsText
- String - Optional- Product ingredients plain text.
ingredientsHTML
- String - Optional- Product ingredients HTML rich text.
- Product ingredients section object:
resources
- Object - Optional- Product resources section object:
resourcesText
- String - Optional- Resources plain text.
resourcesHTML
- String - Optional- Resources HTML rich text.
resourceLinks
- Array of Strings - Optional- List of product resource URL links.
- Product resources section object:
videos
- Object - Optional- Product videos section object:
videosText
- String - OptionalvideosHTML
- String - OptionalvideoUrls
- Array of Strings - Optional
- Product videos section object:
youtube
- Object - Optional- Product YouTube video section object:
url
- String - Optional- YouTube video URL.
align
- String - Optional- YouTube player horizontal alignment: "left", "center", "right".
width
- String - Optional- YouTube player width.
height
- String - Optional- YouTube player height.
useEmbeddedPlayer
- Boolean - Optional- Flag indicating whether to use embedded player.
embeddedCode
- String - Optional- YouTube embedded video code.
playerId
- String - Optional- YouTube embedded video player ID.
- Product YouTube video section object:
contentSections
- Array of Objects - Optional- List of additional content sections.
- Content section object:
sectionHeader
- String - Optional- Section header text.
sectionContent
- String- Section content HTML rich text.
Product Pricing
The following properties and functions provide product pricing, personal volume (PV), and commissionable volume (CV) data.
Properties that are described as "for product's current price type" are calculated for the current value of the priceType
property. Changing the value of priceType
will cause the values of these other properties to change accordingly.
Example:
product.priceType = "WWHL";
console.log(product.price); // 188.40
product.priceType = "WRTL";
console.log(product.price); // 210.15
priceType
- String- Product's current price type.
price
- Number- Product price for product's current price type.
priceByType(type: string)
- Function- Returns product price for given price type.
minPrice
- Number- Product minimum price for product's current price type.
- Relevant only for base products with one or more variants.
maxPrice
- Number- Product maximum price for product's current price type.
- Relevant only for base products with one or more variants.
priceMap
-{[priceType: string]: number}
- Product prices by price type.
PV
- Number- Product personal volume (PV) value for product's current price type.
pvByType(type: string)
- Function- Returns product PV for given price type.
minPV
- Number- Product minimum PV for product's current price type.
- Relevant only for base products with one or more variants.
maxPV
- Number- Product maximum PV for product's current price type.
- Relevant only for base products with one or more variants.
pvMap
-{[priceType: string]: number}
- Product PV by price type.
CV
- Number- Product commissionable volume (CV) value for product's current price type.
cvByType(type: string)
- Function- Returns product CV for given price type.
minCV
- Number- Product minimum CV for product's current price type.
- Relevant only for base products with one or more variants.
maxCV
- Number- Product maximum CV for product's current price type.
- Relevant only for base products with one or more variants.
cvMap
-{[priceType: string]: number}
- Product CV by price type.
Product Variants
The following properties and functions provide information on product variants.
isBaseSKU()
- Function- Returns
true
if product is base product,false
otherwise.
- Returns
isVariant()
- Function- Returns
true
if product is a variant,false
otherwise.
- Returns
baseSKU
- String - Optional- Base SKU of this product if this product is a variant.
null
if this product is not a variant.
variants
-{[SKU: string]: Product}
- Variants of this product, by variant SKU ID.
variantSKUs
- Array of Strings- List of variant SKU IDs of this product.
variantType
- String - Optional- Variant type identifier.
variantsLabel
- String - Optional- Variant type label text.
variantsDropdownLabel
- String - Optional- Product's label text for variants dropdown.
variantsDropdownPlaceholder
- String - Optional- Variants dropdown placeholder text.
- This property can be found on the base product object.