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/ns-loyalty

v2.8.0

Published

Loads data from Annex Cloud GraphQL Proxy service and runs calculations for bucket totals and activity classification

Downloads

1,454

Readme

ns-loyalty

This library handles the interaction with the service layer for retrieving information about the loyalty program and the user's loyalty information.

Installing

All that is needed for adding this to your project is including the library in your package.json like so:

yarn add @nuskin/ns-loyalty

How to use in your project.

Once you have imported the library into your project, you can use it like you see here:

let loyaltyConfig = {
    requestUrl: 'https://example.url.nuskin.com',
    market: 'EX',
    userId: 'EX0123456',
    jwt: "JWT abcdefg1234567",
    client_id: "gfedcba7654321",
    client_secret: "12345abcde",
}

let loyalty = new nsLoyalty.NsLoyalty(loyaltyConfig);

loyalty.getAllLoyaltyInfo().then(response => {
    let value = response;
    doSomethingWith(value);
});

Please note: all functions are asynchronous, so make sure you handle the expected response appropriately.

As you likely noticed, the library expects an object in the constructor with the following data points:

let loyaltyConfig = {
    requestUrl: 'https://example.url.nuskin.com', // This can be retrieved from ConfigService.getMarketConfig().awsUrl
    market: 'EX', // This can be retrieved from the UserService.getUser().countryCd
    userId: 'EX0123456', // This is the id value of the user, which can be retrieved from UserService.getUser().id
    jwt: "JWT abcdefg1234567", // This is the JWT for the current user, needed to make data requests when a user is logged in.
    client_id: "gfedcba7654321", // This is the client_id for making requests through the proxy service. It can be retrieved from: 
    client_secret: "12345abcde", // This is the client_secret for making request through the proxy service. It can be retrieved from:
}

You pass that into the object when initializing like so:

let loyalty = new nsLoyalty.NsLoyalty(loyaltyConfig);

Now you have a loyalty object which can be used for making one of the following requests:

  • getMarketConfig
  • getRewardsBucketsAndCurrentTierData
  • getWalletAndSoonestToExpire
  • getAllLoyaltyInfo

An example would be:

loyalty.getMarketConfig().then((response) => {
    let doSomething = response;
});

Here is an example of what each returns:

getMarketConfig

{
  optInStatus: 'YES',
  tierData: [
    {
      name: 'Tier1',
      purchaseIncrement: 50,
      minSpend: 50,
      purchaseRatio: 0.05,
      redemptionLimit: 0.7,
      daysToExpire: 90
    },
    {
      name: 'Tier2',
      purchaseIncrement: 50,
      minSpend: 50,
      purchaseRatio: 0.07,
      redemptionLimit: 0.7,
      daysToExpire: 90
    },
    {
      name: 'Tier3',
      purchaseIncrement: 50,
      minSpend: 50,
      purchaseRatio: 0.1,
      redemptionLimit: 0.7,
      daysToExpire: 180
    },
    {
      name: 'Tier4',
      purchaseIncrement: 0,
      minSpend: 0,
      purchaseRatio: 0,
      redemptionLimit: 0.7,
      daysToExpire: 90
    }
  ]
}

getRewardsBucketsAndCurrentTierData

{
  buckets: { withinSeven: [], withinThirty: 0, longTerm: 2055 },
  optInStatus: 'YES',
  soonestExpiring: { pointsToExpire: 685, expirationDate: '2019-11-17' },
  userTier: {
    name: 'Tier4',
    purchaseIncrement: 0,
    minSpend: 0,
    purchaseRatio: 0,
    redemptionLimit: 0.7,
    daysToExpire: 90
  },
  wallet: {
    available: 2055,
    spent: 685,
    spentInPeriod: 2055,
    expiredPoints: 0,
    lifetimePointsEarned: 2740,
    expired: 0
  }
}

getWalletAndSoonestToExpire

{
  optInStatus: 'YES',
  soonestExpiring: { pointsToExpire: 685, expirationDate: '2019-11-17' },
  wallet: {
    available: 2055,
    spent: 685,
    spentInPeriod: 2055,
    expiredPoints: 0,
    lifetimePointsEarned: 2740,
    expired: 0
  }
}

getAllLoyaltyInfo

{
  activity: [
    {
      actionId: 148,
      activity: 'DEBIT',
      credit: null,
      debit: 685,
      displayText: 'Return',
      orderId: '0130064377',
      createDate: '2019-08-20T22:40:17+0000',
      expireDate: null
    },
    {
      actionId: 109,
      activity: 'CREDIT',
      credit: 685,
      debit: null,
      displayText: 'Purchase',
      orderId: '0130064383',
      createDate: '2019-08-20T22:05:57+0000',
      expireDate: '2019-11-18T22:05:57+0000'
    },
    {
      actionId: 109,
      activity: 'CREDIT',
      credit: 685,
      debit: null,
      displayText: 'Purchase',
      orderId: '0130064377',
      createDate: '2019-08-19T15:50:07+0000',
      expireDate: '2019-11-17T15:50:07+0000'
    },
    {
      actionId: 109,
      activity: 'CREDIT',
      credit: 1370,
      debit: null,
      displayText: 'Purchase',
      orderId: '0130064345',
      createDate: '2019-08-12T16:01:35+0000',
      expireDate: null
    }
  ],
  buckets: { withinSeven: [], withinThirty: 0, longTerm: 2055 },
  optInStatus: 'YES',
  soonestExpiring: { pointsToExpire: 685, expirationDate: '2019-11-17' },
  tierData: [
    {
      name: 'Tier1',
      purchaseIncrement: 50,
      minSpend: 50,
      purchaseRatio: 0.05,
      redemptionLimit: 0.7,
      daysToExpire: 90
    },
    {
      name: 'Tier2',
      purchaseIncrement: 50,
      minSpend: 50,
      purchaseRatio: 0.07,
      redemptionLimit: 0.7,
      daysToExpire: 90
    },
    {
      name: 'Tier3',
      purchaseIncrement: 50,
      minSpend: 50,
      purchaseRatio: 0.1,
      redemptionLimit: 0.7,
      daysToExpire: 180
    },
    {
      name: 'Tier4',
      purchaseIncrement: 0,
      minSpend: 0,
      purchaseRatio: 0,
      redemptionLimit: 0.7,
      daysToExpire: 90
    }
  ],
  userTier: {
    name: 'Tier4',
    purchaseIncrement: 0,
    minSpend: 0,
    purchaseRatio: 0,
    redemptionLimit: 0.7,
    daysToExpire: 90
  },
  wallet: {
    available: 2055,
    spent: 685,
    spentInPeriod: 2055,
    expiredPoints: 0,
    lifetimePointsEarned: 2740,
    expired: 0
  }
}

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.