"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

function _requestify() {
  const data = _interopRequireDefault(require("requestify"));

  _requestify = function () {
    return data;
  };

  return data;
}

function _globalConfig() {
  const data = require("../api/consumer/lib/global-config");

  _globalConfig = function () {
    return data;
  };

  return data;
}

function _constants() {
  const data = require("../constants");

  _constants = function () {
    return data;
  };

  return data;
}

/* eslint no-console: 0 */
const ANALYTICS_DOMAIN = (0, _globalConfig().getSync)(_constants().CFG_ANALYTICS_DOMAIN_KEY) || _constants().DEFAULT_ANALYTICS_DOMAIN;
/**
 * to debug errors here, first, change the parent to have { silent: false }, in analytics.js `fork` call.
 */


process.on('message', msg => {
  // needed for the parent to make sure the child got the message
  // without it, when the message is large, the parent exits before it totally sent
  process.send('Got the message');
  return _requestify().default.post(ANALYTICS_DOMAIN, msg, {
    timeout: 1000
  }).then(() => {
    console.log('message has been sent');
    process.exit();
  }).fail(err => {
    console.error('failed to send the message', err);
    process.exit();
  });
});
setTimeout(() => {
  console.log('exit due to timeout');
  process.exit();
}, 5000);