@nuskin/configuration-sdk
v3.0.0
Published
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
Downloads
5,028
Keywords
Readme
@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
)
// 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
)
// 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
)