UNPKG

@cgignite/ignite-sf-commerce

Version:

Salesforce Commerce connector for Ignite

38 lines (33 loc) 1.46 kB
const { getCustomersData } = require('../helpers/customers'); const { extractToken } = require('../helpers/functions'); module.exports = function (RED) { function customers(config) { RED.nodes.createNode(this, config); var node = this; this.on('input', function (msg) { var baseURI = 'https://{shortCode}.api.commercecloud.salesforce.com/customer/customers/{version}'; reqHeaders = extractToken(msg) customersInfo = { ApiURL: baseURI + config.endpoint, reqHeaders: msg.reqHeaders ? msg.reqHeaders : reqHeaders, reqParams: msg.reqParams ? msg.reqParams : {}, reqBody: msg.payload ? msg.payload : {}, shortCode: msg.commerceCloudConfig.shortCode, version: msg.commerceCloudConfig.version, organizationId: msg.commerceCloudConfig.organizationId, method: config.method, endpoint: config.endpoint, listId: config.listId, customerNo: config.customerNo, customerListId: config.customerListId, addressId: config.addressId, } getCustomersData(customersInfo) .then(response => { msg.payload = response node.send(msg) }); }); } RED.nodes.registerType("customers", customers); };