Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nuskin/configuration-sdk

Package Overview
Dependencies
Maintainers
5
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nuskin/configuration-sdk

The configuration sdk gets market configuration from content stack. You can get the full configuration for a list of config maps or get partial configuration using graphql. The sdk caches the configurations for 2 minutes in memory. The sdk also allows

  • 2.3.2-cx15-6896.1
  • npm
  • Socket score

Version published
Weekly downloads
1.4K
increased by74.55%
Maintainers
5
Weekly downloads
 
Created
Source

@nuskin/configuration-sdk

"The configuration sdk gets market configuration from content stack. You can get the full configuration for a list of config maps or get partial configuration using graphql. The sdk caches the configurations for 2 minutes in memory. The sdk also allows for configuraitons to be overridden. Override configurations for runtime shopping context configurations. Or use the function for testing purposes to override configuration in the browser on the fly.",

Installing

Usng npm:

npm add @nuskin/configuration-sdk

Usng yarn:

yarn add @nuskin/configuration-sdk

Example usage

const {
    overrideConfigurationProperty, 
    clearConfigurationOverrides, 
    overrideConfiguration, 
    getConfiguration, 
    getPartialConfig,
    getCachedConfigurations,
    getCachedConfiguration,
    getCachedConfigField
} = require('@nuskin/configuration-sdk');


// Override a single configuration for shopping context and market.  The overrides will be merged with the configuration
overrideConfigurationProperty({configMap: 'Ordering', configMapProperty: 'testing', value: true, country: 'US', shoppingContext: 'personal_offer'});

// Override configuration for shopping context and market.  The overrides will be merged with the configuration 
overrideConfiguration({configMap: ''});

// Expose the overrideConfiguration function so QA can change configuration in the browser
// Just expose the function on window so when you open the console in the dev tools you can access it
// Testers can also override the marketConfigurationOverrides sessionStorage object instead of using this function
window.nuskin.overrideConfiguration = overrideConfiguration;

// get partial config through graphql endpoint.  Returns just the fields requested
const partialConfig = await getPartialConfig(
    queryFields = {
        Ordering: ['spendingRestrictionsEnabled', 'inventoryCheckEnabled'],
        Cart: ['minAdrPsv']
    },
    options = { // optional for client usage
        country: 'US',
        environment: 'test',
        clientId: 'Client id for you application'
    }
);

// Get full configuration for config maps.
// Each config will be stored in a cache which is where it will be retrieved in subsequent calls.
const config = await getConfiguration(
    configMapNames = ['Ordering', 'Cart'],   // list of configMap names
    options = { // optional for client usage
        country: 'US',
        clientId: 'clientId',
        shoppingContext: 'storefront'
    }
);

// The following functions are designed to be used after configuration is originally
// loaded getConfiguration above. They only look for configuration that is in
// local cache and these functions are synchronous and can be used in place of the 
// current ConfigService.getMarketConfig call.

// This will return one or more configMaps from cache.
// Will throw an exception if requested config has not already been loaded by getConfiguration.
const configs = getCachedConfigurations(
    configNames = [], // List of configNames to be retrieved from local cache
    country = null    // optional for client usage
)

// This function returns a single configMap from cache.
// Will throw an exception if requested config has not already been loaded by getConfiguration.
const config = getCachedConfiguration(
    configNames = [], // List of configNames to be retrieved from local cache
    country = null    // optional for client usage
)

// This will return a single field from one of the configMaps previously loaded into
// cache. All cached configMaps are searched so no cacheName is needed. Field names
// are required to be unique across configMaps by contentStack
const configFieldValue = getCachedConfigField(
    configField, 
    country = null  // optional for client usage
) 

Resources

License

MIT

FAQs

Package last updated on 12 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc