@nibssplc/cams-sdk-react 1.0.0-rc.3 → 1.0.0-rc.31

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
@@ -18,6 +18,158 @@ import * as DialogPrimitive from '@radix-ui/react-dialog';
18
18
  import { toast } from 'sonner';
19
19
  import { motion } from 'framer-motion';
20
20
  import axios from 'axios';
21
+ import https from 'https';
22
+
23
+ // Crypto polyfill for MSAL browser compatibility
24
+ if (typeof window !== 'undefined') {
25
+ // Ensure crypto object exists
26
+ if (!window.crypto) {
27
+ try {
28
+ Object.defineProperty(window, 'crypto', {
29
+ value: {},
30
+ writable: true,
31
+ configurable: true
32
+ });
33
+ }
34
+ catch (e) {
35
+ // Ignore if crypto cannot be defined
36
+ }
37
+ }
38
+ // Polyfill getRandomValues
39
+ if (window.crypto && !window.crypto.getRandomValues) {
40
+ try {
41
+ Object.defineProperty(window.crypto, 'getRandomValues', {
42
+ value: function (array) {
43
+ var bytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
44
+ for (var i = 0; i < bytes.length; i++) {
45
+ bytes[i] = Math.floor(Math.random() * 256);
46
+ }
47
+ return array;
48
+ },
49
+ writable: true,
50
+ configurable: true
51
+ });
52
+ }
53
+ catch (e) {
54
+ // Ignore if getRandomValues cannot be defined
55
+ }
56
+ }
57
+ // Force polyfill crypto.subtle on localhost and non-HTTPS contexts
58
+ if (window.crypto) {
59
+ var sha256_1 = function (data) { return __awaiter(void 0, void 0, void 0, function () {
60
+ var bytes, hash, k, ml, msg, i, w, j, j, s0, s1, a, b, c, d, e, f, g, h, j, S1, ch, temp1, S0, maj, temp2, result, i;
61
+ return __generator(this, function (_a) {
62
+ bytes = new Uint8Array(data);
63
+ hash = new Uint32Array(8);
64
+ k = new Uint32Array([
65
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
66
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
67
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
68
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
69
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
70
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
71
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
72
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
73
+ ]);
74
+ hash[0] = 0x6a09e667;
75
+ hash[1] = 0xbb67ae85;
76
+ hash[2] = 0x3c6ef372;
77
+ hash[3] = 0xa54ff53a;
78
+ hash[4] = 0x510e527f;
79
+ hash[5] = 0x9b05688c;
80
+ hash[6] = 0x1f83d9ab;
81
+ hash[7] = 0x5be0cd19;
82
+ ml = bytes.length * 8;
83
+ msg = new Uint8Array(bytes.length + 64 + ((64 - ((bytes.length + 9) % 64)) % 64));
84
+ msg.set(bytes);
85
+ msg[bytes.length] = 0x80;
86
+ new DataView(msg.buffer).setUint32(msg.length - 4, ml, false);
87
+ for (i = 0; i < msg.length; i += 64) {
88
+ w = new Uint32Array(64);
89
+ for (j = 0; j < 16; j++)
90
+ w[j] = new DataView(msg.buffer).getUint32(i + j * 4, false);
91
+ for (j = 16; j < 64; j++) {
92
+ s0 = ((w[j - 15] >>> 7) | (w[j - 15] << 25)) ^ ((w[j - 15] >>> 18) | (w[j - 15] << 14)) ^ (w[j - 15] >>> 3);
93
+ s1 = ((w[j - 2] >>> 17) | (w[j - 2] << 15)) ^ ((w[j - 2] >>> 19) | (w[j - 2] << 13)) ^ (w[j - 2] >>> 10);
94
+ w[j] = (w[j - 16] + s0 + w[j - 7] + s1) >>> 0;
95
+ }
96
+ a = hash[0], b = hash[1], c = hash[2], d = hash[3], e = hash[4], f = hash[5], g = hash[6], h = hash[7];
97
+ for (j = 0; j < 64; j++) {
98
+ S1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7));
99
+ ch = (e & f) ^ (~e & g);
100
+ temp1 = (h + S1 + ch + k[j] + w[j]) >>> 0;
101
+ S0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10));
102
+ maj = (a & b) ^ (a & c) ^ (b & c);
103
+ temp2 = (S0 + maj) >>> 0;
104
+ h = g;
105
+ g = f;
106
+ f = e;
107
+ e = (d + temp1) >>> 0;
108
+ d = c;
109
+ c = b;
110
+ b = a;
111
+ a = (temp1 + temp2) >>> 0;
112
+ }
113
+ hash[0] = (hash[0] + a) >>> 0;
114
+ hash[1] = (hash[1] + b) >>> 0;
115
+ hash[2] = (hash[2] + c) >>> 0;
116
+ hash[3] = (hash[3] + d) >>> 0;
117
+ hash[4] = (hash[4] + e) >>> 0;
118
+ hash[5] = (hash[5] + f) >>> 0;
119
+ hash[6] = (hash[6] + g) >>> 0;
120
+ hash[7] = (hash[7] + h) >>> 0;
121
+ }
122
+ result = new Uint8Array(32);
123
+ for (i = 0; i < 8; i++)
124
+ new DataView(result.buffer).setUint32(i * 4, hash[i], false);
125
+ return [2 /*return*/, result.buffer];
126
+ });
127
+ }); };
128
+ var originalSubtle_1 = window.crypto.subtle;
129
+ try {
130
+ Object.defineProperty(window.crypto, 'subtle', {
131
+ value: {
132
+ digest: function (algorithm, data) { return __awaiter(void 0, void 0, void 0, function () {
133
+ var alg;
134
+ return __generator(this, function (_a) {
135
+ alg = typeof algorithm === 'string' ? algorithm : algorithm.name;
136
+ if (alg === 'SHA-256')
137
+ return [2 /*return*/, sha256_1(data)];
138
+ // Fallback to original if available
139
+ if (originalSubtle_1 === null || originalSubtle_1 === void 0 ? void 0 : originalSubtle_1.digest)
140
+ return [2 /*return*/, originalSubtle_1.digest(algorithm, data)];
141
+ throw new Error("Unsupported algorithm: ".concat(alg));
142
+ });
143
+ }); }
144
+ },
145
+ writable: true,
146
+ configurable: true
147
+ });
148
+ }
149
+ catch (e) {
150
+ // Ignore if subtle cannot be defined
151
+ }
152
+ }
153
+ // Polyfill randomUUID
154
+ if (window.crypto && !window.crypto.randomUUID) {
155
+ try {
156
+ Object.defineProperty(window.crypto, 'randomUUID', {
157
+ value: function () {
158
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
159
+ var r = (Math.random() * 16) | 0;
160
+ var v = c === 'x' ? r : (r & 0x3) | 0x8;
161
+ return v.toString(16);
162
+ });
163
+ },
164
+ writable: true,
165
+ configurable: true
166
+ });
167
+ }
168
+ catch (e) {
169
+ // Ignore if randomUUID cannot be defined
170
+ }
171
+ }
172
+ }
21
173
 
22
174
  /******************************************************************************
23
175
  Copyright (c) Microsoft Corporation.
@@ -59,7 +211,7 @@ function __rest(s, e) {
59
211
  return t;
60
212
  }
61
213
 
62
- function __awaiter(thisArg, _arguments, P, generator) {
214
+ function __awaiter$1(thisArg, _arguments, P, generator) {
63
215
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
64
216
  return new (P || (P = Promise))(function (resolve, reject) {
65
217
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -69,7 +221,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
69
221
  });
70
222
  }
71
223
 
72
- function __generator(thisArg, body) {
224
+ function __generator$1(thisArg, body) {
73
225
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
74
226
  return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
75
227
  function verb(n) { return function (v) { return step([n, v]); }; }
@@ -166,10 +318,10 @@ function useCAMSAuth(options) {
166
318
  }
167
319
  }
168
320
  }, [options.storageKey]);
169
- var login = useCallback(function (config) { return __awaiter(_this, void 0, void 0, function () {
321
+ var login = useCallback(function (config) { return __awaiter$1(_this, void 0, void 0, function () {
170
322
  var loginConfig, userProfile, err_1, e, isPopupClosedError, restoredToken, userProfile;
171
323
  var _a, _b, _c;
172
- return __generator(this, function (_d) {
324
+ return __generator$1(this, function (_d) {
173
325
  switch (_d.label) {
174
326
  case 0:
175
327
  if (!sessionManagerRef.current)
@@ -217,8 +369,8 @@ function useCAMSAuth(options) {
217
369
  }
218
370
  });
219
371
  }); }, [options.idleTimeout]);
220
- var logout = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
221
- return __generator(this, function (_a) {
372
+ var logout = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
373
+ return __generator$1(this, function (_a) {
222
374
  switch (_a.label) {
223
375
  case 0:
224
376
  if (!sessionManagerRef.current)
@@ -248,11 +400,13 @@ function useCAMSAuth(options) {
248
400
  };
249
401
  }
250
402
 
251
- var setCookie$1 = function (name, value, days) {
403
+ var setCookie = function (name, value, days) {
404
+ if (days === void 0) { days = 1; }
252
405
  var expires = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString();
406
+ console.log("Auth Cookie Expires >>>", { name: name, value: value, expires: expires });
253
407
  document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
254
408
  };
255
- var getCookie$1 = function (name) {
409
+ var getCookie = function (name) {
256
410
  var _a;
257
411
  return ((_a = document.cookie
258
412
  .split("; ")
@@ -263,23 +417,24 @@ var getCookie$1 = function (name) {
263
417
  .split("=")[1])
264
418
  : null;
265
419
  };
266
- var deleteCookie$1 = function (name) {
420
+ var deleteCookie = function (name) {
267
421
  document.cookie = name + "=; Max-Age=-99999999; path=/";
268
422
  };
269
423
 
270
424
  function useCAMSMSALAuth(options) {
271
425
  var _this = this;
272
- var storageKey = options.storageKey || "CAMS-MSAL-AUTH-SDK";
273
- var _a = useMsal(), instance = _a.instance, inProgress = _a.inProgress, accounts = _a.accounts;
426
+ var optStorageKey = options.storageKey, optScopes = options.scopes, prompt = options.prompt, appCode = options.appCode, MFAEndpoint = options.MFAEndpoint, onAuthSuccess = options.onAuthSuccess, onAuthError = options.onAuthError, _a = options.activeCookiePeriod, activeCookiePeriod = _a === void 0 ? 1 : _a;
427
+ var storageKey = optStorageKey || "CAMS-MSAL-AUTH-SDK";
428
+ var _b = useMsal(), instance = _b.instance, inProgress = _b.inProgress, accounts = _b.accounts;
274
429
  var account = useAccount(accounts[0] || {});
275
- var _b = useState(null), error = _b[0], setError = _b[1];
276
- var _c = useState(""), idToken = _c[0], setIdToken = _c[1];
277
- var _d = useState(""), accessToken = _d[0], setAccessToken = _d[1];
278
- var _e = useState(null), mfaAuthenticator = _e[0], setMfaAuthenticator = _e[1];
279
- var _f = useState(false), requiresMFA = _f[0], setRequiresMFA = _f[1];
430
+ var _c = useState(null), error = _c[0], setError = _c[1];
431
+ var _d = useState(""), idToken = _d[0], setIdToken = _d[1];
432
+ var _e = useState(""), accessToken = _e[0], setAccessToken = _e[1];
433
+ var _f = useState(null), mfaAuthenticator = _f[0], setMfaAuthenticator = _f[1];
434
+ var _g = useState(false), requiresMFA = _g[0], setRequiresMFA = _g[1];
280
435
  var isLoading = inProgress !== InteractionStatus.None;
281
436
  var isAuthenticated = !!account && !!accessToken && !requiresMFA;
282
- var scopes = options.scopes || ["openid", "profile", "email"];
437
+ var scopes = optScopes || ["openid", "profile", "email"];
283
438
  var isTokenValid = function (token) {
284
439
  try {
285
440
  var payload = JSON.parse(atob(token.split(".")[1]));
@@ -303,15 +458,14 @@ function useCAMSMSALAuth(options) {
303
458
  var mfaConfig = {
304
459
  accessToken: accessToken_1,
305
460
  idToken: idToken_1,
306
- appCode: options.appCode,
461
+ appCode: appCode,
307
462
  provider: "MSAL",
308
- apiEndpoint: options.MFAEndpoint,
463
+ apiEndpoint: MFAEndpoint,
309
464
  };
310
465
  var authenticator = new CAMSMFAAuthenticator(mfaConfig);
311
466
  setMfaAuthenticator(authenticator);
312
467
  setRequiresMFA(true);
313
468
  }
314
- Logger.debug("App Code", { ">>>": options.appCode });
315
469
  }
316
470
  else {
317
471
  localStorage.removeItem(storageKey);
@@ -353,22 +507,26 @@ function useCAMSMSALAuth(options) {
353
507
  // };
354
508
  // handleRedirect();
355
509
  // }, []);
356
- var login = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
510
+ var login = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
357
511
  var response, mfaConfig, authenticator, err_1, camsError_1, camsError;
358
- var _a, _b, _c, _d;
359
- return __generator(this, function (_e) {
360
- switch (_e.label) {
512
+ var _a;
513
+ return __generator$1(this, function (_b) {
514
+ switch (_b.label) {
361
515
  case 0:
516
+ if (inProgress !== InteractionStatus.None) {
517
+ Logger.warn("Authentication already in progress, ignoring duplicate call");
518
+ return [2 /*return*/];
519
+ }
362
520
  setError(null);
363
- _e.label = 1;
521
+ _b.label = 1;
364
522
  case 1:
365
- _e.trys.push([1, 3, , 4]);
523
+ _b.trys.push([1, 3, , 4]);
366
524
  return [4 /*yield*/, instance.loginPopup({
367
525
  scopes: scopes,
368
- prompt: options.prompt || "login",
526
+ prompt: prompt || "login",
369
527
  })];
370
528
  case 2:
371
- response = _e.sent();
529
+ response = _b.sent();
372
530
  console.log("Login Token response:", {
373
531
  accessToken: response.accessToken,
374
532
  idToken: response.idToken,
@@ -378,9 +536,9 @@ function useCAMSMSALAuth(options) {
378
536
  mfaConfig = {
379
537
  accessToken: response.accessToken,
380
538
  idToken: response.idToken,
381
- appCode: options.appCode,
539
+ appCode: appCode,
382
540
  provider: "MSAL",
383
- apiEndpoint: options.MFAEndpoint,
541
+ apiEndpoint: MFAEndpoint,
384
542
  };
385
543
  authenticator = new CAMSMFAAuthenticator(mfaConfig);
386
544
  setMfaAuthenticator(authenticator);
@@ -394,10 +552,15 @@ function useCAMSMSALAuth(options) {
394
552
  idToken: response.idToken,
395
553
  }));
396
554
  }
397
- (_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
555
+ onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess(response.accessToken);
398
556
  return [3 /*break*/, 4];
399
557
  case 3:
400
- err_1 = _e.sent();
558
+ err_1 = _b.sent();
559
+ // Handle interaction_in_progress error
560
+ if (err_1.errorCode === "interaction_in_progress") {
561
+ Logger.warn("Interaction already in progress, please wait");
562
+ return [2 /*return*/];
563
+ }
401
564
  // Handle user cancellation gracefully
402
565
  if (err_1.errorCode === "user_cancelled") {
403
566
  Logger.error("User cancelled login");
@@ -406,22 +569,22 @@ function useCAMSMSALAuth(options) {
406
569
  }
407
570
  // If popup is blocked
408
571
  if (err_1.errorCode === "popup_window_error" ||
409
- ((_b = err_1.message) === null || _b === void 0 ? void 0 : _b.includes("popup"))) {
572
+ ((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.includes("popup"))) {
410
573
  camsError_1 = new CAMSError(CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
411
574
  setError(camsError_1);
412
- (_c = options.onAuthError) === null || _c === void 0 ? void 0 : _c.call(options, camsError_1);
575
+ onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError_1);
413
576
  return [2 /*return*/];
414
577
  }
415
578
  camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1.message || err_1);
416
579
  setError(camsError);
417
- (_d = options.onAuthError) === null || _d === void 0 ? void 0 : _d.call(options, camsError);
580
+ onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError);
418
581
  return [3 /*break*/, 4];
419
582
  case 4: return [2 /*return*/];
420
583
  }
421
584
  });
422
- }); }, [instance, scopes, options]);
423
- var completeMFA = useCallback(function (data) { return __awaiter(_this, void 0, void 0, function () {
424
- return __generator(this, function (_a) {
585
+ }); }, [instance, scopes, prompt, appCode, MFAEndpoint, onAuthSuccess, onAuthError, storageKey, inProgress]);
586
+ var completeMFA = useCallback(function (data) { return __awaiter$1(_this, void 0, void 0, function () {
587
+ return __generator$1(this, function (_a) {
425
588
  if (!mfaAuthenticator) {
426
589
  throw new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "MFA Authenticator not initialized");
427
590
  }
@@ -435,7 +598,7 @@ function useCAMSMSALAuth(options) {
435
598
  accessToken: accessToken,
436
599
  idToken: idToken,
437
600
  }));
438
- setCookie$1("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), 1);
601
+ setCookie("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), activeCookiePeriod);
439
602
  setRequiresMFA(false);
440
603
  // Set requiresMFA to false after storage update
441
604
  Logger.debug("MFA completed successfully, storage updated", {
@@ -454,9 +617,9 @@ function useCAMSMSALAuth(options) {
454
617
  }
455
618
  return [2 /*return*/];
456
619
  });
457
- }); }, [mfaAuthenticator, accessToken, idToken, storageKey]);
458
- var sendEmailOTP = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
459
- return __generator(this, function (_a) {
620
+ }); }, [mfaAuthenticator, accessToken, idToken, storageKey, activeCookiePeriod]);
621
+ var sendEmailOTP = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
622
+ return __generator$1(this, function (_a) {
460
623
  switch (_a.label) {
461
624
  case 0:
462
625
  if (!mfaAuthenticator) {
@@ -467,9 +630,9 @@ function useCAMSMSALAuth(options) {
467
630
  }
468
631
  });
469
632
  }); }, [mfaAuthenticator]);
470
- var logout = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
633
+ var logout = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
471
634
  var err_2, camsError;
472
- return __generator(this, function (_a) {
635
+ return __generator$1(this, function (_a) {
473
636
  switch (_a.label) {
474
637
  case 0:
475
638
  _a.trys.push([0, 2, , 3]);
@@ -505,12 +668,13 @@ function useCAMSMSALAuth(options) {
505
668
  error: error,
506
669
  idToken: idToken,
507
670
  accessToken: accessToken,
508
- appCode: options.appCode,
671
+ appCode: appCode,
509
672
  mfaAuthenticator: mfaAuthenticator,
510
673
  requiresMFA: requiresMFA,
511
674
  completeMFA: completeMFA,
512
675
  sendEmailOTP: sendEmailOTP,
513
676
  setRequiresMFA: setRequiresMFA,
677
+ activeCookiePeriod: activeCookiePeriod,
514
678
  };
515
679
  }
516
680
 
@@ -553,10 +717,10 @@ function arrayBufferToBase64url(buffer) {
553
717
  * @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
554
718
  */
555
719
  function register(options) {
556
- return __awaiter(this, void 0, void 0, function () {
720
+ return __awaiter$1(this, void 0, void 0, function () {
557
721
  var createOptions, credential, publicKeyCredential, attestationResponse, transports, err_1;
558
722
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
559
- return __generator(this, function (_k) {
723
+ return __generator$1(this, function (_k) {
560
724
  switch (_k.label) {
561
725
  case 0:
562
726
  _k.trys.push([0, 2, , 3]);
@@ -614,10 +778,10 @@ function register(options) {
614
778
  * @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
615
779
  */
616
780
  function authenticate(options) {
617
- return __awaiter(this, void 0, void 0, function () {
781
+ return __awaiter$1(this, void 0, void 0, function () {
618
782
  var getOptions, credential, publicKeyCredential, assertionResponse;
619
783
  var _a;
620
- return __generator(this, function (_b) {
784
+ return __generator$1(this, function (_b) {
621
785
  switch (_b.label) {
622
786
  case 0:
623
787
  getOptions = __assign(__assign({}, options), { challenge: base64urlToArrayBuffer(options.challenge), allowCredentials: (_a = options.allowCredentials) === null || _a === void 0 ? void 0 : _a.map(function (cred) { return (__assign(__assign({}, cred), { id: base64urlToArrayBuffer(cred.id) })); }) });
@@ -1103,24 +1267,6 @@ function ProtectedRoute(_a) {
1103
1267
  }
1104
1268
 
1105
1269
  var CAMSMSALContext = createContext(null);
1106
- var setCookie = function (name, value, days) {
1107
- var expires = new Date(Date.now() + days * 864e5).toUTCString();
1108
- document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
1109
- };
1110
- var getCookie = function (name) {
1111
- var _a;
1112
- return ((_a = document.cookie
1113
- .split("; ")
1114
- .find(function (row) { return row.startsWith(name + "="); })) === null || _a === void 0 ? void 0 : _a.split("=")[1])
1115
- ? decodeURIComponent(document.cookie
1116
- .split("; ")
1117
- .find(function (row) { return row.startsWith(name + "="); })
1118
- .split("=")[1])
1119
- : null;
1120
- };
1121
- var deleteCookie = function (name) {
1122
- document.cookie = name + "=; Max-Age=-99999999; path=/";
1123
- };
1124
1270
  var isTokenValid = function (token) {
1125
1271
  try {
1126
1272
  var payload = JSON.parse(atob(token.split(".")[1]));
@@ -1169,7 +1315,7 @@ function CAMSMSALProviderInner(_a) {
1169
1315
  localStorage.setItem(auth.storageKey, JSON.stringify({
1170
1316
  accessToken: auth.accessToken,
1171
1317
  idToken: auth.idToken,
1172
- appCode: auth.appCode
1318
+ appCode: auth.appCode,
1173
1319
  }));
1174
1320
  }
1175
1321
  }, [auth.accessToken, auth.idToken, auth.storageKey]);
@@ -1185,8 +1331,8 @@ function CAMSMSALProviderInner(_a) {
1185
1331
  }
1186
1332
  }, [userProfile, profileStorageKey]);
1187
1333
  // Enhanced logout that also clears profile
1188
- var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
1189
- return __generator(this, function (_a) {
1334
+ var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
1335
+ return __generator$1(this, function (_a) {
1190
1336
  switch (_a.label) {
1191
1337
  case 0: return [4 /*yield*/, auth.logout()];
1192
1338
  case 1:
@@ -1253,7 +1399,7 @@ function CAMSProviderCore(props) {
1253
1399
  if (typeof window === "undefined")
1254
1400
  return null;
1255
1401
  try {
1256
- var storedProfile = getCookie$1(profileStorageKey);
1402
+ var storedProfile = getCookie(profileStorageKey);
1257
1403
  return storedProfile ? JSON.parse(storedProfile) : null;
1258
1404
  }
1259
1405
  catch (_a) {
@@ -1263,7 +1409,7 @@ function CAMSProviderCore(props) {
1263
1409
  var _a = useState(getInitialProfile), userProfile = _a[0], setUserProfile = _a[1];
1264
1410
  useEffect(function () {
1265
1411
  if (typeof window !== "undefined") {
1266
- var storedProfile = getCookie$1(profileStorageKey);
1412
+ var storedProfile = getCookie(profileStorageKey);
1267
1413
  if (storedProfile) {
1268
1414
  try {
1269
1415
  setUserProfile(JSON.parse(storedProfile));
@@ -1275,22 +1421,22 @@ function CAMSProviderCore(props) {
1275
1421
  useEffect(function () {
1276
1422
  if (typeof window !== "undefined") {
1277
1423
  if (userProfile) {
1278
- setCookie$1(profileStorageKey, JSON.stringify(userProfile), 1);
1424
+ setCookie(profileStorageKey, JSON.stringify(userProfile), 1);
1279
1425
  }
1280
1426
  else {
1281
- deleteCookie$1(profileStorageKey);
1427
+ deleteCookie(profileStorageKey);
1282
1428
  }
1283
1429
  }
1284
1430
  }, [userProfile, profileStorageKey]);
1285
- var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
1286
- return __generator(this, function (_a) {
1431
+ var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
1432
+ return __generator$1(this, function (_a) {
1287
1433
  switch (_a.label) {
1288
1434
  case 0: return [4 /*yield*/, auth.logout()];
1289
1435
  case 1:
1290
1436
  _a.sent();
1291
1437
  setUserProfile(null);
1292
1438
  if (typeof window !== "undefined") {
1293
- deleteCookie$1(profileStorageKey);
1439
+ deleteCookie(profileStorageKey);
1294
1440
  }
1295
1441
  return [2 /*return*/];
1296
1442
  }
@@ -1326,7 +1472,8 @@ function CAMSProviderCore(props) {
1326
1472
  userProfile,
1327
1473
  ]);
1328
1474
  var value = useMemo(function () {
1329
- return (__assign(__assign({}, auth), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode }));
1475
+ auth.logout; var authRest = __rest(auth, ["logout"]);
1476
+ return __assign(__assign({}, authRest), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode });
1330
1477
  }, [auth, userProfile, mode]);
1331
1478
  return jsxRuntimeExports.jsx(CAMSContext.Provider, { value: value, children: children });
1332
1479
  }
@@ -1334,7 +1481,7 @@ function UnifiedCAMSProvider(props) {
1334
1481
  // Validate appCode is a valid GUID
1335
1482
  var appCodeValidation = GuidSchema.safeParse(props.appCode);
1336
1483
  if (!appCodeValidation.success) {
1337
- throw new Error("Invalid appCode: ".concat(appCodeValidation.error.issues[0].message));
1484
+ throw new Error("Invalid CAS APP CODE: ".concat(appCodeValidation.error.issues[0].message));
1338
1485
  }
1339
1486
  if (props.mode === "MSAL") {
1340
1487
  var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
@@ -1702,7 +1849,7 @@ styleInject(css_248z);
1702
1849
 
1703
1850
  var LoadingSpinner = function (_a) {
1704
1851
  var loadingText = _a.loadingText;
1705
- return (jsxRuntimeExports.jsxs("div", { className: "flex flex-col justify-center items-center", children: [jsxRuntimeExports.jsx("script", { type: "module", defer: true, src: "https://cdn.jsdelivr.net/npm/ldrs/dist/auto/waveform.js" }), jsxRuntimeExports.jsx(r, { size: "35", stroke: "3.5", speed: "1", color: "green" }), loadingText && (jsxRuntimeExports.jsx("p", { className: "text-center font-semibold mt-3", children: "Loading..." }))] }));
1852
+ return (jsxRuntimeExports.jsxs("div", { className: "flex flex-col justify-center items-center h-full w-full py-10", children: [jsxRuntimeExports.jsx("script", { type: "module", defer: true, src: "https://cdn.jsdelivr.net/npm/ldrs/dist/auto/waveform.js" }), jsxRuntimeExports.jsx(r, { size: "35", stroke: "3.5", speed: "1", color: "green" }), loadingText && (jsxRuntimeExports.jsx("p", { className: "text-center font-semibold mt-3", children: "Loading..." }))] }));
1706
1853
  };
1707
1854
 
1708
1855
  var AuthSuccessAnimation = function (_a) {
@@ -1754,15 +1901,36 @@ var APIHeaders = {
1754
1901
  "X-API-VERSION": "1.0",
1755
1902
  };
1756
1903
 
1904
+ // Creates an Axios instance with a base URL determined by the environment (production or development).
1905
+ var axiosInstance = axios.create({
1906
+ httpsAgent: new https.Agent({ rejectUnauthorized: false }),
1907
+ headers: __assign({ "Content-Type": "application/json" }, APIHeaders),
1908
+ });
1909
+ // Intercepts outgoing requests to add authorization token, version header, and timeout settings.
1910
+ axiosInstance.interceptors.request.use(function (config) {
1911
+ var _a;
1912
+ config.timeout = Number((_a = process.env.NEXT_PUBLIC_API_TIMEOUT) !== null && _a !== void 0 ? _a : 605000);
1913
+ config.timeoutErrorMessage = "Operation Timed Out"; // Custom error message for timeouts.
1914
+ return config; // Returns the modified request configuration.
1915
+ }, function (axiosError) {
1916
+ var _a, _b;
1917
+ // Handles request errors.
1918
+ return {
1919
+ status: (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status, // Extracts HTTP status from the error response.
1920
+ message: axiosError.message, // Extracts the error message.
1921
+ data: (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.data, // Extracts response data from the error.
1922
+ };
1923
+ });
1924
+
1757
1925
  var MAX_ATTEMPTS = 3;
1758
1926
  var useOTPHandler = function (_a) {
1759
1927
  var provider = _a.provider, accessToken = _a.accessToken, idToken = _a.idToken, appCode = _a.appCode, authenticationType = _a.authenticationType, MFAEndpoint = _a.MFAEndpoint, onAuthComplete = _a.onAuthComplete;
1760
1928
  var _b = useState(false), loading = _b[0], setLoading = _b[1];
1761
1929
  var _c = useState(0), attemptCount = _c[0], setAttemptCount = _c[1];
1762
1930
  var _d = useState(false), isMaxAttemptsReached = _d[0], setIsMaxAttemptsReached = _d[1];
1763
- var handleSubmitOTP = useMemo(function () { return function (authenticationValue) { return __awaiter(void 0, void 0, void 0, function () {
1931
+ var handleSubmitOTP = useMemo(function () { return function (authenticationValue) { return __awaiter$1(void 0, void 0, void 0, function () {
1764
1932
  var currentAttempt, response, error_1, currentAttempt;
1765
- return __generator(this, function (_a) {
1933
+ return __generator$1(this, function (_a) {
1766
1934
  switch (_a.label) {
1767
1935
  case 0:
1768
1936
  if (isMaxAttemptsReached) {
@@ -1779,16 +1947,13 @@ var useOTPHandler = function (_a) {
1779
1947
  setAttemptCount(currentAttempt);
1780
1948
  if (authenticationType === null)
1781
1949
  return [2 /*return*/, false];
1782
- return [4 /*yield*/, axios.post(MFAEndpoint || "/api/auth/verify-mfa", {
1950
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoint || "/api/auth/verify-mfa", {
1783
1951
  provider: provider,
1784
1952
  accessToken: accessToken,
1785
1953
  idToken: idToken,
1786
1954
  authenticationType: authenticationType,
1787
1955
  MFACode: authenticationValue,
1788
1956
  appCode: appCode,
1789
- }, {
1790
- headers: APIHeaders,
1791
- timeout: 605000,
1792
1957
  })];
1793
1958
  case 2:
1794
1959
  response = (_a.sent()).data;
@@ -1855,23 +2020,20 @@ var useCredentialsHandler = function (onAuthComplete) {
1855
2020
  var _b = useState(0), attemptCount = _b[0], setAttemptCount = _b[1];
1856
2021
  var _c = useState(false), isMaxAttemptsReached = _c[0], setIsMaxAttemptsReached = _c[1];
1857
2022
  var handleSubmitCredentials = useMemo(function () {
1858
- return function (CredAuthEndpoint, credentials, appCode) { return __awaiter(void 0, void 0, void 0, function () {
2023
+ return function (CredAuthEndpoint, credentials, appCode) { return __awaiter$1(void 0, void 0, void 0, function () {
1859
2024
  var currentAttempt, response, error_2, currentAttempt;
1860
- return __generator(this, function (_a) {
2025
+ return __generator$1(this, function (_a) {
1861
2026
  switch (_a.label) {
1862
2027
  case 0:
1863
2028
  _a.trys.push([0, 2, 3, 4]);
1864
2029
  setLoading(true);
1865
2030
  currentAttempt = attemptCount + 1;
1866
2031
  setAttemptCount(currentAttempt);
1867
- return [4 /*yield*/, axios.post(CredAuthEndpoint, {
2032
+ return [4 /*yield*/, axiosInstance.post(CredAuthEndpoint, {
1868
2033
  username: credentials.username,
1869
2034
  password: credentials.password,
1870
2035
  MFACode: credentials.MFACode,
1871
2036
  appCode: appCode,
1872
- }, {
1873
- headers: APIHeaders,
1874
- timeout: 605000,
1875
2037
  })];
1876
2038
  case 1:
1877
2039
  response = (_a.sent()).data;
@@ -1932,23 +2094,21 @@ var MFAOptions = function (_a) {
1932
2094
  var context = useCAMSContext();
1933
2095
  var _f = context.authMode === "MSAL" && "sendEmailOTP" in context
1934
2096
  ? context
1935
- : { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
2097
+ : { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter$1(void 0, void 0, void 0, function () { return __generator$1(this, function (_a) {
1936
2098
  return [2 /*return*/];
1937
2099
  }); }); } }, sendEmailOTP = _f.sendEmailOTP, completeMFA = _f.completeMFA, logout = _f.logout;
1938
2100
  var accessToken = context.authMode === "MSAL" ? context.accessToken : "";
1939
2101
  var idToken = context.authMode === "MSAL" ? context.idToken : "";
1940
2102
  var authenticate = useWebAuthn().authenticate;
1941
- var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
2103
+ var handleFIDOLogin = function () { return __awaiter$1(void 0, void 0, void 0, function () {
1942
2104
  var options, assertionResponse, error_1;
1943
- return __generator(this, function (_a) {
2105
+ return __generator$1(this, function (_a) {
1944
2106
  switch (_a.label) {
1945
2107
  case 0:
1946
2108
  _a.trys.push([0, 4, , 5]);
1947
2109
  // 1. Fetch authentication challenge from your server
1948
2110
  console.log("Requesting authentication challenge from server...");
1949
- return [4 /*yield*/, axios.post(MFAEndpoints.RetrieveAuthChallenge, {}, {
1950
- headers: APIHeaders,
1951
- })];
2111
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RetrieveAuthChallenge, {})];
1952
2112
  case 1:
1953
2113
  options = (_a.sent()).data;
1954
2114
  console.log("Received challenge:", options);
@@ -1960,10 +2120,7 @@ var MFAOptions = function (_a) {
1960
2120
  console.log("Authentication assertion received from client:", assertionResponse);
1961
2121
  // 3. Send the assertion back to the server for verification
1962
2122
  console.log("Sending assertion to server for verification...");
1963
- return [4 /*yield*/, axios.post(MFAEndpoints.AuthChallengeVerify, assertionResponse, {
1964
- headers: APIHeaders,
1965
- withCredentials: true, // credentials: 'include'
1966
- })];
2123
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.AuthChallengeVerify, assertionResponse)];
1967
2124
  case 3:
1968
2125
  _a.sent();
1969
2126
  toast.success("🔑 Sign-in successful!");
@@ -2025,12 +2182,12 @@ var MFAOptions = function (_a) {
2025
2182
  }
2026
2183
  var content = jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {});
2027
2184
  if (!authType) {
2028
- content = (jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-600 text-center mb-6", children: "Choose your preferred authentication method:" }), jsxRuntimeExports.jsxs("div", { className: "flex flex-col gap-3", children: [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 () { return __awaiter(void 0, void 0, void 0, function () {
2185
+ content = (jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-600 text-center mb-6", children: "Choose your preferred authentication method:" }), jsxRuntimeExports.jsxs("div", { className: "flex flex-col gap-3", children: [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 () { return __awaiter$1(void 0, void 0, void 0, function () {
2029
2186
  var success;
2030
- return __generator(this, function (_a) {
2187
+ return __generator$1(this, function (_a) {
2031
2188
  switch (_a.label) {
2032
2189
  case 0:
2033
- resetAttempts();
2190
+ // resetAttempts();
2034
2191
  setAuthType("EmailOTP");
2035
2192
  setOtpVisible(true);
2036
2193
  if (!sendEmailOTP) return [3 /*break*/, 2];
@@ -2047,7 +2204,6 @@ var MFAOptions = function (_a) {
2047
2204
  }
2048
2205
  });
2049
2206
  }); }, 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 () {
2050
- resetAttempts();
2051
2207
  setAuthType("AuthenticatorCode");
2052
2208
  setOtpVisible(true);
2053
2209
  }, 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",
@@ -2056,7 +2212,7 @@ var MFAOptions = function (_a) {
2056
2212
  // setAuthType("AuthenticatorCode");
2057
2213
  // setOtpVisible(true);
2058
2214
  // }}
2059
- 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" })] })] }))] })] }));
2215
+ 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" })] })] }))] })] }));
2060
2216
  }
2061
2217
  else if (authType === "EmailOTP") {
2062
2218
  content = (jsxRuntimeExports.jsx(Dialog, { open: otpVisible, onOpenChange: function () {
@@ -2099,16 +2255,16 @@ var ADLoginModal = function (_a) {
2099
2255
  resolver: a$1(credentialsSchema),
2100
2256
  defaultValues: { username: "", password: "" },
2101
2257
  });
2102
- var handleCredentialsSubmit = function (values) { return __awaiter(void 0, void 0, void 0, function () {
2103
- return __generator(this, function (_a) {
2258
+ var handleCredentialsSubmit = function (values) { return __awaiter$1(void 0, void 0, void 0, function () {
2259
+ return __generator$1(this, function (_a) {
2104
2260
  setCredentials(values);
2105
2261
  setStep("mfa");
2106
2262
  return [2 /*return*/];
2107
2263
  });
2108
2264
  }); };
2109
- var handleMFASubmit = function (code) { return __awaiter(void 0, void 0, void 0, function () {
2265
+ var handleMFASubmit = function (code) { return __awaiter$1(void 0, void 0, void 0, function () {
2110
2266
  var error_1;
2111
- return __generator(this, function (_a) {
2267
+ return __generator$1(this, function (_a) {
2112
2268
  switch (_a.label) {
2113
2269
  case 0:
2114
2270
  setIsLoading(true);
@@ -2169,8 +2325,8 @@ var DefaultLoginPage = function (_a) {
2169
2325
  var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
2170
2326
  var _b = useState(false), showADModal = _b[0], setShowADModal = _b[1];
2171
2327
  var register = useWebAuthn().register;
2172
- var _c = useCredentialsHandler(function (state, data) { return __awaiter(void 0, void 0, void 0, function () {
2173
- return __generator(this, function (_a) {
2328
+ var _c = useCredentialsHandler(function (state, data) { return __awaiter$1(void 0, void 0, void 0, function () {
2329
+ return __generator$1(this, function (_a) {
2174
2330
  console.log(data);
2175
2331
  if (state && data) {
2176
2332
  context.isAuthenticated = true;
@@ -2184,6 +2340,10 @@ var DefaultLoginPage = function (_a) {
2184
2340
  });
2185
2341
  }); }), handleSubmitCredentials = _c.handleSubmitCredentials, isCredAuthLoading = _c.loading, setIsCredAuthLoading = _c.setLoading;
2186
2342
  var handleMSALLogin = function () {
2343
+ if (typeof window !== "undefined" && !window.crypto) {
2344
+ toast.error("Crypto API not available. Please use a modern browser.");
2345
+ return;
2346
+ }
2187
2347
  if (authMode === "MSAL") {
2188
2348
  login();
2189
2349
  }
@@ -2192,17 +2352,15 @@ var DefaultLoginPage = function (_a) {
2192
2352
  console.warn("Regular CAMS login requires configuration");
2193
2353
  }
2194
2354
  };
2195
- var handleRegister = function (data) { return __awaiter(void 0, void 0, void 0, function () {
2355
+ var handleRegister = function (data) { return __awaiter$1(void 0, void 0, void 0, function () {
2196
2356
  var options, attestationResponse, error_1;
2197
- return __generator(this, function (_a) {
2357
+ return __generator$1(this, function (_a) {
2198
2358
  switch (_a.label) {
2199
2359
  case 0:
2200
2360
  _a.trys.push([0, 4, , 5]);
2201
2361
  // 1. Fetch challenge from your server
2202
2362
  console.log("Requesting registration challenge from server...");
2203
- return [4 /*yield*/, axios.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data), {
2204
- headers: APIHeaders,
2205
- })];
2363
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data))];
2206
2364
  case 1:
2207
2365
  options = (_a.sent()).data;
2208
2366
  console.log("Received challenge:", options);
@@ -2214,10 +2372,7 @@ var DefaultLoginPage = function (_a) {
2214
2372
  console.log("Passkey created on client:", attestationResponse);
2215
2373
  // 3. Send the response back to the server for verification
2216
2374
  console.log("Sending attestation to server for verification...");
2217
- return [4 /*yield*/, axios.post(MFAEndpoints.RegisterVerify, attestationResponse, {
2218
- headers: APIHeaders,
2219
- withCredentials: true, // credentials: 'include'
2220
- })];
2375
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterVerify + "?username=".concat(data.username), attestationResponse)];
2221
2376
  case 3:
2222
2377
  _a.sent();
2223
2378
  toast.success("✅ Registration successful! Passkey created.");
@@ -2231,15 +2386,15 @@ var DefaultLoginPage = function (_a) {
2231
2386
  }
2232
2387
  });
2233
2388
  }); };
2234
- return (jsxRuntimeExports.jsxs("main", { className: "min-h-screen bg-gray-50", children: [jsxRuntimeExports.jsx(motion.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.5 }, children: jsxRuntimeExports.jsx("div", { className: "flex h-screen items-center justify-center", children: jsxRuntimeExports.jsxs(motion.div, { variants: cardVariants, initial: "hidden", animate: "visible", exit: "exit", className: "w-full max-w-md p-6 space-y-4 bg-gray-50 rounded-2xl shadow-2xl --dark:bg-gray-800", children: [jsxRuntimeExports.jsxs(CardHeader, { className: "text-center space-y-3", children: [jsxRuntimeExports.jsx("div", { className: "w-full flex items-center justify-center", children: jsxRuntimeExports.jsx("img", { src: NIBSSLogo, alt: "NIBSS Logo", width: 265, height: 265 }) }), jsxRuntimeExports.jsx(CardTitle, { className: "text-3xl font-bold --text-gray-900 --dark:text-white", children: "NIBSS CAMS" }), jsxRuntimeExports.jsx(CardTitle, { className: "text-gray-500 dark:text-gray-400 font-bold text-lg", children: "Centralized Authentication" })] }), jsxRuntimeExports.jsxs(CardAction, { className: "w-full flex flex-col items-center justify-center text-center text-gray-500 dark:text-gray-400 mb-6", children: [jsxRuntimeExports.jsx("img", { src: AuthLogo, alt: "Auth Logo", width: 365, height: 365 }), "Kindly use the below identity providers to authenticate"] }), jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsxs(Button
2389
+ return (jsxRuntimeExports.jsxs("main", { className: "min-h-screen bg-gray-50", children: [jsxRuntimeExports.jsx(motion.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.5 }, children: jsxRuntimeExports.jsx("div", { className: "flex h-screen items-center justify-center", children: jsxRuntimeExports.jsxs(motion.div, { variants: cardVariants, initial: "hidden", animate: "visible", exit: "exit", className: "w-full max-w-md p-6 space-y-4 bg-gray-50 rounded-2xl shadow-2xl --dark:bg-gray-800", children: [jsxRuntimeExports.jsxs(CardHeader, { className: "text-center space-y-3", children: [jsxRuntimeExports.jsx("div", { className: "w-full flex items-center justify-center", children: jsxRuntimeExports.jsx("img", { src: NIBSSLogo, alt: "NIBSS Logo", width: 265, height: 265 }) }), jsxRuntimeExports.jsx(CardTitle, { className: "text-3xl font-bold --text-gray-900 --dark:text-white", children: "NIBSS CAMS" }), jsxRuntimeExports.jsx(CardTitle, { className: "text-gray-500 dark:text-gray-400 font-bold text-lg", children: "Centralized Authentication" })] }), jsxRuntimeExports.jsxs(CardAction, { className: "w-full flex flex-col items-center justify-center text-center text-gray-500 dark:text-gray-400 mb-8", children: [jsxRuntimeExports.jsx("img", { src: AuthLogo, alt: "Auth Logo", width: 365, height: 365 }), "Use Below Identity Providers To Authenticate"] }), jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsxs(Button
2235
2390
  // variant="outline"
2236
2391
  , {
2237
2392
  // variant="outline"
2238
2393
  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", onClick: handleMSALLogin, disabled: isLoading, children: [jsxRuntimeExports.jsx("img", { src: MicrosoftLogo, alt: "Microsoft Logo", width: 35, height: 35 }), jsxRuntimeExports.jsx("span", { className: "ml-2", children: isLoading ? "Logging in..." : "Sign in with Microsoft" })] }), useADLogin && (jsxRuntimeExports.jsxs(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", onClick: function () { return setShowADModal(true); }, disabled: isLoading, children: [jsxRuntimeExports.jsx(KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsxRuntimeExports.jsx("span", { children: isLoading
2239
2394
  ? "Logging in..."
2240
- : "Sign in with ActiveDirectory" })] })), usePassKey && (jsxRuntimeExports.jsxs(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", onClick: function () { return handleRegister(PassKeysRegisterProps); }, disabled: isLoading, children: [jsxRuntimeExports.jsx(KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsxRuntimeExports.jsx("span", { children: "Create a Passkey" })] }))] }), jsxRuntimeExports.jsxs(CardFooter, { className: "flex items-center justify-center mt-6 space-x-2 text-gray-400 text-sm", children: [jsxRuntimeExports.jsx(ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsxRuntimeExports.jsx("span", { children: "Powered By NIBSS" })] })] }) }) }, "landing"), jsxRuntimeExports.jsx(ADLoginModal, { open: showADModal, onOpenChange: setShowADModal, isLoading: isCredAuthLoading, setIsLoading: setIsCredAuthLoading, onLogin: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
2395
+ : "Sign in with ActiveDirectory" })] })), usePassKey && (jsxRuntimeExports.jsxs(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", onClick: function () { return handleRegister(PassKeysRegisterProps); }, disabled: isLoading, children: [jsxRuntimeExports.jsx(KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsxRuntimeExports.jsx("span", { children: "Create a Passkey" })] }))] }), jsxRuntimeExports.jsxs(CardFooter, { className: "flex items-center justify-center mt-6 space-x-2 text-gray-400 text-sm", children: [jsxRuntimeExports.jsx(ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsxRuntimeExports.jsx("span", { children: "Powered By NIBSS" })] })] }) }) }, "landing"), jsxRuntimeExports.jsx(ADLoginModal, { open: showADModal, onOpenChange: setShowADModal, isLoading: isCredAuthLoading, setIsLoading: setIsCredAuthLoading, onLogin: function (_a) { return __awaiter$1(void 0, [_a], void 0, function (_b) {
2241
2396
  var username = _b.username, password = _b.password, MFACode = _b.MFACode;
2242
- return __generator(this, function (_c) {
2397
+ return __generator$1(this, function (_c) {
2243
2398
  // Implement your AD login logic here
2244
2399
  console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
2245
2400
  // Example: await adLoginService(username, password, mfaCode);
@@ -2280,8 +2435,8 @@ var MFAGate = function (_a) {
2280
2435
  if (!success)
2281
2436
  Logger.error("MFA authentication failed");
2282
2437
  }, []);
2283
- var handleAuthFailed = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
2284
- return __generator(this, function (_a) {
2438
+ var handleAuthFailed = useCallback(function () { return __awaiter$1(void 0, void 0, void 0, function () {
2439
+ return __generator$1(this, function (_a) {
2285
2440
  switch (_a.label) {
2286
2441
  case 0: return [4 /*yield*/, context.logout()];
2287
2442
  case 1:
@@ -2290,7 +2445,6 @@ var MFAGate = function (_a) {
2290
2445
  }
2291
2446
  });
2292
2447
  }); }, [context.logout]);
2293
- Logger.debug("MFA Endpoint >>>", { MFAEndpoints: MFAEndpoints });
2294
2448
  if (useADLogin && !CredentialsAuthEndpoint)
2295
2449
  return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
2296
2450
  if (!validatedMFAEndpoints)