ADR Service Client
JavaScript client for the Nu Skin ADR Service web API
Installing
Using npm:
$ npm install @nuskin/adr-client
Using Yarn:
$ yarn add @nuskin/adr-client
Initializing the Client
Initialize a new instance of the client by providing the following parameters to the constructor:
baseURL
- The Nu Skin Payment Service web API base URL. Currently, this is the base URL of Nu Skin's legacy web services.clientID
- The Nu Skin web API client ID.clientSecret
- The Nu Skin web API client secret.country
- Country code of the market that requests will be made for.language
- Language code of the market that requests will be made for.userID
- ID of the user that requests will be made for.userToken
- Auth token (eid) of the user that requests will be made for.
Example:
import { ADRClient } from "@nuskin/adr-client";
const client = new ADRClient({
baseURL: "https://www.nuskin.com",
clientID: "0123...aeae",
clientSecret: "8888...aa00",
country: "US",
language: "en",
userID: "US1234567",
userToken: "aBCd....3Au0"
});
Using the Client
Retrieving User's ADR Status Information
Call .getUserStatus()
to retrieve the user's ADR status information in the current market.
Retrieving User's Subscription List
Call .getSubscriptions()
to retrieve a list of the user's subscriptions in the current market.
Retrieving a Subscription's Full Details
Call .getSubscription(id)
to retrieve the full details of a single subscription.
id
is the subscription's order ID.
Creating a New Subscription
Call .createSubscription(subscription, [options])
to create a new subscription.
subscription
is the subscription to create.
Additional options for the request can be given in the options
argument:
{
simulate: false,
shipImmediate: false
}
The method returns a promise that resolves to the newly created subscription's details.
Updating a Subscription
Call .updateSubscription(subscription)
to perform updates of an existing subscription order.
The method returns a promise that resolves to the updated subscription's details.
Deleting a Subscription
Call .deleteSubscription(id)
to delete an existing subscription order.
id
is the subscription's order ID.
Handling Errors
Promises returned by the ADR Service Client may reject with either a plain Error
instance or with a ADRServiceError
instance.
The ADRServiceError
class represents errors caused by the web API rejecting a request. The class takes the following form:
class ADRServiceError extends Error {
status: number;
messages: Array<{
level: string;
code: string;
type: string;
message: string;
technicalMessage: string;
}>;
}
The list of messages included in a ADRServiceError
instance are intended to provide useful information to the user. The following is an example of how this might be handled:
import { ADRClient, ADRServiceError } from "@nuskin/adr-client";
const client = new ADRClient({...});
client.createSubscription(subscription)
.then(...)
.catch(e => {
if (e instanceof ADRServiceError) {
e.messages.forEach(msg => {
})
} else {
}
})
Data Types
ADR Request
Object representing a request to update a subscription (ADR) order record.
interface ADRRequest {
SalesOrder: SalesOrder;
DeliveryDate?: number;
OrderFrequency?: number;
ContractLength?: number;
timestamp: number;
Scan?: ScanCard[];
}
ADR Detail
Object representing the details of a subscription (ADR) order record.
interface ADRDetail {
SalesOrderDetail: SalesOrderDetail;
ShipToName?: string;
Editable?: boolean;
CreateDate?: number;
EndDate?: number;
NextDeliveryDate: number;
LastPlacedDate: number;
ContractLength?: number;
OrderFrequency: number;
LastOrderStatus?: string;
Overridden?: boolean;
Held?: boolean;
Scan?: ScanCard[];
Custom?: CustomField[];
MonthCount: number;
TimeStamp: string;
}
User ADR Status
Object representing the user's market-specific ADR status information.
interface UserADRStatus {
ADRMarketStatus: {
CountryCode: string;
Status: string;
}[];
ADRPoints: {
CountryGroup: string;
CountryCode: string;
Type: string;
TotalPoints: number;
UsedPoints: number;
AvailablePoints: number;
PendingPoints: number;
ExpiringPoints: number;
Currency: string;
}[];
TotalPoints: number;
}