"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.httpClient = exports.getWebViewLink = exports.getEncryptedText = exports.getDecryptedData = void 0;
var _axios = _interopRequireDefault(require("axios"));
var _constants = _interopRequireDefault(require("./constants"));
var _cryptoJs = _interopRequireDefault(require("crypto-js"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const httpClient = exports.httpClient = _axios.default.create({
  timeout: 60000
});
const getEncryptedText = (data, env) => {
  var truncHexKey = _cryptoJs.default.SHA256(env.toUpperCase() === 'PROD' ? _constants.default.PROD_ENC_KEY : _constants.default.STAG_ENC_KEY).toString().substr(0, 32); // hex encode and truncate

  var key = _cryptoJs.default.enc.Utf8.parse(truncHexKey);
  var iv = _cryptoJs.default.enc.Utf8.parse(env.toUpperCase() === 'PROD' ? _constants.default.PROD_ENC_IV : _constants.default.STAGE_ENC_IV);
  var ciphertext = _cryptoJs.default.AES.encrypt(JSON.stringify(data), key, {
    iv: iv,
    mode: _cryptoJs.default.mode.CBC
  });
  return ciphertext.toString();
};
exports.getEncryptedText = getEncryptedText;
const getDecryptedData = (cipher, env) => {
  var truncHexKey = _cryptoJs.default.SHA256(env.toUpperCase() === 'PROD' ? _constants.default.PROD_ENC_KEY : _constants.default.STAG_ENC_KEY).toString().substr(0, 32); // hex encode and truncate

  var key = _cryptoJs.default.enc.Utf8.parse(truncHexKey);
  var iv = _cryptoJs.default.enc.Utf8.parse(env.toUpperCase() === 'PROD' ? _constants.default.PROD_ENC_IV : _constants.default.STAGE_ENC_IV);
  var decryptedData = _cryptoJs.default.AES.decrypt(cipher, key, {
    iv: iv,
    mode: _cryptoJs.default.mode.CBC
  });
  return decryptedData.toString(_cryptoJs.default.enc.Utf8);
};
exports.getDecryptedData = getDecryptedData;
const getWebViewLink = (baseUrl, token, cpsid, srcClientId, deviceId, appVersion, deviceVersion, userEnv) => {
  const data = {
    cpsid,
    token,
    srcClientId,
    deviceId,
    appVersion,
    deviceVersion,
    userEnv
  };
  return httpClient.post(`${baseUrl}/partners/v3/generate-magic-link-star-health`, data).then(res => {
    console.log('getWebViewLink res', {
      res
    });
    return res;
  }).catch(err => {
    console.log('getWebViewLink err', {
      err
    });
    return err;
  });
};
exports.getWebViewLink = getWebViewLink;
//# sourceMappingURL=Services.js.map