@nuskin/product-ratings-sdk
v1.1.0
Published
SDK for product ratings and reviews storefront experiences
Readme
@nuskin/product-ratings-sdk
TypeScript SDK for Nu Skin product ratings and reviews storefront experiences.
The SDK exposes Nu Skin product-ratings domain language and hides downstream network/vendor terminology behind typed mapping boundaries.
Translation Boundary
This package is the boundary between Nu Skin storefront applications and the
downstream Equinox ratings and reviews API. Consumers should import and work
with the public ProductReview* and ProductRatings* types exported from this
package.
Equinox DTOs are internal implementation details. They are modeled in the SDK only so network responses and request bodies can be translated at the edge, and they are not exported from the package entrypoint.
Equinox* types must remain internal to this SDK. Do not export them, document
them as consumer contracts, or require storefront applications to construct
objects that match Equinox DTO shapes.
Examples of translations enforced by the SDK:
- Equinox
itemIdis exposed asproductId. - Equinox
reviewtitleis exposed asreviewTitle. - Equinox
ratingdistributionis exposed asratingDistribution. - Equinox
accumulatedtotalis exposed asaccumulatedTotal. - Equinox
ratingfinalis exposed asaverageRating. - Equinox
unlikeCountis exposed asdislikeCount. - Equinox
collectionIdis not exposed to consumers.
Storefront applications should not construct or depend on Equinox DTO shapes. If the downstream API changes, this SDK should absorb that change in its mapping layer while preserving the public product-ratings domain model whenever possible.
Install
yarn add @nuskin/product-ratings-sdk axiosaxios is a peer dependency. The SDK creates and owns its internal Axios
instance.
Usage
import { createRatingsReviewsService } from '@nuskin/product-ratings-sdk';
const ratingsReviews = createRatingsReviewsService({
baseUrl: '/storefront/ratings-reviews',
storeId: 'US',
locale: 'en_US',
userId: 'US1234567'
});
const summary = await ratingsReviews.getRatingsSummary({
productId: 'sku-123'
});
const reviews = await ratingsReviews.getReviews({
productId: 'sku-123',
page: 1,
size: 10,
sort: 'mostRecent'
});Build Outputs
The package is authored in TypeScript and publishes consumer-friendly build artifacts:
- CommonJS JavaScript:
dist/index.js - ES module JavaScript:
dist/index.mjs - Source maps:
dist/*.map - Type definitions:
dist/index.d.ts
Scripts
yarn build
yarn types:check
yarn lint
yarn test