npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nuskin/shipping-address-sdk

v1.2.0

Published

Client SDK for working with Nu Skin shipping address objects and APIs.

Downloads

1,878

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 user
  • userEid: the EID token of the current user
  • clientId: client ID
  • clientSecret: client secret
  • country: the two-letter country code of the current market
  • language: 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);