@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.cjs.js CHANGED
@@ -1775,6 +1775,27 @@ var APIHeaders = {
1775
1775
  "X-API-VERSION": "1.0",
1776
1776
  };
1777
1777
 
1778
+ // Creates an Axios instance with a base URL determined by the environment (production or development).
1779
+ var axiosInstance = axios.create({
1780
+ httpsAgent: new (require("node:https").Agent)({ rejectUnauthorized: false }),
1781
+ headers: __assign({ "Content-Type": "application/json" }, APIHeaders),
1782
+ });
1783
+ // Intercepts outgoing requests to add authorization token, version header, and timeout settings.
1784
+ axiosInstance.interceptors.request.use(function (config) {
1785
+ var _a;
1786
+ config.timeout = Number((_a = process.env.NEXT_PUBLIC_API_TIMEOUT) !== null && _a !== void 0 ? _a : 605000);
1787
+ config.timeoutErrorMessage = "Operation Timed Out"; // Custom error message for timeouts.
1788
+ return config; // Returns the modified request configuration.
1789
+ }, function (axiosError) {
1790
+ var _a, _b;
1791
+ // Handles request errors.
1792
+ return {
1793
+ status: (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status, // Extracts HTTP status from the error response.
1794
+ message: axiosError.message, // Extracts the error message.
1795
+ data: (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.data, // Extracts response data from the error.
1796
+ };
1797
+ });
1798
+
1778
1799
  var MAX_ATTEMPTS = 3;
1779
1800
  var useOTPHandler = function (_a) {
1780
1801
  var provider = _a.provider, accessToken = _a.accessToken, idToken = _a.idToken, appCode = _a.appCode, authenticationType = _a.authenticationType, MFAEndpoint = _a.MFAEndpoint, onAuthComplete = _a.onAuthComplete;
@@ -1800,16 +1821,13 @@ var useOTPHandler = function (_a) {
1800
1821
  setAttemptCount(currentAttempt);
1801
1822
  if (authenticationType === null)
1802
1823
  return [2 /*return*/, false];
1803
- return [4 /*yield*/, axios.post(MFAEndpoint || "/api/auth/verify-mfa", {
1824
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoint || "/api/auth/verify-mfa", {
1804
1825
  provider: provider,
1805
1826
  accessToken: accessToken,
1806
1827
  idToken: idToken,
1807
1828
  authenticationType: authenticationType,
1808
1829
  MFACode: authenticationValue,
1809
1830
  appCode: appCode,
1810
- }, {
1811
- headers: APIHeaders,
1812
- timeout: 605000,
1813
1831
  })];
1814
1832
  case 2:
1815
1833
  response = (_a.sent()).data;
@@ -1885,14 +1903,11 @@ var useCredentialsHandler = function (onAuthComplete) {
1885
1903
  setLoading(true);
1886
1904
  currentAttempt = attemptCount + 1;
1887
1905
  setAttemptCount(currentAttempt);
1888
- return [4 /*yield*/, axios.post(CredAuthEndpoint, {
1906
+ return [4 /*yield*/, axiosInstance.post(CredAuthEndpoint, {
1889
1907
  username: credentials.username,
1890
1908
  password: credentials.password,
1891
1909
  MFACode: credentials.MFACode,
1892
1910
  appCode: appCode,
1893
- }, {
1894
- headers: APIHeaders,
1895
- timeout: 605000,
1896
1911
  })];
1897
1912
  case 1:
1898
1913
  response = (_a.sent()).data;
@@ -1967,9 +1982,7 @@ var MFAOptions = function (_a) {
1967
1982
  _a.trys.push([0, 4, , 5]);
1968
1983
  // 1. Fetch authentication challenge from your server
1969
1984
  console.log("Requesting authentication challenge from server...");
1970
- return [4 /*yield*/, axios.post(MFAEndpoints.RetrieveAuthChallenge, {}, {
1971
- headers: APIHeaders,
1972
- })];
1985
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RetrieveAuthChallenge, {})];
1973
1986
  case 1:
1974
1987
  options = (_a.sent()).data;
1975
1988
  console.log("Received challenge:", options);
@@ -1981,9 +1994,7 @@ var MFAOptions = function (_a) {
1981
1994
  console.log("Authentication assertion received from client:", assertionResponse);
1982
1995
  // 3. Send the assertion back to the server for verification
1983
1996
  console.log("Sending assertion to server for verification...");
1984
- return [4 /*yield*/, axios.post(MFAEndpoints.AuthChallengeVerify, assertionResponse, {
1985
- headers: APIHeaders
1986
- })];
1997
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.AuthChallengeVerify, assertionResponse)];
1987
1998
  case 3:
1988
1999
  _a.sent();
1989
2000
  sonner.toast.success("🔑 Sign-in successful!");
@@ -2050,7 +2061,7 @@ var MFAOptions = function (_a) {
2050
2061
  return __generator(this, function (_a) {
2051
2062
  switch (_a.label) {
2052
2063
  case 0:
2053
- resetAttempts();
2064
+ // resetAttempts();
2054
2065
  setAuthType("EmailOTP");
2055
2066
  setOtpVisible(true);
2056
2067
  if (!sendEmailOTP) return [3 /*break*/, 2];
@@ -2067,7 +2078,6 @@ var MFAOptions = function (_a) {
2067
2078
  }
2068
2079
  });
2069
2080
  }); }, 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
2081
  setAuthType("AuthenticatorCode");
2072
2082
  setOtpVisible(true);
2073
2083
  }, 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 +2086,7 @@ var MFAOptions = function (_a) {
2076
2086
  // setAuthType("AuthenticatorCode");
2077
2087
  // setOtpVisible(true);
2078
2088
  // }}
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" })] })] }))] })] }));
2089
+ 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
2090
  }
2081
2091
  else if (authType === "EmailOTP") {
2082
2092
  content = (jsxRuntimeExports.jsx(Dialog, { open: otpVisible, onOpenChange: function () {
@@ -2220,9 +2230,7 @@ var DefaultLoginPage = function (_a) {
2220
2230
  _a.trys.push([0, 4, , 5]);
2221
2231
  // 1. Fetch challenge from your server
2222
2232
  console.log("Requesting registration challenge from server...");
2223
- return [4 /*yield*/, axios.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data), {
2224
- headers: APIHeaders,
2225
- })];
2233
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data))];
2226
2234
  case 1:
2227
2235
  options = (_a.sent()).data;
2228
2236
  console.log("Received challenge:", options);
@@ -2234,9 +2242,7 @@ var DefaultLoginPage = function (_a) {
2234
2242
  console.log("Passkey created on client:", attestationResponse);
2235
2243
  // 3. Send the response back to the server for verification
2236
2244
  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
- })];
2245
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterVerify + "?username=".concat(data.username), attestationResponse)];
2240
2246
  case 3:
2241
2247
  _a.sent();
2242
2248
  sonner.toast.success("✅ Registration successful! Passkey created.");
@@ -2309,7 +2315,6 @@ var MFAGate = function (_a) {
2309
2315
  }
2310
2316
  });
2311
2317
  }); }, [context.logout]);
2312
- camsSdk.Logger.debug("MFA Endpoint >>>", { MFAEndpoints: MFAEndpoints });
2313
2318
  if (useADLogin && !CredentialsAuthEndpoint)
2314
2319
  return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
2315
2320
  if (!validatedMFAEndpoints)