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

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.
@@ -0,0 +1,2 @@
1
+ import { type ClassValue } from "clsx";
2
+ export declare function cn(...inputs: ClassValue[]): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nibssplc/cams-sdk-react",
3
- "version": "0.0.1-beta.55",
3
+ "version": "0.0.1-beta.58",
4
4
  "description": "React hooks and components for NIBSS CAMS SDK",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "module": "./dist/index.esm.js",
@@ -29,8 +29,24 @@
29
29
  "author": "NIBSS PLC, Caleb Boluwade",
30
30
  "license": "MIT",
31
31
  "dependencies": {
32
- "@nibssplc/cams-sdk": "^0.0.1-beta.33",
33
- "tslib": "^2.6.0"
32
+ "@hookform/resolvers": "^5.2.2",
33
+ "@nibssplc/cams-sdk": "^0.0.1-beta.35",
34
+ "@radix-ui/react-dialog": "^1.1.15",
35
+ "@radix-ui/react-label": "^2.1.7",
36
+ "@radix-ui/react-slot": "^1.2.3",
37
+ "axios": "^1.12.2",
38
+ "class-variance-authority": "^0.7.1",
39
+ "clsx": "^2.1.1",
40
+ "framer-motion": "^12.23.22",
41
+ "input-otp": "^1.4.2",
42
+ "ldrs": "^1.1.7",
43
+ "lucide-react": "^0.544.0",
44
+ "react-hook-form": "^7.63.0",
45
+ "sonner": "^2.0.7",
46
+ "tailwind": "^4.0.0",
47
+ "tailwind-merge": "^3.3.1",
48
+ "tslib": "^2.6.0",
49
+ "zod": "^4.1.11"
34
50
  },
35
51
  "optionalDependencies": {
36
52
  "@azure/msal-browser": "^3.0.0",
@@ -42,6 +58,7 @@
42
58
  },
43
59
  "devDependencies": {
44
60
  "@rollup/plugin-commonjs": "^25.0.7",
61
+ "@rollup/plugin-json": "^6.1.0",
45
62
  "@rollup/plugin-node-resolve": "^15.2.3",
46
63
  "@rollup/plugin-typescript": "^11.1.6",
47
64
  "@testing-library/jest-dom": "^6.8.0",
@@ -50,9 +67,11 @@
50
67
  "@types/react-dom": "^19",
51
68
  "jest": "^29.7.0",
52
69
  "jest-environment-jsdom": "^29.7.0",
70
+ "postcss": "^8.5.6",
53
71
  "react": "^19.1.0",
54
72
  "react-dom": "^19.1.0",
55
73
  "rollup": "^4.21.1",
74
+ "rollup-plugin-postcss": "^4.0.2",
56
75
  "ts-jest": "^29.4.4",
57
76
  "typescript": "^5.4.5"
58
77
  },
package/README.md DELETED
@@ -1,397 +0,0 @@
1
- # NIBSS CAMS SDK - React
2
-
3
- React hooks and components for NIBSS CAMS SDK with support for popup authentication and Azure AD MSAL integration.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install @nibssplc/cams-sdk-react
9
-
10
- # For Azure AD MSAL 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, useCAMSContext } from '@nibssplc/cams-sdk-react';
20
-
21
- function App() {
22
- return (
23
- <CAMSProvider appCode="your-app-code" storageKey="CAMS-AUTH-SDK">
24
- <LoginComponent />
25
- </CAMSProvider>
26
- );
27
- }
28
-
29
- function LoginComponent() {
30
- const { login, logout, isAuthenticated, isLoading, userProfile, error } = useCAMSContext();
31
-
32
- const handleLogin = async () => {
33
- try {
34
- await login({
35
- camsUrl: 'https://your-cams-instance.com/auth',
36
- messageOrigin: 'your-cams-instance.com',
37
- windowWidth: 500,
38
- windowHeight: 600,
39
- });
40
- } catch (err) {
41
- console.error('Login failed:', err);
42
- }
43
- };
44
-
45
- if (error) {
46
- return <div>Error: {error.message}</div>;
47
- }
48
-
49
- if (isAuthenticated) {
50
- return (
51
- <div>
52
- <p>Welcome, {userProfile?.name}!</p>
53
- <button onClick={logout}>Logout</button>
54
- </div>
55
- );
56
- }
57
-
58
- return (
59
- <button onClick={handleLogin} disabled={isLoading}>
60
- {isLoading ? 'Logging in...' : 'Login'}
61
- </button>
62
- );
63
- }
64
- ```
65
-
66
- ### Direct Hook Usage
67
-
68
- ```tsx
69
- import { useCAMSAuth } from '@nibssplc/cams-sdk-react';
70
-
71
- function LoginComponent() {
72
- const {
73
- login,
74
- logout,
75
- isAuthenticated,
76
- isLoading,
77
- error,
78
- token,
79
- profile
80
- } = useCAMSAuth({
81
- appCode: 'your-app-code',
82
- storageKey: 'CAMS-AUTH-SDK',
83
- onAuthSuccess: (token) => console.log('Login successful'),
84
- onAuthError: (error) => console.error('Login failed:', error),
85
- });
86
-
87
- const handleLogin = async () => {
88
- await login({
89
- camsUrl: 'https://your-cams-instance.com/auth',
90
- messageOrigin: 'your-cams-instance.com',
91
- windowWidth: 500,
92
- windowHeight: 600,
93
- });
94
- };
95
-
96
- return (
97
- <div>
98
- {isAuthenticated ? (
99
- <div>
100
- <p>Welcome, {profile?.name}!</p>
101
- <p>Token: {token}</p>
102
- <button onClick={logout}>Logout</button>
103
- </div>
104
- ) : (
105
- <button onClick={handleLogin} disabled={isLoading}>
106
- {isLoading ? 'Logging in...' : 'Login'}
107
- </button>
108
- )}
109
- {error && <div>Error: {error.message}</div>}
110
- </div>
111
- );
112
- }
113
- ```
114
-
115
- ### Azure AD MSAL Integration with MFA
116
-
117
- ```tsx
118
- import { CAMSMSALProvider, useCAMSMSALContext } from '@nibssplc/cams-sdk-react';
119
- import { Configuration } from '@azure/msal-browser';
120
-
121
- const msalConfig: Configuration = {
122
- auth: {
123
- clientId: 'your-client-id',
124
- authority: 'https://login.microsoftonline.com/your-tenant-id',
125
- redirectUri: window.location.origin,
126
- },
127
- };
128
-
129
- function App() {
130
- return (
131
- <CAMSMSALProvider
132
- msalConfig={msalConfig}
133
- mfaUrl="/auth/multi-factor"
134
- storageKey="CAMS-MSAL-AUTH-SDK"
135
- scopes={['openid', 'profile', 'email']}
136
- onAuthSuccess={(token) => console.log('Auth complete:', token)}
137
- onAuthError={(error) => console.error('Auth failed:', error)}
138
- >
139
- <LoginComponent />
140
- </CAMSMSALProvider>
141
- );
142
- }
143
-
144
- function LoginComponent() {
145
- const {
146
- login,
147
- logout,
148
- isAuthenticated,
149
- isLoading,
150
- error,
151
- userProfile,
152
- accessToken,
153
- idToken
154
- } = useCAMSMSALContext();
155
-
156
- if (error) {
157
- return <div>Error: {error.message}</div>;
158
- }
159
-
160
- if (isAuthenticated) {
161
- return (
162
- <div>
163
- <p>Welcome, {userProfile?.name}!</p>
164
- <p>Access Token: {accessToken}</p>
165
- <button onClick={logout}>Logout</button>
166
- </div>
167
- );
168
- }
169
-
170
- return (
171
- <button onClick={login} disabled={isLoading}>
172
- {isLoading ? 'Logging in...' : 'Login with Azure AD'}
173
- </button>
174
- );
175
- }
176
- ```
177
-
178
- ### Direct MSAL Hook Usage
179
-
180
- ```tsx
181
- import { useCAMSMSALAuth } from '@nibssplc/cams-sdk-react';
182
- import { useMsal } from '@azure/msal-react';
183
-
184
- function LoginComponent() {
185
- const {
186
- login,
187
- logout,
188
- isAuthenticated,
189
- isLoading,
190
- error,
191
- accessToken,
192
- idToken,
193
- appCode
194
- } = useCAMSMSALAuth({
195
- mfaUrl: '/auth/multi-factor',
196
- storageKey: 'CAMS-MSAL-AUTH-SDK',
197
- scopes: ['openid', 'profile', 'email'],
198
- onAuthSuccess: (token) => console.log('Login successful'),
199
- onAuthError: (error) => console.error('Login failed:', error),
200
- });
201
-
202
- return (
203
- <div>
204
- {isAuthenticated ? (
205
- <div>
206
- <p>Access Token: {accessToken}</p>
207
- <p>ID Token: {idToken}</p>
208
- <button onClick={logout}>Logout</button>
209
- </div>
210
- ) : (
211
- <button onClick={login} disabled={isLoading}>
212
- {isLoading ? 'Logging in...' : 'Login with Azure AD'}
213
- </button>
214
- )}
215
- {error && <div>Error: {error.message}</div>}
216
- </div>
217
- );
218
- }
219
- ```
220
-
221
- ## API Reference
222
-
223
- ### useCAMSAuth
224
-
225
- Hook for popup-based CAMS authentication.
226
-
227
- ```tsx
228
- const {
229
- login, // (config: CAMSConfig) => Promise<void>
230
- logout, // () => Promise<void>
231
- isAuthenticated, // boolean
232
- isLoading, // boolean
233
- error, // CAMSError | null
234
- token, // string | null
235
- profile, // Profile | null
236
- appCode, // string
237
- storageKey, // string
238
- } = useCAMSAuth(options);
239
- ```
240
-
241
- **Options:**
242
- - `appCode: string` - Application code (required)
243
- - `storageKey?: string` - Storage key (default: "CAMS-AUTH-SDK")
244
- - `onAuthSuccess?: (token: string) => void` - Success callback
245
- - `onAuthError?: (error: CAMSError) => void` - Error callback
246
- - `onTokenExpired?: () => void` - Token expiration callback
247
-
248
- ### useCAMSMSALAuth
249
-
250
- Hook for Azure AD MSAL authentication with MFA support.
251
-
252
- ```tsx
253
- const {
254
- login, // () => Promise<void>
255
- logout, // () => Promise<void>
256
- isAuthenticated, // boolean
257
- isLoading, // boolean
258
- error, // CAMSError | null
259
- idToken, // string
260
- accessToken, // string
261
- appCode, // string
262
- storageKey, // string
263
- } = useCAMSMSALAuth(options);
264
- ```
265
-
266
- **Options:**
267
- - `mfaUrl?: string` - MFA URL (default: "/auth/multi-factor")
268
- - `storageKey?: string` - Storage key (default: "CAMS-MSAL-AUTH-SDK")
269
- - `scopes?: string[]` - MSAL scopes (default: ["openid", "profile", "email"])
270
- - `prompt?: string` - MSAL prompt (default: "login")
271
- - `allowedOrigins?: string[]` - Allowed message origins
272
- - `messageOrigin?: string` - Expected message origin
273
- - `onAuthSuccess?: (token: string) => void` - Success callback
274
- - `onAuthError?: (error: CAMSError) => void` - Error callback
275
-
276
- ### CAMSProvider
277
-
278
- Provider component for popup-based authentication.
279
-
280
- ```tsx
281
- <CAMSProvider
282
- appCode="your-app-code"
283
- storageKey="CAMS-AUTH-SDK"
284
- onAuthSuccess={(token) => console.log('Success')}
285
- onAuthError={(error) => console.error('Error:', error)}
286
- onTokenExpired={() => console.log('Token expired')}
287
- >
288
- {children}
289
- </CAMSProvider>
290
- ```
291
-
292
- ### CAMSMSALProvider
293
-
294
- Provider component for Azure AD MSAL integration.
295
-
296
- ```tsx
297
- <CAMSMSALProvider
298
- msalConfig={config}
299
- msalInstance={instance}
300
- mfaUrl="/auth/multi-factor"
301
- storageKey="CAMS-MSAL-AUTH-SDK"
302
- scopes={['openid', 'profile', 'email']}
303
- onAuthSuccess={(token) => console.log('Success')}
304
- onAuthError={(error) => console.error('Error:', error)}
305
- >
306
- {children}
307
- </CAMSMSALProvider>
308
- ```
309
-
310
- **Props:**
311
- - `msalConfig: Configuration` - MSAL configuration object (required)
312
- - `msalInstance?: PublicClientApplication` - Optional pre-configured MSAL instance
313
- - `children: ReactNode` - Child components
314
- - All `UseCAMSMSALAuthOptions` are also supported as props
315
-
316
- ### Context Hooks
317
-
318
- #### useCAMSContext
319
-
320
- Access CAMS authentication context (must be used within `CAMSProvider`).
321
-
322
- ```tsx
323
- const {
324
- login, logout, isAuthenticated, isLoading, error, token, profile,
325
- userProfile, setUserProfile, appCode, storageKey
326
- } = useCAMSContext();
327
- ```
328
-
329
- #### useCAMSMSALContext
330
-
331
- Access CAMS MSAL authentication context (must be used within `CAMSMSALProvider`).
332
-
333
- ```tsx
334
- const {
335
- login, logout, isAuthenticated, isLoading, error,
336
- idToken, accessToken, appCode, storageKey,
337
- userProfile, setUserProfile
338
- } = useCAMSMSALContext();
339
- ```
340
-
341
- ### Components
342
-
343
- #### ProtectedRoute
344
-
345
- Route component that requires authentication.
346
-
347
- ```tsx
348
- <ProtectedRoute fallback={<LoginPage />}>
349
- <Dashboard />
350
- </ProtectedRoute>
351
- ```
352
-
353
- #### ClientOnly
354
-
355
- Wrapper component for client-side only rendering (useful for SSR).
356
-
357
- ```tsx
358
- <ClientOnly fallback={<div>Loading...</div>}>
359
- <CAMSProvider>
360
- <App />
361
- </CAMSProvider>
362
- </ClientOnly>
363
- ```
364
-
365
- ## Types
366
-
367
- ### Profile
368
-
369
- ```typescript
370
- interface Profile {
371
- userProfile: {
372
- name: string;
373
- image?: string | null;
374
- tokens: {
375
- Bearer: string;
376
- };
377
- };
378
- }
379
- ```
380
-
381
- ### CAMSError
382
-
383
- ```typescript
384
- class CAMSError extends Error {
385
- constructor(public type: CAMSErrorType, message: string);
386
- }
387
-
388
- enum CAMSErrorType {
389
- POPUP_BLOCKED = "POPUP_BLOCKED",
390
- TIMEOUT = "TIMEOUT",
391
- INVALID_ORIGIN = "INVALID_ORIGIN",
392
- USER_CANCELLED = "USER_CANCELLED",
393
- INVALID_URL = "INVALID_URL",
394
- MAX_RETRIES_EXCEEDED = "MAX_RETRIES_EXCEEDED",
395
- API_VALIDATION_ERROR = "VALIDATION_ERROR",
396
- }
397
- ```