@nibssplc/cams-sdk-react 0.0.1-beta.10

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/README.md ADDED
@@ -0,0 +1,160 @@
1
+ # NIBSS CAMS SDK - React
2
+
3
+ React hooks and components for NIBSS CAMS SDK with support for both popup and redirect authentication flows.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @nibssplc/cams-sdk-react
9
+
10
+ # For MSAL redirect support (optional)
11
+ npm install @azure/msal-browser @azure/msal-react
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ### Popup Authentication (Default)
17
+
18
+ ```tsx
19
+ import { CAMSProvider, useCAMSAuth } from '@nibssplc/cams-sdk-react';
20
+
21
+ function App() {
22
+ return (
23
+ <CAMSProvider>
24
+ <LoginComponent />
25
+ </CAMSProvider>
26
+ );
27
+ }
28
+
29
+ function LoginComponent() {
30
+ const { login, logout, isAuthenticated, isLoading } = useCAMSAuth();
31
+
32
+ const handleLogin = () => {
33
+ login({
34
+ camsUrl: 'https://your-cams-instance.com/auth',
35
+ messageOrigin: 'your-cams-instance.com',
36
+ windowWidth: 500,
37
+ windowHeight: 600,
38
+ });
39
+ };
40
+
41
+ if (isAuthenticated) {
42
+ return <button onClick={logout}>Logout</button>;
43
+ }
44
+
45
+ return (
46
+ <button onClick={handleLogin} disabled={isLoading}>
47
+ {isLoading ? 'Logging in...' : 'Login'}
48
+ </button>
49
+ );
50
+ }
51
+ ```
52
+
53
+ ### MSAL Redirect Authentication with MFA
54
+
55
+ ```tsx
56
+ import { CAMSMSALProvider, useCAMSMSALAuth } from '@nibssplc/cams-sdk-react';
57
+
58
+ const msalConfig = {
59
+ auth: {
60
+ clientId: 'your-client-id',
61
+ authority: 'https://login.microsoftonline.com/your-tenant-id',
62
+ redirectUri: window.location.origin,
63
+ },
64
+ };
65
+
66
+ function App() {
67
+ return (
68
+ <CAMSMSALProvider msalConfig={msalConfig}>
69
+ <LoginComponent />
70
+ </CAMSMSALProvider>
71
+ );
72
+ }
73
+
74
+ function LoginComponent() {
75
+ const {
76
+ login,
77
+ logout,
78
+ completeMFA,
79
+ isAuthenticated,
80
+ isLoading,
81
+ isMFAPending,
82
+ account
83
+ } = useCAMSMSALAuth({
84
+ scopes: ['openid', 'profile', 'email'],
85
+ mfaUrl: 'https://your-mfa-page.com/verify',
86
+ onAuthSuccess: (token) => console.log('Auth complete:', token),
87
+ onMFARequired: (msalToken, account) => console.log('MFA required for:', account.name),
88
+ });
89
+
90
+ // Handle MFA completion (call this after MFA verification)
91
+ const handleMFAComplete = (mfaToken: string) => {
92
+ completeMFA(mfaToken);
93
+ };
94
+
95
+ if (isAuthenticated) {
96
+ return (
97
+ <div>
98
+ <p>Welcome, {account?.name}</p>
99
+ <button onClick={logout}>Logout</button>
100
+ </div>
101
+ );
102
+ }
103
+
104
+ if (isMFAPending) {
105
+ return <div>Completing MFA verification...</div>;
106
+ }
107
+
108
+ return (
109
+ <button onClick={login} disabled={isLoading}>
110
+ {isLoading ? 'Redirecting...' : 'Login with Azure AD'}
111
+ </button>
112
+ );
113
+ }
114
+ ```
115
+
116
+ ## API Reference
117
+
118
+ ### useCAMSMSALAuth
119
+
120
+ Hook for MSAL redirect authentication.
121
+
122
+ ```tsx
123
+ const {
124
+ login,
125
+ logout,
126
+ isAuthenticated,
127
+ isLoading,
128
+ error,
129
+ token,
130
+ profile,
131
+ account
132
+ } = useCAMSMSALAuth(options);
133
+ ```
134
+
135
+ **Options:**
136
+ - `scopes?: string[]` - OAuth scopes (default: `['openid', 'profile', 'email']`)
137
+ - `mfaUrl?: string` - Custom MFA page URL for redirect after MSAL login
138
+ - `onAuthSuccess?: (token: string) => void` - Success callback (after MFA completion)
139
+ - `onAuthError?: (error: CAMSError) => void` - Error callback
140
+ - `onTokenExpired?: () => void` - Token expiration callback
141
+ - `onMFARequired?: (msalToken: string, account: AccountInfo) => void` - MFA required callback
142
+
143
+ **Returns:**
144
+ - `completeMFA: (mfaToken: string) => void` - Complete MFA verification
145
+ - `isMFAPending: boolean` - Whether MFA verification is pending
146
+
147
+ ### CAMSMSALProvider
148
+
149
+ Provider component for MSAL integration.
150
+
151
+ ```tsx
152
+ <CAMSMSALProvider msalConfig={config} msalInstance={instance}>
153
+ {children}
154
+ </CAMSMSALProvider>
155
+ ```
156
+
157
+ **Props:**
158
+ - `msalConfig: Configuration` - MSAL configuration object
159
+ - `msalInstance?: PublicClientApplication` - Optional pre-configured MSAL instance
160
+ - `children: ReactNode` - Child components
@@ -0,0 +1,8 @@
1
+ import { ReactNode } from 'react';
2
+ import { PublicClientApplication, Configuration } from '@azure/msal-browser';
3
+ export interface CAMSMSALProviderProps {
4
+ children: ReactNode;
5
+ msalConfig: Configuration;
6
+ msalInstance?: PublicClientApplication;
7
+ }
8
+ export declare function CAMSMSALProvider({ children, msalConfig, msalInstance }: CAMSMSALProviderProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,13 @@
1
+ import { ReactNode } from 'react';
2
+ import { CAMSConfig } from '@nibssplc/cams-sdk';
3
+ import { UseCAMSAuthReturn, UseCAMSAuthOptions } from '../hooks/useCAMSAuth';
4
+ interface CAMSContextValue extends UseCAMSAuthReturn {
5
+ defaultConfig?: Partial<CAMSConfig>;
6
+ }
7
+ export interface CAMSProviderProps extends UseCAMSAuthOptions {
8
+ children: ReactNode;
9
+ defaultConfig?: Partial<CAMSConfig>;
10
+ }
11
+ export declare function CAMSProvider({ children, defaultConfig, ...authOptions }: CAMSProviderProps): import("react/jsx-runtime").JSX.Element;
12
+ export declare function useCAMSContext(): CAMSContextValue;
13
+ export {};
@@ -0,0 +1,7 @@
1
+ import React, { ReactNode } from 'react';
2
+ export interface ProtectedRouteProps {
3
+ children: ReactNode;
4
+ fallback?: ReactNode;
5
+ redirectTo?: string;
6
+ }
7
+ export declare function ProtectedRoute({ children, fallback, redirectTo }: ProtectedRouteProps): string | number | true | Iterable<React.ReactNode> | import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,17 @@
1
+ import { CAMSConfig, CAMSError, Profile } from '@nibssplc/cams-sdk';
2
+ export interface UseCAMSAuthOptions {
3
+ storageKey?: string;
4
+ onAuthSuccess?: (token: string) => void;
5
+ onAuthError?: (error: CAMSError) => void;
6
+ onTokenExpired?: () => void;
7
+ }
8
+ export interface UseCAMSAuthReturn {
9
+ login: (config: CAMSConfig) => Promise<void>;
10
+ logout: () => Promise<void>;
11
+ isAuthenticated: boolean;
12
+ isLoading: boolean;
13
+ error: CAMSError | null;
14
+ token: string | null;
15
+ profile: Profile | null;
16
+ }
17
+ export declare function useCAMSAuth(options?: UseCAMSAuthOptions): UseCAMSAuthReturn;
@@ -0,0 +1,23 @@
1
+ import { AccountInfo } from "@azure/msal-browser";
2
+ import { CAMSError, Profile } from "@nibssplc/cams-sdk";
3
+ export interface UseCAMSMSALAuthOptions {
4
+ onAuthSuccess?: (token: string) => void;
5
+ onAuthError?: (error: CAMSError) => void;
6
+ onTokenExpired?: () => void;
7
+ onMFARequired?: (msalToken: string, account: AccountInfo) => void;
8
+ scopes?: string[];
9
+ mfaUrl?: string;
10
+ }
11
+ export interface UseCAMSMSALAuthReturn {
12
+ login: () => Promise<void>;
13
+ logout: () => Promise<void>;
14
+ completeMFA: (mfaToken: string) => void;
15
+ isAuthenticated: boolean;
16
+ isLoading: boolean;
17
+ isMFAPending: boolean;
18
+ error: CAMSError | null;
19
+ token: string | null;
20
+ profile: Profile | null;
21
+ account: AccountInfo | null;
22
+ }
23
+ export declare function useCAMSMSALAuth(options?: UseCAMSMSALAuthOptions): UseCAMSMSALAuthReturn;