@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.esm.js CHANGED
@@ -18,6 +18,7 @@ import * as DialogPrimitive from '@radix-ui/react-dialog';
18
18
  import { toast } from 'sonner';
19
19
  import { motion } from 'framer-motion';
20
20
  import axios from 'axios';
21
+ import https from 'https';
21
22
 
22
23
  /******************************************************************************
23
24
  Copyright (c) Microsoft Corporation.
@@ -1754,6 +1755,27 @@ var APIHeaders = {
1754
1755
  "X-API-VERSION": "1.0",
1755
1756
  };
1756
1757
 
1758
+ // Creates an Axios instance with a base URL determined by the environment (production or development).
1759
+ var axiosInstance = axios.create({
1760
+ httpsAgent: new https.Agent({ rejectUnauthorized: false }),
1761
+ headers: __assign({ "Content-Type": "application/json" }, APIHeaders),
1762
+ });
1763
+ // Intercepts outgoing requests to add authorization token, version header, and timeout settings.
1764
+ axiosInstance.interceptors.request.use(function (config) {
1765
+ var _a;
1766
+ config.timeout = Number((_a = process.env.NEXT_PUBLIC_API_TIMEOUT) !== null && _a !== void 0 ? _a : 605000);
1767
+ config.timeoutErrorMessage = "Operation Timed Out"; // Custom error message for timeouts.
1768
+ return config; // Returns the modified request configuration.
1769
+ }, function (axiosError) {
1770
+ var _a, _b;
1771
+ // Handles request errors.
1772
+ return {
1773
+ status: (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status, // Extracts HTTP status from the error response.
1774
+ message: axiosError.message, // Extracts the error message.
1775
+ data: (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.data, // Extracts response data from the error.
1776
+ };
1777
+ });
1778
+
1757
1779
  var MAX_ATTEMPTS = 3;
1758
1780
  var useOTPHandler = function (_a) {
1759
1781
  var provider = _a.provider, accessToken = _a.accessToken, idToken = _a.idToken, appCode = _a.appCode, authenticationType = _a.authenticationType, MFAEndpoint = _a.MFAEndpoint, onAuthComplete = _a.onAuthComplete;
@@ -1779,16 +1801,13 @@ var useOTPHandler = function (_a) {
1779
1801
  setAttemptCount(currentAttempt);
1780
1802
  if (authenticationType === null)
1781
1803
  return [2 /*return*/, false];
1782
- return [4 /*yield*/, axios.post(MFAEndpoint || "/api/auth/verify-mfa", {
1804
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoint || "/api/auth/verify-mfa", {
1783
1805
  provider: provider,
1784
1806
  accessToken: accessToken,
1785
1807
  idToken: idToken,
1786
1808
  authenticationType: authenticationType,
1787
1809
  MFACode: authenticationValue,
1788
1810
  appCode: appCode,
1789
- }, {
1790
- headers: APIHeaders,
1791
- timeout: 605000,
1792
1811
  })];
1793
1812
  case 2:
1794
1813
  response = (_a.sent()).data;
@@ -1864,14 +1883,11 @@ var useCredentialsHandler = function (onAuthComplete) {
1864
1883
  setLoading(true);
1865
1884
  currentAttempt = attemptCount + 1;
1866
1885
  setAttemptCount(currentAttempt);
1867
- return [4 /*yield*/, axios.post(CredAuthEndpoint, {
1886
+ return [4 /*yield*/, axiosInstance.post(CredAuthEndpoint, {
1868
1887
  username: credentials.username,
1869
1888
  password: credentials.password,
1870
1889
  MFACode: credentials.MFACode,
1871
1890
  appCode: appCode,
1872
- }, {
1873
- headers: APIHeaders,
1874
- timeout: 605000,
1875
1891
  })];
1876
1892
  case 1:
1877
1893
  response = (_a.sent()).data;
@@ -1946,9 +1962,7 @@ var MFAOptions = function (_a) {
1946
1962
  _a.trys.push([0, 4, , 5]);
1947
1963
  // 1. Fetch authentication challenge from your server
1948
1964
  console.log("Requesting authentication challenge from server...");
1949
- return [4 /*yield*/, axios.post(MFAEndpoints.RetrieveAuthChallenge, {}, {
1950
- headers: APIHeaders,
1951
- })];
1965
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RetrieveAuthChallenge, {})];
1952
1966
  case 1:
1953
1967
  options = (_a.sent()).data;
1954
1968
  console.log("Received challenge:", options);
@@ -1960,9 +1974,7 @@ var MFAOptions = function (_a) {
1960
1974
  console.log("Authentication assertion received from client:", assertionResponse);
1961
1975
  // 3. Send the assertion back to the server for verification
1962
1976
  console.log("Sending assertion to server for verification...");
1963
- return [4 /*yield*/, axios.post(MFAEndpoints.AuthChallengeVerify, assertionResponse, {
1964
- headers: APIHeaders
1965
- })];
1977
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.AuthChallengeVerify, assertionResponse)];
1966
1978
  case 3:
1967
1979
  _a.sent();
1968
1980
  toast.success("🔑 Sign-in successful!");
@@ -2029,7 +2041,7 @@ var MFAOptions = function (_a) {
2029
2041
  return __generator(this, function (_a) {
2030
2042
  switch (_a.label) {
2031
2043
  case 0:
2032
- resetAttempts();
2044
+ // resetAttempts();
2033
2045
  setAuthType("EmailOTP");
2034
2046
  setOtpVisible(true);
2035
2047
  if (!sendEmailOTP) return [3 /*break*/, 2];
@@ -2046,7 +2058,6 @@ var MFAOptions = function (_a) {
2046
2058
  }
2047
2059
  });
2048
2060
  }); }, children: [jsxRuntimeExports.jsx(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 () {
2049
- resetAttempts();
2050
2061
  setAuthType("AuthenticatorCode");
2051
2062
  setOtpVisible(true);
2052
2063
  }, children: [jsxRuntimeExports.jsx("img", { src: MicrosoftAuthenticatorImg, alt: "Authenticator", className: "rounded-full", width: 24, height: 24, onError: function () { return jsxRuntimeExports.jsx(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",
@@ -2055,7 +2066,7 @@ var MFAOptions = function (_a) {
2055
2066
  // setAuthType("AuthenticatorCode");
2056
2067
  // setOtpVisible(true);
2057
2068
  // }}
2058
- 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(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" })] })] }))] })] }));
2069
+ onClick: handleFIDOLogin, disabled: context.isLoading, children: [jsxRuntimeExports.jsx(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" })] })] }))] })] }));
2059
2070
  }
2060
2071
  else if (authType === "EmailOTP") {
2061
2072
  content = (jsxRuntimeExports.jsx(Dialog, { open: otpVisible, onOpenChange: function () {
@@ -2199,9 +2210,7 @@ var DefaultLoginPage = function (_a) {
2199
2210
  _a.trys.push([0, 4, , 5]);
2200
2211
  // 1. Fetch challenge from your server
2201
2212
  console.log("Requesting registration challenge from server...");
2202
- return [4 /*yield*/, axios.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data), {
2203
- headers: APIHeaders,
2204
- })];
2213
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data))];
2205
2214
  case 1:
2206
2215
  options = (_a.sent()).data;
2207
2216
  console.log("Received challenge:", options);
@@ -2213,9 +2222,7 @@ var DefaultLoginPage = function (_a) {
2213
2222
  console.log("Passkey created on client:", attestationResponse);
2214
2223
  // 3. Send the response back to the server for verification
2215
2224
  console.log("Sending attestation to server for verification...");
2216
- return [4 /*yield*/, axios.post(MFAEndpoints.RegisterVerify + "?username=".concat(data.username), attestationResponse, {
2217
- headers: APIHeaders
2218
- })];
2225
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterVerify + "?username=".concat(data.username), attestationResponse)];
2219
2226
  case 3:
2220
2227
  _a.sent();
2221
2228
  toast.success("✅ Registration successful! Passkey created.");
@@ -2288,7 +2295,6 @@ var MFAGate = function (_a) {
2288
2295
  }
2289
2296
  });
2290
2297
  }); }, [context.logout]);
2291
- Logger.debug("MFA Endpoint >>>", { MFAEndpoints: MFAEndpoints });
2292
2298
  if (useADLogin && !CredentialsAuthEndpoint)
2293
2299
  return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
2294
2300
  if (!validatedMFAEndpoints)