"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
var _exportNames = {
  sdkSetup: true,
  authenticateClient: true,
  authenticateUser: true,
  verifyOTP: true,
  renewAccessToken: true,
  registerDevice: true,
  listRegisteredDevices: true,
  deleteDevice: true,
  getPendingAuthorisationRequest: true,
  authorisationPendingRequest: true,
  cancelPendingRequest: true,
  getUserProfile: true,
  getDeviceRegistrationSettings: true,
  generateQRCode: true,
  verifyQRCode: true,
  registerDeviceForPushNotification: true,
  deleteDeviceForPushNotification: true,
  decodeRequestBase64: true
};
exports.authenticateClient = authenticateClient;
exports.authenticateUser = authenticateUser;
exports.authorisationPendingRequest = authorisationPendingRequest;
exports.cancelPendingRequest = cancelPendingRequest;
exports.decodeRequestBase64 = decodeRequestBase64;
exports.deleteDevice = deleteDevice;
exports.deleteDeviceForPushNotification = deleteDeviceForPushNotification;
exports.generateQRCode = generateQRCode;
exports.getDeviceRegistrationSettings = getDeviceRegistrationSettings;
exports.getPendingAuthorisationRequest = getPendingAuthorisationRequest;
exports.getUserProfile = getUserProfile;
exports.listRegisteredDevices = listRegisteredDevices;
exports.registerDevice = registerDevice;
exports.registerDeviceForPushNotification = registerDeviceForPushNotification;
exports.renewAccessToken = renewAccessToken;
exports.sdkSetup = sdkSetup;
exports.verifyOTP = verifyOTP;
exports.verifyQRCode = verifyQRCode;
var _reactNative = require("react-native");
var _buffer = require("buffer");
var _textEncoding = require("text-encoding");
var _reactNativeXml2js = require("react-native-xml2js");
var _hooks = require("./hooks");
Object.keys(_hooks).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  if (key in exports && exports[key] === _hooks[key]) return;
  Object.defineProperty(exports, key, {
    enumerable: true,
    get: function () {
      return _hooks[key];
    }
  });
});
var _types = require("./types");
Object.keys(_types).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  if (key in exports && exports[key] === _types[key]) return;
  Object.defineProperty(exports, key, {
    enumerable: true,
    get: function () {
      return _types[key];
    }
  });
});
var _screens = require("./screens");
Object.keys(_screens).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  if (key in exports && exports[key] === _screens[key]) return;
  Object.defineProperty(exports, key, {
    enumerable: true,
    get: function () {
      return _screens[key];
    }
  });
});
var _components = require("./components");
Object.keys(_components).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  if (key in exports && exports[key] === _components[key]) return;
  Object.defineProperty(exports, key, {
    enumerable: true,
    get: function () {
      return _components[key];
    }
  });
});
var _context = require("./context");
Object.keys(_context).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  if (key in exports && exports[key] === _context[key]) return;
  Object.defineProperty(exports, key, {
    enumerable: true,
    get: function () {
      return _context[key];
    }
  });
});
const LINKING_ERROR = `The package 'react-native-cloud-ca' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
  ios: "- You have run 'pod install'\n",
  default: ''
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
const CloudCa = _reactNative.NativeModules.CloudCa ? _reactNative.NativeModules.CloudCa : new Proxy({}, {
  get() {
    throw new Error(LINKING_ERROR);
  }
});
function sdkSetup(params) {
  const {
    baseUrl
  } = params ?? {
    baseUrl: ''
  };
  const urlValidated = validateUrl(baseUrl);
  return CloudCa.sdkSetup(urlValidated);
}
function validateUrl(params) {
  if (!params.startsWith('http://') && !params.startsWith('https://')) {
    return 'https://' + params;
  }
  return params;
}

// 4.1 AuthenticateClient
function authenticateClient(params) {
  const {
    clientId,
    clientSecret,
    grantType
  } = params;
  return CloudCa.authenticateClient(clientId, clientSecret, grantType);
}

// 4.2 AuthenticateUser
function authenticateUser(params) {
  const {
    userId
  } = params;
  return CloudCa.authenticateUser(userId);
}

// 4.3 Verify OTP
function verifyOTP(params) {
  const {
    otpMail,
    otpSms
  } = params;
  return CloudCa.verifyOTP(otpSms, otpMail);
}

// 4.4 Renew Access Token
function renewAccessToken(params) {
  const {
    refresh_token
  } = params;
  if (_reactNative.Platform.OS === 'ios') {
    return CloudCa.renewAccessToken(refresh_token);
  }
  return CloudCa.renewAccessToken();
}

// 4.5 DeviceRegistration
function registerDevice(params) {
  const {
    biometricApiType,
    localizedReason
  } = params ?? {};
  if (_reactNative.Platform.OS === 'ios') {
    return CloudCa.registerDevice(localizedReason);
  }
  return CloudCa.registerDevice(biometricApiType);
}

// 4.6 List Registered Devices
function listRegisteredDevices() {
  return CloudCa.listRegisteredDevices();
}

// 4.7 Delete Device
function deleteDevice(params) {
  const {
    deviceId
  } = params;
  return CloudCa.deleteDevice(deviceId);
}

// 4.8 Get Pending Authorisation Request
function getPendingAuthorisationRequest() {
  return CloudCa.getPendingAuthorisationRequest();
}

// 4.9 Authorise a Pending Request
function authorisationPendingRequest(params) {
  const {
    biometricApiType,
    hashAlgorithm,
    localizedReason,
    request,
    transactionID
  } = params ?? {};
  if (_reactNative.Platform.OS === 'ios') {
    return CloudCa.authorisationPendingRequest(localizedReason, transactionID, request, hashAlgorithm);
  }
  return CloudCa.authorisationPendingRequest(biometricApiType, transactionID, request, hashAlgorithm);
}

// 4.10 Cancel a Pending Authorisation Request
function cancelPendingRequest(params) {
  const {
    hashAlgorithm,
    request,
    transactionID
  } = params ?? {};
  return CloudCa.cancelPendingRequest(transactionID, request, hashAlgorithm);
}

// 4.11 Users Profile
function getUserProfile() {
  return CloudCa.getUserProfile();
}

// 4.12 Get Device Registration Settings
function getDeviceRegistrationSettings() {
  return CloudCa.getDeviceRegistrationSettings();
}

// 4.13 Generate QR Code
function generateQRCode(params) {
  const {
    clientId,
    format,
    size
  } = params;
  if (_reactNative.Platform.OS === 'ios') {
    return CloudCa.generateQRCode(clientId);
  }
  return CloudCa.generateQRCode(format, size);
}

// 4.14 Verify QR Code
function verifyQRCode(params) {
  const {
    qrCode
  } = params;
  console.log('params', params);
  return CloudCa.verifyQRCode(qrCode);
}

// 4.15 Register Device for Push Notification
function registerDeviceForPushNotification(params) {
  const {
    deviceToken
  } = params;
  return CloudCa.registerDeviceForPushNotification(deviceToken);
}

// 4.16 Delete Device for Push Notification
function deleteDeviceForPushNotification(params) {
  const {
    deviceToken
  } = params;
  return CloudCa.deleteDeviceForPushNotification(deviceToken);
}

// decode base64 from 4.8 response
function decodeRequestBase64(encodedString) {
  const binaryString = _buffer.Buffer.from(encodedString, 'base64').toString('binary');
  const decoder = new _textEncoding.TextDecoder('utf-8');
  const decodedString = decoder.decode(new Uint8Array(binaryString.length).map((_, i) => binaryString.charCodeAt(i)));
  let jsonData = {};
  const options = {
    explicitArray: false
  };
  (0, _reactNativeXml2js.parseString)(decodedString, options, function (_err, result) {
    jsonData = result;
  });
  return jsonData;
}
//# sourceMappingURL=index.js.map