"use strict";

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

exports.__esModule = true;
exports.getXWebTraceId = exports.md5Http = exports.random = void 0;

var _jsMd = _interopRequireDefault(require("js-md5"));

var random = function random(count) {
  var num = Date.now() + Math.floor(1000 * Math.random() + 1000);

  if (count) {
    return num.toString().substr(-count);
  }

  return num.toString();
};

exports.random = random;

var md5Http = function md5Http(token, timestamp, body) {
  return (0, _jsMd.default)((0, _jsMd.default)(token).toUpperCase() + timestamp + JSON.stringify(body || {})).toUpperCase();
};

exports.md5Http = md5Http;

var getXWebTraceId = function getXWebTraceId(userId, menuId, now) {
  var log = window.ksui && window.ksui.log;
  var startTime = log && log.initTime || now;
  return userId + "-" + (menuId || 'xxxx') + "-" + startTime + "-" + (log && log.lastActionId || '') + "-" + random(4);
};

exports.getXWebTraceId = getXWebTraceId;