{"size": 1065, "ext": "js", "max_stars_repo_path": "src/app/getProducts.js", "max_stars_repo_name": "JVmano/product-watcher", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/app/getProducts.js", "max_issues_repo_name": "JVmano/product-watcher", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/app/getProducts.js", "max_forks_repo_name": "JVmano/product-watcher", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 34.3548387097, "max_line_length": 66, "alphanum_fraction": 0.6938967136}
const { defaultGrowthHeaders } = require('./interface/getHeaders')
const { parseProduct } = require('./lib/parseProduct')
const { sendDiscordWebhook } = require('./lib/sendWebhook')
const { execReq } = require('./services/execReq')
const productsCache = []

const getProducts = async (productLink) => {
  const headers = defaultGrowthHeaders(productLink)
  const productPage = await execReq(productLink, headers)
  const product = await parseProduct(productPage)
  if (product.availability) {
    // * search if the product was already sent in discord channel
    const warningTrigger = productsCache.filter(
      (element) => element.name === product.name
    )
    if (!warningTrigger[0]) {
      productsCache.push(product)
      sendDiscordWebhook(product.name, product.image, productLink)
      // * after 20min the interval delete the old key in cache
      setInterval(function () {
        const index = productsCache.indexOf(product)
        if (index > -1) productsCache.splice(index, 1)
      }, 1200000)
    }
  }
}

module.exports = {
  getProducts
}
