Skip to main content

Helpers Available in JS Expression

Helper functions and libraries allowed in JS Expression

External Libraries

LibraryAliasReference
Description
lodash_ (underscore)https://lodash.com/docs/4.17.15A modern JavaScript utility library delivering modularity, performance & extras. Great for iterating arrays, objects, & strings; manipulating & testing values; creating composite functions.
btoa-litebtoahttps://www.npmjs.com/package/btoa-liteEncode base64 strings.
pluralizepluralizehttps://www.npmjs.com/package/pluralizeThis module uses a pre-defined list of rules, applied in order, to singularize or pluralize a given word. There are many cases where this is useful, such as any automation based on user input.
jmespathjmespathhttps://www.npmjs.com/package/jmespathjmespath.js is a javascript implementation of JMESPath, which is a query language for JSON. It will take a JSON document and transform it into another JSON document through a JMESPath expression.
jsonpath-plusJSONPathhttps://www.npmjs.com/package/jsonpath-plusAnalyse, transform, and selectively extract data from JSON documents (and JavaScript objects).
ejsejshttps://www.npmjs.com/package/ejsEmbedded JavaScript templates.
luxonDateTimehttps://www.npmjs.com/package/luxonLuxon is a library for working with dates and times in JavaScript.
handlebarsprocessHandlebarshttps://www.npmjs.com/package/handlebarsHandlebars.js is an extension to the Mustache templating language. Handlebars.js and Mustache are both logicless templating languages that keep the view and the code separated.
josejosehttps://www.npmjs.com/package/joseJose is JavaScript module for JSON Object Signing and Encryption, providing support for JSON Web Tokens (JWT), JSON Web Signature (JWS), JSON Web Encryption (JWE), JSON Web Key (JWK), JSON Web Key Set (JWKS), and more.
commerceToolscommerceToolsCommercetools HelperHelper library for commercetools authentication.
fluentCommercefluentCommerceFluent Commerce HelperHelper library for fluentcommerce authentication.
salesforceCommerceCloudsalesforceCommerceCloudSalesforce HelperHelper library for Salesforce authentication.
elasticpathelasticpathElastic Path HelperHelper library for Elastic Path authentication.

Examples

Some external library functions return a Promise. For example, to get the returned payload from jose.jwtVerify, you first need to wait on the Promise and then get the payload from the response: jose.jwtVerify(xxx, yyy).then(response => response.payload).

List of methods in custom commerce helper libraries

commercetools Helper

generateToken

Generate access token for commercetools.

Params:

  • region
  • projectKey
  • clientId
  • clientSecret

Usage example:

commerceTools.generateToken('{region}', '{projectKey}', '{clientId}', secret('clientSecret')).then(token => 'Bearer ' + token)

Fluent Commerce Helper

generateToken

Generate access token for fluentcommerce.

Params:

  • accountId
  • retailerUsername
  • password
  • environment
  • clientSecret

Salesforce Helper

generateOCAPIToken

Generate OpenCommerce API Token.

Params:

  • clientId
  • clientSecret

generateSLASToken

Generate token for Shopper Login (B2C).

Params:

  • shortCode
  • organizationId
  • clientId
  • clientSecret
  • customerId: optional

generateOauthToken

Generate token for Connected Apps.

Params:

  • clientId
  • clientSecret
  • username
  • password

Elastic Path Helper

generateClientCredential

Generate client credentials for Elastic Path.

Params:

  • authUrl
  • clientId
  • clientSecret

generateImplicitCredential

Generate implicit credentials for Elastic Path.

Params:

  • authUrl
  • clientId

Inbuilt methods and global objects

Function/ObjectReference
encodeURIhttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI
encodeURIComponenthttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
JSONhttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON
Arrayhttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
Promisehttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
Objecthttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object