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

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