Helpers Available in JS Expression
Helper functions and libraries allowed in JS Expression
External Libraries
Library | Alias | Reference | Description |
---|---|---|---|
lodash | _ (underscore) | https://lodash.com/docs/4.17.15 | A modern JavaScript utility library delivering modularity, performance & extras. Great for iterating arrays, objects, & strings; manipulating & testing values; creating composite functions. |
btoa-lite | btoa | https://www.npmjs.com/package/btoa-lite | Encode base64 strings. |
pluralize | pluralize | https://www.npmjs.com/package/pluralize | This 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. |
jmespath | jmespath | https://www.npmjs.com/package/jmespath | jmespath.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-plus | JSONPath | https://www.npmjs.com/package/jsonpath-plus | Analyse, transform, and selectively extract data from JSON documents (and JavaScript objects). |
ejs | ejs | https://www.npmjs.com/package/ejs | Embedded JavaScript templates. |
luxon | DateTime | https://www.npmjs.com/package/luxon | Luxon is a library for working with dates and times in JavaScript. |
handlebars | processHandlebars | https://www.npmjs.com/package/handlebars | Handlebars.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. |
jose | jose | https://www.npmjs.com/package/jose | Jose 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. |
commerceTools | commerceTools | Commercetools Helper | Helper library for commercetools authentication. |
fluentCommerce | fluentCommerce | Fluent Commerce Helper | Helper library for fluentcommerce authentication. |
salesforceCommerceCloud | salesforceCommerceCloud | Salesforce Helper | Helper library for Salesforce authentication. |
elasticpath | elasticpath | Elastic Path Helper | Helper 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