import freshcom from 'freshcom-sdk'
// Use the customer's username and password to obtain a user access token.
freshcom.createAndSetAccessToken({
password: 'supersecurepassword',
scope: 'aid:aid-test-74b901b2-32f9-4e3b-8d4d-4eca2360550c',
return freshcom.listProduct()
}).then(function (response) {
let products = response.data
// Filter out the unlockable products.
let unlockableProducts = products.filter(function (product) {
return product.goods.type === 'Unlockable'
// Map to an array of unlockable ids.
let unlockableIds = unlockableProducts.map(function (product) {
// List all unlock matching the unlockable ids.
filter: { unlockableId: unlockableIds },
}).then(function(responses) {
let unlocks = responses[0].data
let products = responses[1].data.map(function (product) {
if (product.goods.type !== 'Unlockable') { return }
// Check if an unlock exist for this product.
let unlock = this.unlocks.find(function (unlock) {
return product.goods.id === unlock.unlockable.id
// Add a new 'unlock' property for the product if an unlock exist.
// You can now check for products[0].unlock to see if the product
// for an already unlocked unlockable.