@nuskin/shipping-address-sdk
v1.2.0
Published
Client SDK for working with Nu Skin shipping address objects and APIs.
Downloads
577
Keywords
Readme
Shipping Address SDK
Client SDK for working with Nu Skin shipping address objects and APIs.
This SDK is divided into the following namespaces:
- CREW
- LegacyWeb
- Converters
- PickupPoints
CREW
Shipping Profile Client
The CREW namespace exposes a client for the CREW Shipping Profile API.
Example:
import { CREW } from '@nuskin/shipping-address-sdk';
const shippingClient = new CREW.ShippingProfileClient({
env: 'prod',
userSapId: 'US12345678',
userEid: 'noq398...r284yh',
clientId: '9248yt...983yrf',
clientSecret: '928yff...2948yf',
country: 'US',
language: 'en'
});
The following are all required in the constructor parameters:
env
: runtime environment: "dev", "test", or "prod"userSapId
: the SAP ID of the current useruserEid
: the EID token of the current userclientId
: client IDclientSecret
: client secretcountry
: the two-letter country code of the current marketlanguage
: the two-letter language code of the current market
Get shipping addresses
The shipping profile client method getShippingAddresses(market)
retrieves all the user's saved shipping addresses for the current market.
Example:
const market = 'MX';
const addresses = await shippingClient.getShippingAddresses(market);
The market
parameter is optional, and defaults to the client's current market.
Create a new shipping address
The shipping profile client method createShippingAddress(newAddress)
saves a new shipping address to the user's profile in CREW.
Example:
/** @type {CREW.ShippingAddressDraft} */
const newAddress = {
shippingAddressName: 'John Doe',
shippingAddress1: '75 W Center St',
shippingAddress2: 'HR02',
shippingCity: 'Provo',
shippingState: 'UT',
shippingPostalCode: '84601',
shippingCountry: 'US',
shippingPhone: '801-345-1000',
shippingEmail: '[email protected]',
addressType: 'HOME',
defaultShipping: false
};
/** @type {CREW.ShippingAddress} */
const savedAddress = await shippingClient.createShippingAddress(newAddress);
Update a shipping address
The shipping profile client method updateShippingAddress(address)
saves changes to an existing address in the user's profile in CREW. This method overwrites the saved address with the given address data.
Example:
/** @type {CREW.ShippingAddress} */
const addressToUpdate = {
beShippingAddressId: 314159265
/* ... address fields, including updated fields ... */
};
const savedAddress = await shippingClient.updateShippingAddress(addressToUpdate);
Delete a shipping address
The shipping profile client method deleteShippingAddress(shippingAddressId)
deletes a saved address from the user's profile in CREW. The shipping address ID parameter that this method accepts is the beShippingAddressId
property of the CREW shipping address object.
Example:
/** @type {CREW.ShippingAddress} */
const addressToDelete = {
beShippingAddressId: 314159265
/* ... address fields ... */
};
await shippingClient.deleteShippingAddress(addressToDelete.beShippingAddressId);
Get available subscription shipping dates
Various markets have limits regarding the dates on which recurring (subscription) orders can be processed for shipping.
These limits are made available through the shipping profile client method getMarketShipDays()
. This method retrieves the limits of the current market.
Example:
const shippingDates = await shippingClient.getMarketShipDays();
/*
shippingDates = {
defaultShipDay: 15,
blackoutPeriod: 2,
blackoutDays: [28, 29, 30, 31]
}
*/
Get Vietnam regions
The web front-end makes use of a list of Vietnam regions. This list includes the smaller districts that comprise each region, and the cities and towns within each district.
This list is retrieved via the following client method:
Example:
const vnRegions = await shippingClient.getVNRegions();
/*
vnRegions = [ {
value: "AGI",
text: "An Giang",
districts: [
{
text: "An Phú",
cities: [
"An Phú",
"Đa Phước",
"Khánh An",
"Khánh Bình",
...
]
},
...
]
},
...
]
*/
Find cities by postal code
The web front-end for some markets uses a service to find cities and regions that match a given postal code. This service is made available through the following client method:
Example:
const countryCode = 'AU';
const postalCode = '1234567';
const results = await shippingClient.getCitiesByPostalCode(countryCode, postalCode);
/*
results = [
{
postalcode: '1234567',
region: 'ZZZ',
district: 'Demo County',
city: 'Demo Town'
},
...
]
*/
LegacyWeb
Legacy ShippingAddress class
The legacy web front-end uses a ShippingAddress
class in various places. the LegacyWeb namespace exposes this class for use:
import { LegacyWeb } from '@nuskin/shipping-address-sdk';
const legacyAddressObj = new LegacyWeb.ShippingAddress({
/* ... */
});
Converters
The Converters namespace exposes functions for converting shipping address objects from one domain format to another. The domains in question are the SAP Shipping Party, CREW Shipping Address, and Legacy Web Shipping Address.
SAP Shipping Party to CREW Shipping Address
Converting an SAP shipping party object to a CREW shipping address object:
import { Converters } from '@nuskin/shipping-address-sdk';
const sapShippingParty = {
ShippingMemberID: 'US12345678',
Type: 'SHIP_TO',
ShippingAddress: { /* ... */ },
Custom: [ /* ... */ ]
};
const crewShippingAddressDraft = Converters.sapToCrew(sapShippingParty);
SAP Shipping Party to Legacy Web Shipping Address
Converting an SAP shipping party object to a legacy web shipping address object:
import { Converters } from '@nuskin/shipping-address-sdk';
const sapShippingParty = {
ShippingMemberID: 'US12345678',
Type: 'SHIP_TO',
ShippingAddress: { /* ... */ },
Custom: [ /* ... */ ]
};
const legacyAddressObj = Converters.sapToLegacyWeb(sapShippingParty);
Legacy Web Shipping Address to SAP Shipping Party
Converting a legacy web shipping address object to an SAP shipping party object:
import { Converters, LegacyWeb } from '@nuskin/shipping-address-sdk';
const legacyAddressObj = new LegacyWeb.ShippingAddress({
/* ... */
});
const sapShippingParty = Converters.legacyWebToSap(legacyAddressObj);
PickupPoints
The PickupPoints namespace exposes functions for working with EMEA pickup points. EMEA pickup points are locations to which products can be shipped for later pickup by the end recipient.
Check Pickup Point Shipping Methods
EMEA pickup points are only available through certain shipping methods. The PickupPoints namespace exposes the function isPickupPointShippingMethod(methodCode)
to check whether a given shipping method is for EMEA pickup points.
Example:
import { PickupPoints } from '@nuskin/shipping-address-sdk';
const shippingMethodCode1 = 'K1';
const shippingMethodCode2 = 'UPS';
const result1 = PickupPoints.isPickupPointShippingMethod(shippingMethodCode1); // true
const result2 = PickupPoints.isPickupPointShippingMethod(shippingMethodCode2); // false
Convert SAP data to Pickup Points
Information on pickup points is found in the shipping data of SAP's order simulation responses. However, it arrives somewhat serialized within the shipping data's Custom Fields list. The PickupPoints namespace exposes the function parseSapPickupPointFields(sapCustomFields)
to deserialize this data.
Example:
import { PickupPoints } from '@nuskin/shipping-address-sdk';
const sapCustomFields = [
{ /* ... */ },
{ /* ... */ },
// ...
{ /* ... */ }
];
const pickupPoints = PickupPoints.parseSapPickupPointFields(sapCustomFields);