@nibssplc/cams-sdk-react 1.0.0-rc.5 → 1.0.0-rc.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -18,6 +18,7 @@ var DialogPrimitive = require('@radix-ui/react-dialog');
18
18
  var sonner = require('sonner');
19
19
  var framerMotion = require('framer-motion');
20
20
  var axios = require('axios');
21
+ var https = require('https');
21
22
 
22
23
  function _interopNamespaceDefault(e) {
23
24
  var n = Object.create(null);
@@ -1775,6 +1776,27 @@ var APIHeaders = {
1775
1776
  "X-API-VERSION": "1.0",
1776
1777
  };
1777
1778
 
1779
+ // Creates an Axios instance with a base URL determined by the environment (production or development).
1780
+ var axiosInstance = axios.create({
1781
+ httpsAgent: new https.Agent({ rejectUnauthorized: false }),
1782
+ headers: __assign({ "Content-Type": "application/json" }, APIHeaders),
1783
+ });
1784
+ // Intercepts outgoing requests to add authorization token, version header, and timeout settings.
1785
+ axiosInstance.interceptors.request.use(function (config) {
1786
+ var _a;
1787
+ config.timeout = Number((_a = process.env.NEXT_PUBLIC_API_TIMEOUT) !== null && _a !== void 0 ? _a : 605000);
1788
+ config.timeoutErrorMessage = "Operation Timed Out"; // Custom error message for timeouts.
1789
+ return config; // Returns the modified request configuration.
1790
+ }, function (axiosError) {
1791
+ var _a, _b;
1792
+ // Handles request errors.
1793
+ return {
1794
+ status: (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status, // Extracts HTTP status from the error response.
1795
+ message: axiosError.message, // Extracts the error message.
1796
+ data: (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.data, // Extracts response data from the error.
1797
+ };
1798
+ });
1799
+
1778
1800
  var MAX_ATTEMPTS = 3;
1779
1801
  var useOTPHandler = function (_a) {
1780
1802
  var provider = _a.provider, accessToken = _a.accessToken, idToken = _a.idToken, appCode = _a.appCode, authenticationType = _a.authenticationType, MFAEndpoint = _a.MFAEndpoint, onAuthComplete = _a.onAuthComplete;
@@ -1800,16 +1822,13 @@ var useOTPHandler = function (_a) {
1800
1822
  setAttemptCount(currentAttempt);
1801
1823
  if (authenticationType === null)
1802
1824
  return [2 /*return*/, false];
1803
- return [4 /*yield*/, axios.post(MFAEndpoint || "/api/auth/verify-mfa", {
1825
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoint || "/api/auth/verify-mfa", {
1804
1826
  provider: provider,
1805
1827
  accessToken: accessToken,
1806
1828
  idToken: idToken,
1807
1829
  authenticationType: authenticationType,
1808
1830
  MFACode: authenticationValue,
1809
1831
  appCode: appCode,
1810
- }, {
1811
- headers: APIHeaders,
1812
- timeout: 605000,
1813
1832
  })];
1814
1833
  case 2:
1815
1834
  response = (_a.sent()).data;
@@ -1885,14 +1904,11 @@ var useCredentialsHandler = function (onAuthComplete) {
1885
1904
  setLoading(true);
1886
1905
  currentAttempt = attemptCount + 1;
1887
1906
  setAttemptCount(currentAttempt);
1888
- return [4 /*yield*/, axios.post(CredAuthEndpoint, {
1907
+ return [4 /*yield*/, axiosInstance.post(CredAuthEndpoint, {
1889
1908
  username: credentials.username,
1890
1909
  password: credentials.password,
1891
1910
  MFACode: credentials.MFACode,
1892
1911
  appCode: appCode,
1893
- }, {
1894
- headers: APIHeaders,
1895
- timeout: 605000,
1896
1912
  })];
1897
1913
  case 1:
1898
1914
  response = (_a.sent()).data;
@@ -1967,9 +1983,7 @@ var MFAOptions = function (_a) {
1967
1983
  _a.trys.push([0, 4, , 5]);
1968
1984
  // 1. Fetch authentication challenge from your server
1969
1985
  console.log("Requesting authentication challenge from server...");
1970
- return [4 /*yield*/, axios.post(MFAEndpoints.RetrieveAuthChallenge, {}, {
1971
- headers: APIHeaders,
1972
- })];
1986
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RetrieveAuthChallenge, {})];
1973
1987
  case 1:
1974
1988
  options = (_a.sent()).data;
1975
1989
  console.log("Received challenge:", options);
@@ -1981,9 +1995,7 @@ var MFAOptions = function (_a) {
1981
1995
  console.log("Authentication assertion received from client:", assertionResponse);
1982
1996
  // 3. Send the assertion back to the server for verification
1983
1997
  console.log("Sending assertion to server for verification...");
1984
- return [4 /*yield*/, axios.post(MFAEndpoints.AuthChallengeVerify, assertionResponse, {
1985
- headers: APIHeaders
1986
- })];
1998
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.AuthChallengeVerify, assertionResponse)];
1987
1999
  case 3:
1988
2000
  _a.sent();
1989
2001
  sonner.toast.success("🔑 Sign-in successful!");
@@ -2050,7 +2062,7 @@ var MFAOptions = function (_a) {
2050
2062
  return __generator(this, function (_a) {
2051
2063
  switch (_a.label) {
2052
2064
  case 0:
2053
- resetAttempts();
2065
+ // resetAttempts();
2054
2066
  setAuthType("EmailOTP");
2055
2067
  setOtpVisible(true);
2056
2068
  if (!sendEmailOTP) return [3 /*break*/, 2];
@@ -2067,7 +2079,6 @@ var MFAOptions = function (_a) {
2067
2079
  }
2068
2080
  });
2069
2081
  }); }, children: [jsxRuntimeExports.jsx(lucideReact.Mail, { className: "w-5 h-5" }), jsxRuntimeExports.jsxs("div", { className: "text-left", children: [jsxRuntimeExports.jsx("div", { className: "font-medium", children: "Email OTP" }), jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-500", children: "Send code to your email" })] })] }), jsxRuntimeExports.jsxs(Button, { variant: "outline", className: "w-full flex items-center justify-start gap-3 p-4 h-auto border-2 hover:border-[#506f4a] hover:bg-[#506f4a]/5 transition-all", onClick: function () {
2070
- resetAttempts();
2071
2082
  setAuthType("AuthenticatorCode");
2072
2083
  setOtpVisible(true);
2073
2084
  }, children: [jsxRuntimeExports.jsx("img", { src: MicrosoftAuthenticatorImg, alt: "Authenticator", className: "rounded-full", width: 24, height: 24, onError: function () { return jsxRuntimeExports.jsx(lucideReact.Shield, {}); } }), jsxRuntimeExports.jsxs("div", { className: "text-left", children: [jsxRuntimeExports.jsx("div", { className: "font-medium", children: "Authenticator App" }), jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-500", children: "Use Authenticator App" })] })] }), usePassKey && (jsxRuntimeExports.jsxs(Button, { variant: "outline", className: "w-full flex items-center justify-start gap-3 p-4 h-auto border-2 hover:border-[#506f4a] hover:bg-[#506f4a]/5 transition-all",
@@ -2076,7 +2087,7 @@ var MFAOptions = function (_a) {
2076
2087
  // setAuthType("AuthenticatorCode");
2077
2088
  // setOtpVisible(true);
2078
2089
  // }}
2079
- onClick: handleFIDOLogin, disabled: context.isLoading, children: [jsxRuntimeExports.jsx(Button, { className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", children: jsxRuntimeExports.jsx("span", { children: "Sign In " }) }), jsxRuntimeExports.jsx(lucideReact.KeyIcon, { className: "w-16 h-16 text-[#506f4a]" }), jsxRuntimeExports.jsxs("div", { className: "text-left", children: [jsxRuntimeExports.jsx("div", { className: "font-medium", children: "Continue with Passkey" }), jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-500", children: "Passkey" })] })] }))] })] }));
2090
+ onClick: handleFIDOLogin, disabled: context.isLoading, children: [jsxRuntimeExports.jsx(lucideReact.KeyIcon, { className: "text-[#506f4a]", size: 48 }), jsxRuntimeExports.jsxs("div", { className: "text-left", children: [jsxRuntimeExports.jsx("div", { className: "font-medium", children: "Continue with Passkey" }), jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-500", children: "Passkey" })] })] }))] })] }));
2080
2091
  }
2081
2092
  else if (authType === "EmailOTP") {
2082
2093
  content = (jsxRuntimeExports.jsx(Dialog, { open: otpVisible, onOpenChange: function () {
@@ -2220,9 +2231,7 @@ var DefaultLoginPage = function (_a) {
2220
2231
  _a.trys.push([0, 4, , 5]);
2221
2232
  // 1. Fetch challenge from your server
2222
2233
  console.log("Requesting registration challenge from server...");
2223
- return [4 /*yield*/, axios.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data), {
2224
- headers: APIHeaders,
2225
- })];
2234
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data))];
2226
2235
  case 1:
2227
2236
  options = (_a.sent()).data;
2228
2237
  console.log("Received challenge:", options);
@@ -2234,9 +2243,7 @@ var DefaultLoginPage = function (_a) {
2234
2243
  console.log("Passkey created on client:", attestationResponse);
2235
2244
  // 3. Send the response back to the server for verification
2236
2245
  console.log("Sending attestation to server for verification...");
2237
- return [4 /*yield*/, axios.post(MFAEndpoints.RegisterVerify + "?username=".concat(data.username), attestationResponse, {
2238
- headers: APIHeaders
2239
- })];
2246
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterVerify + "?username=".concat(data.username), attestationResponse)];
2240
2247
  case 3:
2241
2248
  _a.sent();
2242
2249
  sonner.toast.success("✅ Registration successful! Passkey created.");
@@ -2309,7 +2316,6 @@ var MFAGate = function (_a) {
2309
2316
  }
2310
2317
  });
2311
2318
  }); }, [context.logout]);
2312
- camsSdk.Logger.debug("MFA Endpoint >>>", { MFAEndpoints: MFAEndpoints });
2313
2319
  if (useADLogin && !CredentialsAuthEndpoint)
2314
2320
  return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
2315
2321
  if (!validatedMFAEndpoints)