@nibssplc/cams-sdk-react 0.0.1-beta.58 → 0.0.1-beta.59

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.
@@ -2,5 +2,5 @@ interface ClientOnlyProps {
2
2
  children: React.ReactNode;
3
3
  fallback?: React.ReactNode;
4
4
  }
5
- export declare function ClientOnly({ children, fallback }: ClientOnlyProps): import("react/jsx-runtime").JSX.Element;
6
- export {};
5
+ declare const ClientOnly: ({ children, fallback }: ClientOnlyProps) => import("react/jsx-runtime").JSX.Element;
6
+ export default ClientOnly;
@@ -0,0 +1,2 @@
1
+ declare const LoginButton: () => import("react/jsx-runtime").JSX.Element;
2
+ export default LoginButton;
@@ -1,6 +1,7 @@
1
1
  interface MFAGateProps {
2
2
  children: React.ReactNode;
3
3
  fallback?: React.ReactNode;
4
+ loginComponent?: React.ComponentType;
4
5
  }
5
- declare const MFAGate: ({ children, fallback }: MFAGateProps) => string | number | bigint | true | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element;
6
+ declare const MFAGate: ({ children, fallback, loginComponent: LoginComponent }: MFAGateProps) => string | number | bigint | true | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element;
6
7
  export default MFAGate;
@@ -2,6 +2,7 @@ import React from "react";
2
2
  import { PublicClientApplication, Configuration } from "@azure/msal-browser";
3
3
  import { UseCAMSAuthOptions } from "../hooks/useCAMSAuth";
4
4
  import { UseCAMSMSALAuthOptions } from "../hooks/useCAMSMSALAuth";
5
+ import { useCAMSContext } from "../context/CAMSContext";
5
6
  interface BaseProviderProps {
6
7
  children: React.ReactNode;
7
8
  appCode: string;
@@ -19,4 +20,4 @@ type UnifiedCAMSProviderProps = RegularProviderProps | MSALProviderProps;
19
20
  export declare function UnifiedCAMSProvider(props: UnifiedCAMSProviderProps): import("react/jsx-runtime").JSX.Element;
20
21
  export declare const CAMSProvider: (props: Omit<RegularProviderProps, "mode">) => import("react/jsx-runtime").JSX.Element;
21
22
  export declare const CAMSMSALProvider: (props: Omit<MSALProviderProps, "mode">) => import("react/jsx-runtime").JSX.Element;
22
- export {};
23
+ export { useCAMSContext };
package/dist/index.cjs.js CHANGED
@@ -1102,7 +1102,7 @@ function useCAMSMSALContext() {
1102
1102
  return context;
1103
1103
  }
1104
1104
 
1105
- function ClientOnly(_a) {
1105
+ var ClientOnly = function (_a) {
1106
1106
  var children = _a.children, _b = _a.fallback, fallback = _b === void 0 ? null : _b;
1107
1107
  var _c = React.useState(false), hasMounted = _c[0], setHasMounted = _c[1];
1108
1108
  React.useEffect(function () {
@@ -1112,7 +1112,7 @@ function ClientOnly(_a) {
1112
1112
  return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: fallback });
1113
1113
  }
1114
1114
  return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
1115
- }
1115
+ };
1116
1116
 
1117
1117
  var CAMSContext = React.createContext(null);
1118
1118
  function useCAMSContext() {
@@ -1143,7 +1143,7 @@ var getCookie = function (name) {
1143
1143
  var deleteCookie = function (name) {
1144
1144
  document.cookie = name + "=; Max-Age=-99999999; path=/";
1145
1145
  };
1146
- function CAMSProviderInner(props) {
1146
+ function CAMSProviderCore(props) {
1147
1147
  var _this = this;
1148
1148
  var _a = props, children = _a.children, mode = _a.mode, appCode = _a.appCode, validateTokenUrl = _a.validateTokenUrl;
1149
1149
  // Always call both hooks to satisfy Rules of Hooks
@@ -1239,9 +1239,9 @@ function UnifiedCAMSProvider(props) {
1239
1239
  if (props.mode === "MSAL") {
1240
1240
  var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
1241
1241
  var instance = msalInstance || new msalBrowser.PublicClientApplication(msalConfig);
1242
- return (jsxRuntimeExports.jsx(msalReact.MsalProvider, { instance: instance, children: jsxRuntimeExports.jsx(CAMSProviderInner, __assign({}, props)) }));
1242
+ return (jsxRuntimeExports.jsx(msalReact.MsalProvider, { instance: instance, children: jsxRuntimeExports.jsx(CAMSProviderCore, __assign({}, props)) }));
1243
1243
  }
1244
- return jsxRuntimeExports.jsx(CAMSProviderInner, __assign({}, props));
1244
+ return (jsxRuntimeExports.jsx(ClientOnly, { fallback: jsxRuntimeExports.jsx("div", { children: "Loading..." }), children: jsxRuntimeExports.jsx(CAMSProviderCore, __assign({}, props)) }));
1245
1245
  }
1246
1246
  // Backward compatibility exports
1247
1247
  var CAMSProvider = function (props) { return (jsxRuntimeExports.jsx(UnifiedCAMSProvider, __assign({}, props, { mode: "REGULAR" }))); };
@@ -1765,8 +1765,23 @@ var MFAOptions = function (_a) {
1765
1765
  return (jsxRuntimeExports.jsxs(Card, { className: "mx-auto space-y-6 p-6 bg-white rounded-lg shadow-md", children: [jsxRuntimeExports.jsxs(CardHeader, { children: [jsxRuntimeExports.jsx("img", { src: "/OTPAuthentication1.svg", alt: "NIBSS Logo", width: 365, height: 365 }), jsxRuntimeExports.jsx(CardTitle, { className: "text-3xl font-bold mb-6 text-center", children: "Two-Factor Authentication" }), jsxRuntimeExports.jsx(CardTitle, { className: "text-gray-300 text-sm -tracking-wide text-center", children: "Your Microsoft account has been validated. Please complete two-factor authentication to continue." })] }), jsxRuntimeExports.jsx(CardContent, { children: content }), jsxRuntimeExports.jsxs(CardFooter, { className: "flex items-center justify-center mt-6 space-x-2 text-gray-400 text-sm", children: [jsxRuntimeExports.jsx(lucideReact.ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsxRuntimeExports.jsx("span", { children: "Powered By NIBSS" })] })] }));
1766
1766
  };
1767
1767
 
1768
+ var LoginButton = function () {
1769
+ var context = useCAMSContext();
1770
+ var login = context.login, isLoading = context.isLoading, error = context.error, authMode = context.authMode;
1771
+ var handleLogin = function () {
1772
+ if (authMode === "MSAL") {
1773
+ login();
1774
+ }
1775
+ else {
1776
+ // For regular mode, you'd need to provide CAMSConfig
1777
+ console.warn("Regular CAMS login requires configuration");
1778
+ }
1779
+ };
1780
+ return (jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center gap-4 p-6", children: [jsxRuntimeExports.jsx(Button, { onClick: handleLogin, disabled: isLoading, className: "min-w-[200px]", children: isLoading ? 'Logging in...' : 'Login with Microsoft' }), error && (jsxRuntimeExports.jsxs("p", { className: "text-red-600 text-sm text-center", children: ["Error: ", error.message] }))] }));
1781
+ };
1782
+
1768
1783
  var MFAGate = function (_a) {
1769
- var children = _a.children, fallback = _a.fallback;
1784
+ var children = _a.children, fallback = _a.fallback, LoginComponent = _a.loginComponent;
1770
1785
  var context = useCAMSContext();
1771
1786
  // Only apply MFA gate for MSAL mode
1772
1787
  if (context.authMode !== "MSAL") {
@@ -1784,7 +1799,7 @@ var MFAGate = function (_a) {
1784
1799
  } }));
1785
1800
  }
1786
1801
  if (!isAuthenticated) {
1787
- return fallback || jsxRuntimeExports.jsx("div", { children: "Please log in" });
1802
+ return fallback || (LoginComponent ? jsxRuntimeExports.jsx(LoginComponent, {}) : jsxRuntimeExports.jsx(LoginButton, {}));
1788
1803
  }
1789
1804
  return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
1790
1805
  };
@@ -1792,6 +1807,7 @@ var MFAGate = function (_a) {
1792
1807
  exports.CAMSMSALProvider = CAMSMSALProvider;
1793
1808
  exports.CAMSProvider = CAMSProvider;
1794
1809
  exports.ClientOnly = ClientOnly;
1810
+ exports.LoginButton = LoginButton;
1795
1811
  exports.MFAGate = MFAGate;
1796
1812
  exports.MFAOptions = MFAOptions;
1797
1813
  exports.ProtectedRoute = ProtectedRoute;