diff --git a/index.js b/index.js index 272ad78..489097c 100644 --- a/index.js +++ b/index.js @@ -20,6 +20,7 @@ const logger = require('tektrans-logger'); const report = require('./lib/report'); const sleep = require('./lib/sleep'); +const composeGatewayLocations = require('./lib/compose-gateway-locations'); let partner; let first = true; @@ -56,6 +57,7 @@ async function getTask() { const payload = { handler: config.handler || config.handler_name, products: config.products || [], + locations: composeGatewayLocations(config), }; let task; diff --git a/lib/compose-gateway-locations.js b/lib/compose-gateway-locations.js new file mode 100644 index 0000000..83d14a8 --- /dev/null +++ b/lib/compose-gateway-locations.js @@ -0,0 +1,18 @@ +/** + * @param {Object} config + * @param {Array.<string>} [config.locations] + * @returns {Array.<string>} + */ +module.exports = (config) => { + const retval = (( + Array.isArray(config.locations) && config.locations.length && config.locations) + || [] + ) + .filter((item) => typeof item === 'string') + .map((item) => item.trim()) + .filter((item) => item.length); + + if (!retval.length) retval.push('ALL'); + + return retval; +};