@nibssplc/cams-sdk-react 1.0.0-rc.4 → 1.0.0-rc.40

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,165 @@ 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
+ (function () {
25
+ var _this = this;
26
+ if (typeof window === "undefined")
27
+ return;
28
+ // Ensure crypto object exists
29
+ if (!window.crypto) {
30
+ window.crypto = {};
31
+ }
32
+ // Polyfill getRandomValues
33
+ if (!window.crypto.getRandomValues) {
34
+ window.crypto.getRandomValues = function (array) {
35
+ var bytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
36
+ for (var i = 0; i < bytes.length; i++) {
37
+ bytes[i] = Math.floor(Math.random() * 256);
38
+ }
39
+ return array;
40
+ };
41
+ }
42
+ var sha256 = function (data) { return __awaiter(_this, void 0, void 0, function () {
43
+ var toUint8, bytes, hash, k, ml, msg, dv, high, low, i, w, j, j, s0, s1, a, b, c, d, e, f, g, h, j, S1, ch, temp1, S0, maj, temp2, result, i;
44
+ return __generator(this, function (_a) {
45
+ toUint8 = function (src) {
46
+ if (src instanceof ArrayBuffer)
47
+ return new Uint8Array(src);
48
+ if (ArrayBuffer.isView(src)) {
49
+ var view = src;
50
+ return new Uint8Array(view.buffer, view.byteOffset || 0, view.byteLength);
51
+ }
52
+ throw new TypeError("Unsupported BufferSource");
53
+ };
54
+ bytes = toUint8(data);
55
+ hash = new Uint32Array(8);
56
+ k = new Uint32Array([
57
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
58
+ 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
59
+ 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
60
+ 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
61
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
62
+ 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
63
+ 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
64
+ 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
65
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
66
+ 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
67
+ 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
68
+ ]);
69
+ hash[0] = 0x6a09e667;
70
+ hash[1] = 0xbb67ae85;
71
+ hash[2] = 0x3c6ef372;
72
+ hash[3] = 0xa54ff53a;
73
+ hash[4] = 0x510e527f;
74
+ hash[5] = 0x9b05688c;
75
+ hash[6] = 0x1f83d9ab;
76
+ hash[7] = 0x5be0cd19;
77
+ ml = bytes.length * 8;
78
+ msg = new Uint8Array(bytes.length + 64 + ((64 - ((bytes.length + 9) % 64)) % 64));
79
+ msg.set(bytes);
80
+ msg[bytes.length] = 0x80;
81
+ dv = new DataView(msg.buffer);
82
+ high = Math.floor(ml / 0x100000000);
83
+ low = ml >>> 0;
84
+ dv.setUint32(msg.length - 8, high, false);
85
+ dv.setUint32(msg.length - 4, low, false);
86
+ for (i = 0; i < msg.length; i += 64) {
87
+ w = new Uint32Array(64);
88
+ for (j = 0; j < 16; j++)
89
+ w[j] = new DataView(msg.buffer).getUint32(i + j * 4, false);
90
+ for (j = 16; j < 64; j++) {
91
+ s0 = ((w[j - 15] >>> 7) | (w[j - 15] << 25)) ^
92
+ ((w[j - 15] >>> 18) | (w[j - 15] << 14)) ^
93
+ (w[j - 15] >>> 3);
94
+ s1 = ((w[j - 2] >>> 17) | (w[j - 2] << 15)) ^
95
+ ((w[j - 2] >>> 19) | (w[j - 2] << 13)) ^
96
+ (w[j - 2] >>> 10);
97
+ w[j] = (w[j - 16] + s0 + w[j - 7] + s1) >>> 0;
98
+ }
99
+ a = hash[0], b = hash[1], c = hash[2], d = hash[3], e = hash[4], f = hash[5], g = hash[6], h = hash[7];
100
+ for (j = 0; j < 64; j++) {
101
+ S1 = ((e >>> 6) | (e << 26)) ^
102
+ ((e >>> 11) | (e << 21)) ^
103
+ ((e >>> 25) | (e << 7));
104
+ ch = (e & f) ^ (~e & g);
105
+ temp1 = (h + S1 + ch + k[j] + w[j]) >>> 0;
106
+ S0 = ((a >>> 2) | (a << 30)) ^
107
+ ((a >>> 13) | (a << 19)) ^
108
+ ((a >>> 22) | (a << 10));
109
+ maj = (a & b) ^ (a & c) ^ (b & c);
110
+ temp2 = (S0 + maj) >>> 0;
111
+ h = g;
112
+ g = f;
113
+ f = e;
114
+ e = (d + temp1) >>> 0;
115
+ d = c;
116
+ c = b;
117
+ b = a;
118
+ a = (temp1 + temp2) >>> 0;
119
+ }
120
+ hash[0] = (hash[0] + a) >>> 0;
121
+ hash[1] = (hash[1] + b) >>> 0;
122
+ hash[2] = (hash[2] + c) >>> 0;
123
+ hash[3] = (hash[3] + d) >>> 0;
124
+ hash[4] = (hash[4] + e) >>> 0;
125
+ hash[5] = (hash[5] + f) >>> 0;
126
+ hash[6] = (hash[6] + g) >>> 0;
127
+ hash[7] = (hash[7] + h) >>> 0;
128
+ }
129
+ result = new Uint8Array(32);
130
+ for (i = 0; i < 8; i++)
131
+ new DataView(result.buffer).setUint32(i * 4, hash[i], false);
132
+ return [2 /*return*/, result.buffer];
133
+ });
134
+ }); };
135
+ // Store reference to original subtle if it exists
136
+ var originalSubtle = window.crypto.subtle;
137
+ // Create the polyfilled subtle object
138
+ var polyfillSubtle = {
139
+ digest: function (algorithm, data) { return __awaiter(_this, void 0, void 0, function () {
140
+ var alg;
141
+ return __generator(this, function (_a) {
142
+ alg = typeof algorithm === "string"
143
+ ? algorithm
144
+ : algorithm.name;
145
+ if (alg === "SHA-256")
146
+ return [2 /*return*/, sha256(data)];
147
+ if (originalSubtle === null || originalSubtle === void 0 ? void 0 : originalSubtle.digest)
148
+ return [2 /*return*/, originalSubtle.digest(algorithm, data)];
149
+ throw new Error("Unsupported algorithm: ".concat(alg));
150
+ });
151
+ }); },
152
+ };
153
+ // Try to define the property, fallback to assignment if needed
154
+ try {
155
+ Object.defineProperty(window.crypto, "subtle", {
156
+ configurable: true,
157
+ enumerable: true,
158
+ writable: true,
159
+ value: polyfillSubtle,
160
+ });
161
+ }
162
+ catch (_a) {
163
+ // Some environments prevent redefining built-ins
164
+ window.crypto.subtle = polyfillSubtle;
165
+ }
166
+ // Polyfill randomUUID
167
+ if (!window.crypto.randomUUID) {
168
+ window.crypto.randomUUID =
169
+ function () {
170
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
171
+ var r = (Math.random() * 16) | 0;
172
+ var v = c === "x" ? r : (r & 0x3) | 0x8;
173
+ return v.toString(16);
174
+ });
175
+ };
176
+ }
177
+ // Log success for debugging
178
+ console.log("Crypto polyfill loaded successfully");
179
+ })();
21
180
 
22
181
  /******************************************************************************
23
182
  Copyright (c) Microsoft Corporation.
@@ -59,7 +218,7 @@ function __rest(s, e) {
59
218
  return t;
60
219
  }
61
220
 
62
- function __awaiter(thisArg, _arguments, P, generator) {
221
+ function __awaiter$1(thisArg, _arguments, P, generator) {
63
222
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
64
223
  return new (P || (P = Promise))(function (resolve, reject) {
65
224
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -69,7 +228,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
69
228
  });
70
229
  }
71
230
 
72
- function __generator(thisArg, body) {
231
+ function __generator$1(thisArg, body) {
73
232
  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
233
  return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
75
234
  function verb(n) { return function (v) { return step([n, v]); }; }
@@ -166,10 +325,10 @@ function useCAMSAuth(options) {
166
325
  }
167
326
  }
168
327
  }, [options.storageKey]);
169
- var login = useCallback(function (config) { return __awaiter(_this, void 0, void 0, function () {
328
+ var login = useCallback(function (config) { return __awaiter$1(_this, void 0, void 0, function () {
170
329
  var loginConfig, userProfile, err_1, e, isPopupClosedError, restoredToken, userProfile;
171
330
  var _a, _b, _c;
172
- return __generator(this, function (_d) {
331
+ return __generator$1(this, function (_d) {
173
332
  switch (_d.label) {
174
333
  case 0:
175
334
  if (!sessionManagerRef.current)
@@ -217,8 +376,8 @@ function useCAMSAuth(options) {
217
376
  }
218
377
  });
219
378
  }); }, [options.idleTimeout]);
220
- var logout = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
221
- return __generator(this, function (_a) {
379
+ var logout = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
380
+ return __generator$1(this, function (_a) {
222
381
  switch (_a.label) {
223
382
  case 0:
224
383
  if (!sessionManagerRef.current)
@@ -248,11 +407,13 @@ function useCAMSAuth(options) {
248
407
  };
249
408
  }
250
409
 
251
- var setCookie$1 = function (name, value, days) {
410
+ var setCookie = function (name, value, days) {
411
+ if (days === void 0) { days = 1; }
252
412
  var expires = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString();
413
+ console.log("Auth Cookie Expires >>>", { name: name, value: value, expires: expires });
253
414
  document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
254
415
  };
255
- var getCookie$1 = function (name) {
416
+ var getCookie = function (name) {
256
417
  var _a;
257
418
  return ((_a = document.cookie
258
419
  .split("; ")
@@ -263,23 +424,24 @@ var getCookie$1 = function (name) {
263
424
  .split("=")[1])
264
425
  : null;
265
426
  };
266
- var deleteCookie$1 = function (name) {
427
+ var deleteCookie = function (name) {
267
428
  document.cookie = name + "=; Max-Age=-99999999; path=/";
268
429
  };
269
430
 
270
431
  function useCAMSMSALAuth(options) {
271
432
  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;
433
+ 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;
434
+ var storageKey = optStorageKey || "CAMS-MSAL-AUTH-SDK";
435
+ var _b = useMsal(), instance = _b.instance, inProgress = _b.inProgress, accounts = _b.accounts;
274
436
  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];
437
+ var _c = useState(null), error = _c[0], setError = _c[1];
438
+ var _d = useState(""), idToken = _d[0], setIdToken = _d[1];
439
+ var _e = useState(""), accessToken = _e[0], setAccessToken = _e[1];
440
+ var _f = useState(null), mfaAuthenticator = _f[0], setMfaAuthenticator = _f[1];
441
+ var _g = useState(false), requiresMFA = _g[0], setRequiresMFA = _g[1];
280
442
  var isLoading = inProgress !== InteractionStatus.None;
281
443
  var isAuthenticated = !!account && !!accessToken && !requiresMFA;
282
- var scopes = options.scopes || ["openid", "profile", "email"];
444
+ var scopes = optScopes || ["openid", "profile", "email"];
283
445
  var isTokenValid = function (token) {
284
446
  try {
285
447
  var payload = JSON.parse(atob(token.split(".")[1]));
@@ -303,15 +465,14 @@ function useCAMSMSALAuth(options) {
303
465
  var mfaConfig = {
304
466
  accessToken: accessToken_1,
305
467
  idToken: idToken_1,
306
- appCode: options.appCode,
468
+ appCode: appCode,
307
469
  provider: "MSAL",
308
- apiEndpoint: options.MFAEndpoint,
470
+ apiEndpoint: MFAEndpoint,
309
471
  };
310
472
  var authenticator = new CAMSMFAAuthenticator(mfaConfig);
311
473
  setMfaAuthenticator(authenticator);
312
474
  setRequiresMFA(true);
313
475
  }
314
- Logger.debug("App Code", { ">>>": options.appCode });
315
476
  }
316
477
  else {
317
478
  localStorage.removeItem(storageKey);
@@ -353,22 +514,26 @@ function useCAMSMSALAuth(options) {
353
514
  // };
354
515
  // handleRedirect();
355
516
  // }, []);
356
- var login = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
517
+ var login = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
357
518
  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) {
519
+ var _a;
520
+ return __generator$1(this, function (_b) {
521
+ switch (_b.label) {
361
522
  case 0:
523
+ if (inProgress !== InteractionStatus.None) {
524
+ Logger.warn("Authentication already in progress, ignoring duplicate call");
525
+ return [2 /*return*/];
526
+ }
362
527
  setError(null);
363
- _e.label = 1;
528
+ _b.label = 1;
364
529
  case 1:
365
- _e.trys.push([1, 3, , 4]);
530
+ _b.trys.push([1, 3, , 4]);
366
531
  return [4 /*yield*/, instance.loginPopup({
367
532
  scopes: scopes,
368
- prompt: options.prompt || "login",
533
+ prompt: prompt || "login",
369
534
  })];
370
535
  case 2:
371
- response = _e.sent();
536
+ response = _b.sent();
372
537
  console.log("Login Token response:", {
373
538
  accessToken: response.accessToken,
374
539
  idToken: response.idToken,
@@ -378,9 +543,9 @@ function useCAMSMSALAuth(options) {
378
543
  mfaConfig = {
379
544
  accessToken: response.accessToken,
380
545
  idToken: response.idToken,
381
- appCode: options.appCode,
546
+ appCode: appCode,
382
547
  provider: "MSAL",
383
- apiEndpoint: options.MFAEndpoint,
548
+ apiEndpoint: MFAEndpoint,
384
549
  };
385
550
  authenticator = new CAMSMFAAuthenticator(mfaConfig);
386
551
  setMfaAuthenticator(authenticator);
@@ -394,10 +559,15 @@ function useCAMSMSALAuth(options) {
394
559
  idToken: response.idToken,
395
560
  }));
396
561
  }
397
- (_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
562
+ onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess(response.accessToken);
398
563
  return [3 /*break*/, 4];
399
564
  case 3:
400
- err_1 = _e.sent();
565
+ err_1 = _b.sent();
566
+ // Handle interaction_in_progress error
567
+ if (err_1.errorCode === "interaction_in_progress") {
568
+ Logger.warn("Interaction already in progress, please wait");
569
+ return [2 /*return*/];
570
+ }
401
571
  // Handle user cancellation gracefully
402
572
  if (err_1.errorCode === "user_cancelled") {
403
573
  Logger.error("User cancelled login");
@@ -406,22 +576,22 @@ function useCAMSMSALAuth(options) {
406
576
  }
407
577
  // If popup is blocked
408
578
  if (err_1.errorCode === "popup_window_error" ||
409
- ((_b = err_1.message) === null || _b === void 0 ? void 0 : _b.includes("popup"))) {
579
+ ((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.includes("popup"))) {
410
580
  camsError_1 = new CAMSError(CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
411
581
  setError(camsError_1);
412
- (_c = options.onAuthError) === null || _c === void 0 ? void 0 : _c.call(options, camsError_1);
582
+ onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError_1);
413
583
  return [2 /*return*/];
414
584
  }
415
585
  camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1.message || err_1);
416
586
  setError(camsError);
417
- (_d = options.onAuthError) === null || _d === void 0 ? void 0 : _d.call(options, camsError);
587
+ onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError);
418
588
  return [3 /*break*/, 4];
419
589
  case 4: return [2 /*return*/];
420
590
  }
421
591
  });
422
- }); }, [instance, scopes, options]);
423
- var completeMFA = useCallback(function (data) { return __awaiter(_this, void 0, void 0, function () {
424
- return __generator(this, function (_a) {
592
+ }); }, [instance, scopes, prompt, appCode, MFAEndpoint, onAuthSuccess, onAuthError, storageKey, inProgress]);
593
+ var completeMFA = useCallback(function (data) { return __awaiter$1(_this, void 0, void 0, function () {
594
+ return __generator$1(this, function (_a) {
425
595
  if (!mfaAuthenticator) {
426
596
  throw new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "MFA Authenticator not initialized");
427
597
  }
@@ -435,7 +605,7 @@ function useCAMSMSALAuth(options) {
435
605
  accessToken: accessToken,
436
606
  idToken: idToken,
437
607
  }));
438
- setCookie$1("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), 1);
608
+ setCookie("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), activeCookiePeriod);
439
609
  setRequiresMFA(false);
440
610
  // Set requiresMFA to false after storage update
441
611
  Logger.debug("MFA completed successfully, storage updated", {
@@ -454,9 +624,9 @@ function useCAMSMSALAuth(options) {
454
624
  }
455
625
  return [2 /*return*/];
456
626
  });
457
- }); }, [mfaAuthenticator, accessToken, idToken, storageKey]);
458
- var sendEmailOTP = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
459
- return __generator(this, function (_a) {
627
+ }); }, [mfaAuthenticator, accessToken, idToken, storageKey, activeCookiePeriod]);
628
+ var sendEmailOTP = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
629
+ return __generator$1(this, function (_a) {
460
630
  switch (_a.label) {
461
631
  case 0:
462
632
  if (!mfaAuthenticator) {
@@ -467,9 +637,9 @@ function useCAMSMSALAuth(options) {
467
637
  }
468
638
  });
469
639
  }); }, [mfaAuthenticator]);
470
- var logout = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
640
+ var logout = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
471
641
  var err_2, camsError;
472
- return __generator(this, function (_a) {
642
+ return __generator$1(this, function (_a) {
473
643
  switch (_a.label) {
474
644
  case 0:
475
645
  _a.trys.push([0, 2, , 3]);
@@ -505,12 +675,13 @@ function useCAMSMSALAuth(options) {
505
675
  error: error,
506
676
  idToken: idToken,
507
677
  accessToken: accessToken,
508
- appCode: options.appCode,
678
+ appCode: appCode,
509
679
  mfaAuthenticator: mfaAuthenticator,
510
680
  requiresMFA: requiresMFA,
511
681
  completeMFA: completeMFA,
512
682
  sendEmailOTP: sendEmailOTP,
513
683
  setRequiresMFA: setRequiresMFA,
684
+ activeCookiePeriod: activeCookiePeriod,
514
685
  };
515
686
  }
516
687
 
@@ -553,10 +724,10 @@ function arrayBufferToBase64url(buffer) {
553
724
  * @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
554
725
  */
555
726
  function register(options) {
556
- return __awaiter(this, void 0, void 0, function () {
727
+ return __awaiter$1(this, void 0, void 0, function () {
557
728
  var createOptions, credential, publicKeyCredential, attestationResponse, transports, err_1;
558
729
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
559
- return __generator(this, function (_k) {
730
+ return __generator$1(this, function (_k) {
560
731
  switch (_k.label) {
561
732
  case 0:
562
733
  _k.trys.push([0, 2, , 3]);
@@ -614,10 +785,10 @@ function register(options) {
614
785
  * @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
615
786
  */
616
787
  function authenticate(options) {
617
- return __awaiter(this, void 0, void 0, function () {
788
+ return __awaiter$1(this, void 0, void 0, function () {
618
789
  var getOptions, credential, publicKeyCredential, assertionResponse;
619
790
  var _a;
620
- return __generator(this, function (_b) {
791
+ return __generator$1(this, function (_b) {
621
792
  switch (_b.label) {
622
793
  case 0:
623
794
  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 +1274,6 @@ function ProtectedRoute(_a) {
1103
1274
  }
1104
1275
 
1105
1276
  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
1277
  var isTokenValid = function (token) {
1125
1278
  try {
1126
1279
  var payload = JSON.parse(atob(token.split(".")[1]));
@@ -1169,7 +1322,7 @@ function CAMSMSALProviderInner(_a) {
1169
1322
  localStorage.setItem(auth.storageKey, JSON.stringify({
1170
1323
  accessToken: auth.accessToken,
1171
1324
  idToken: auth.idToken,
1172
- appCode: auth.appCode
1325
+ appCode: auth.appCode,
1173
1326
  }));
1174
1327
  }
1175
1328
  }, [auth.accessToken, auth.idToken, auth.storageKey]);
@@ -1185,8 +1338,8 @@ function CAMSMSALProviderInner(_a) {
1185
1338
  }
1186
1339
  }, [userProfile, profileStorageKey]);
1187
1340
  // Enhanced logout that also clears profile
1188
- var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
1189
- return __generator(this, function (_a) {
1341
+ var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
1342
+ return __generator$1(this, function (_a) {
1190
1343
  switch (_a.label) {
1191
1344
  case 0: return [4 /*yield*/, auth.logout()];
1192
1345
  case 1:
@@ -1253,7 +1406,7 @@ function CAMSProviderCore(props) {
1253
1406
  if (typeof window === "undefined")
1254
1407
  return null;
1255
1408
  try {
1256
- var storedProfile = getCookie$1(profileStorageKey);
1409
+ var storedProfile = getCookie(profileStorageKey);
1257
1410
  return storedProfile ? JSON.parse(storedProfile) : null;
1258
1411
  }
1259
1412
  catch (_a) {
@@ -1263,7 +1416,7 @@ function CAMSProviderCore(props) {
1263
1416
  var _a = useState(getInitialProfile), userProfile = _a[0], setUserProfile = _a[1];
1264
1417
  useEffect(function () {
1265
1418
  if (typeof window !== "undefined") {
1266
- var storedProfile = getCookie$1(profileStorageKey);
1419
+ var storedProfile = getCookie(profileStorageKey);
1267
1420
  if (storedProfile) {
1268
1421
  try {
1269
1422
  setUserProfile(JSON.parse(storedProfile));
@@ -1275,22 +1428,22 @@ function CAMSProviderCore(props) {
1275
1428
  useEffect(function () {
1276
1429
  if (typeof window !== "undefined") {
1277
1430
  if (userProfile) {
1278
- setCookie$1(profileStorageKey, JSON.stringify(userProfile), 1);
1431
+ setCookie(profileStorageKey, JSON.stringify(userProfile), 1);
1279
1432
  }
1280
1433
  else {
1281
- deleteCookie$1(profileStorageKey);
1434
+ deleteCookie(profileStorageKey);
1282
1435
  }
1283
1436
  }
1284
1437
  }, [userProfile, profileStorageKey]);
1285
- var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
1286
- return __generator(this, function (_a) {
1438
+ var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
1439
+ return __generator$1(this, function (_a) {
1287
1440
  switch (_a.label) {
1288
1441
  case 0: return [4 /*yield*/, auth.logout()];
1289
1442
  case 1:
1290
1443
  _a.sent();
1291
1444
  setUserProfile(null);
1292
1445
  if (typeof window !== "undefined") {
1293
- deleteCookie$1(profileStorageKey);
1446
+ deleteCookie(profileStorageKey);
1294
1447
  }
1295
1448
  return [2 /*return*/];
1296
1449
  }
@@ -1326,7 +1479,8 @@ function CAMSProviderCore(props) {
1326
1479
  userProfile,
1327
1480
  ]);
1328
1481
  var value = useMemo(function () {
1329
- return (__assign(__assign({}, auth), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode }));
1482
+ auth.logout; var authRest = __rest(auth, ["logout"]);
1483
+ return __assign(__assign({}, authRest), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode });
1330
1484
  }, [auth, userProfile, mode]);
1331
1485
  return jsxRuntimeExports.jsx(CAMSContext.Provider, { value: value, children: children });
1332
1486
  }
@@ -1334,7 +1488,7 @@ function UnifiedCAMSProvider(props) {
1334
1488
  // Validate appCode is a valid GUID
1335
1489
  var appCodeValidation = GuidSchema.safeParse(props.appCode);
1336
1490
  if (!appCodeValidation.success) {
1337
- throw new Error("Invalid appCode: ".concat(appCodeValidation.error.issues[0].message));
1491
+ throw new Error("Invalid CAS APP CODE: ".concat(appCodeValidation.error.issues[0].message));
1338
1492
  }
1339
1493
  if (props.mode === "MSAL") {
1340
1494
  var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
@@ -1702,7 +1856,7 @@ styleInject(css_248z);
1702
1856
 
1703
1857
  var LoadingSpinner = function (_a) {
1704
1858
  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..." }))] }));
1859
+ 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
1860
  };
1707
1861
 
1708
1862
  var AuthSuccessAnimation = function (_a) {
@@ -1754,15 +1908,36 @@ var APIHeaders = {
1754
1908
  "X-API-VERSION": "1.0",
1755
1909
  };
1756
1910
 
1911
+ // Creates an Axios instance with a base URL determined by the environment (production or development).
1912
+ var axiosInstance = axios.create({
1913
+ httpsAgent: new https.Agent({ rejectUnauthorized: false }),
1914
+ headers: __assign({ "Content-Type": "application/json" }, APIHeaders),
1915
+ });
1916
+ // Intercepts outgoing requests to add authorization token, version header, and timeout settings.
1917
+ axiosInstance.interceptors.request.use(function (config) {
1918
+ var _a;
1919
+ config.timeout = Number((_a = process.env.NEXT_PUBLIC_API_TIMEOUT) !== null && _a !== void 0 ? _a : 605000);
1920
+ config.timeoutErrorMessage = "Operation Timed Out"; // Custom error message for timeouts.
1921
+ return config; // Returns the modified request configuration.
1922
+ }, function (axiosError) {
1923
+ var _a, _b;
1924
+ // Handles request errors.
1925
+ return {
1926
+ status: (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status, // Extracts HTTP status from the error response.
1927
+ message: axiosError.message, // Extracts the error message.
1928
+ data: (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.data, // Extracts response data from the error.
1929
+ };
1930
+ });
1931
+
1757
1932
  var MAX_ATTEMPTS = 3;
1758
1933
  var useOTPHandler = function (_a) {
1759
1934
  var provider = _a.provider, accessToken = _a.accessToken, idToken = _a.idToken, appCode = _a.appCode, authenticationType = _a.authenticationType, MFAEndpoint = _a.MFAEndpoint, onAuthComplete = _a.onAuthComplete;
1760
1935
  var _b = useState(false), loading = _b[0], setLoading = _b[1];
1761
1936
  var _c = useState(0), attemptCount = _c[0], setAttemptCount = _c[1];
1762
1937
  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 () {
1938
+ var handleSubmitOTP = useMemo(function () { return function (authenticationValue) { return __awaiter$1(void 0, void 0, void 0, function () {
1764
1939
  var currentAttempt, response, error_1, currentAttempt;
1765
- return __generator(this, function (_a) {
1940
+ return __generator$1(this, function (_a) {
1766
1941
  switch (_a.label) {
1767
1942
  case 0:
1768
1943
  if (isMaxAttemptsReached) {
@@ -1779,16 +1954,13 @@ var useOTPHandler = function (_a) {
1779
1954
  setAttemptCount(currentAttempt);
1780
1955
  if (authenticationType === null)
1781
1956
  return [2 /*return*/, false];
1782
- return [4 /*yield*/, axios.post(MFAEndpoint || "/api/auth/verify-mfa", {
1957
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoint || "/api/auth/verify-mfa", {
1783
1958
  provider: provider,
1784
1959
  accessToken: accessToken,
1785
1960
  idToken: idToken,
1786
1961
  authenticationType: authenticationType,
1787
1962
  MFACode: authenticationValue,
1788
1963
  appCode: appCode,
1789
- }, {
1790
- headers: APIHeaders,
1791
- timeout: 605000,
1792
1964
  })];
1793
1965
  case 2:
1794
1966
  response = (_a.sent()).data;
@@ -1855,23 +2027,20 @@ var useCredentialsHandler = function (onAuthComplete) {
1855
2027
  var _b = useState(0), attemptCount = _b[0], setAttemptCount = _b[1];
1856
2028
  var _c = useState(false), isMaxAttemptsReached = _c[0], setIsMaxAttemptsReached = _c[1];
1857
2029
  var handleSubmitCredentials = useMemo(function () {
1858
- return function (CredAuthEndpoint, credentials, appCode) { return __awaiter(void 0, void 0, void 0, function () {
2030
+ return function (CredAuthEndpoint, credentials, appCode) { return __awaiter$1(void 0, void 0, void 0, function () {
1859
2031
  var currentAttempt, response, error_2, currentAttempt;
1860
- return __generator(this, function (_a) {
2032
+ return __generator$1(this, function (_a) {
1861
2033
  switch (_a.label) {
1862
2034
  case 0:
1863
2035
  _a.trys.push([0, 2, 3, 4]);
1864
2036
  setLoading(true);
1865
2037
  currentAttempt = attemptCount + 1;
1866
2038
  setAttemptCount(currentAttempt);
1867
- return [4 /*yield*/, axios.post(CredAuthEndpoint, {
2039
+ return [4 /*yield*/, axiosInstance.post(CredAuthEndpoint, {
1868
2040
  username: credentials.username,
1869
2041
  password: credentials.password,
1870
2042
  MFACode: credentials.MFACode,
1871
2043
  appCode: appCode,
1872
- }, {
1873
- headers: APIHeaders,
1874
- timeout: 605000,
1875
2044
  })];
1876
2045
  case 1:
1877
2046
  response = (_a.sent()).data;
@@ -1932,23 +2101,21 @@ var MFAOptions = function (_a) {
1932
2101
  var context = useCAMSContext();
1933
2102
  var _f = context.authMode === "MSAL" && "sendEmailOTP" in context
1934
2103
  ? context
1935
- : { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
2104
+ : { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter$1(void 0, void 0, void 0, function () { return __generator$1(this, function (_a) {
1936
2105
  return [2 /*return*/];
1937
2106
  }); }); } }, sendEmailOTP = _f.sendEmailOTP, completeMFA = _f.completeMFA, logout = _f.logout;
1938
2107
  var accessToken = context.authMode === "MSAL" ? context.accessToken : "";
1939
2108
  var idToken = context.authMode === "MSAL" ? context.idToken : "";
1940
2109
  var authenticate = useWebAuthn().authenticate;
1941
- var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
2110
+ var handleFIDOLogin = function () { return __awaiter$1(void 0, void 0, void 0, function () {
1942
2111
  var options, assertionResponse, error_1;
1943
- return __generator(this, function (_a) {
2112
+ return __generator$1(this, function (_a) {
1944
2113
  switch (_a.label) {
1945
2114
  case 0:
1946
2115
  _a.trys.push([0, 4, , 5]);
1947
2116
  // 1. Fetch authentication challenge from your server
1948
2117
  console.log("Requesting authentication challenge from server...");
1949
- return [4 /*yield*/, axios.post(MFAEndpoints.RetrieveAuthChallenge, {}, {
1950
- headers: APIHeaders,
1951
- })];
2118
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RetrieveAuthChallenge, {})];
1952
2119
  case 1:
1953
2120
  options = (_a.sent()).data;
1954
2121
  console.log("Received challenge:", options);
@@ -1960,9 +2127,7 @@ var MFAOptions = function (_a) {
1960
2127
  console.log("Authentication assertion received from client:", assertionResponse);
1961
2128
  // 3. Send the assertion back to the server for verification
1962
2129
  console.log("Sending assertion to server for verification...");
1963
- return [4 /*yield*/, axios.post(MFAEndpoints.AuthChallengeVerify, assertionResponse, {
1964
- headers: APIHeaders
1965
- })];
2130
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.AuthChallengeVerify, assertionResponse)];
1966
2131
  case 3:
1967
2132
  _a.sent();
1968
2133
  toast.success("🔑 Sign-in successful!");
@@ -2024,12 +2189,12 @@ var MFAOptions = function (_a) {
2024
2189
  }
2025
2190
  var content = jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {});
2026
2191
  if (!authType) {
2027
- 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 () {
2192
+ 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 () {
2028
2193
  var success;
2029
- return __generator(this, function (_a) {
2194
+ return __generator$1(this, function (_a) {
2030
2195
  switch (_a.label) {
2031
2196
  case 0:
2032
- resetAttempts();
2197
+ // resetAttempts();
2033
2198
  setAuthType("EmailOTP");
2034
2199
  setOtpVisible(true);
2035
2200
  if (!sendEmailOTP) return [3 /*break*/, 2];
@@ -2046,7 +2211,6 @@ var MFAOptions = function (_a) {
2046
2211
  }
2047
2212
  });
2048
2213
  }); }, 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 () {
2049
- resetAttempts();
2050
2214
  setAuthType("AuthenticatorCode");
2051
2215
  setOtpVisible(true);
2052
2216
  }, 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",
@@ -2055,7 +2219,7 @@ var MFAOptions = function (_a) {
2055
2219
  // setAuthType("AuthenticatorCode");
2056
2220
  // setOtpVisible(true);
2057
2221
  // }}
2058
- 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" })] })] }))] })] }));
2222
+ 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" })] })] }))] })] }));
2059
2223
  }
2060
2224
  else if (authType === "EmailOTP") {
2061
2225
  content = (jsxRuntimeExports.jsx(Dialog, { open: otpVisible, onOpenChange: function () {
@@ -2098,16 +2262,16 @@ var ADLoginModal = function (_a) {
2098
2262
  resolver: a$1(credentialsSchema),
2099
2263
  defaultValues: { username: "", password: "" },
2100
2264
  });
2101
- var handleCredentialsSubmit = function (values) { return __awaiter(void 0, void 0, void 0, function () {
2102
- return __generator(this, function (_a) {
2265
+ var handleCredentialsSubmit = function (values) { return __awaiter$1(void 0, void 0, void 0, function () {
2266
+ return __generator$1(this, function (_a) {
2103
2267
  setCredentials(values);
2104
2268
  setStep("mfa");
2105
2269
  return [2 /*return*/];
2106
2270
  });
2107
2271
  }); };
2108
- var handleMFASubmit = function (code) { return __awaiter(void 0, void 0, void 0, function () {
2272
+ var handleMFASubmit = function (code) { return __awaiter$1(void 0, void 0, void 0, function () {
2109
2273
  var error_1;
2110
- return __generator(this, function (_a) {
2274
+ return __generator$1(this, function (_a) {
2111
2275
  switch (_a.label) {
2112
2276
  case 0:
2113
2277
  setIsLoading(true);
@@ -2168,8 +2332,8 @@ var DefaultLoginPage = function (_a) {
2168
2332
  var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
2169
2333
  var _b = useState(false), showADModal = _b[0], setShowADModal = _b[1];
2170
2334
  var register = useWebAuthn().register;
2171
- var _c = useCredentialsHandler(function (state, data) { return __awaiter(void 0, void 0, void 0, function () {
2172
- return __generator(this, function (_a) {
2335
+ var _c = useCredentialsHandler(function (state, data) { return __awaiter$1(void 0, void 0, void 0, function () {
2336
+ return __generator$1(this, function (_a) {
2173
2337
  console.log(data);
2174
2338
  if (state && data) {
2175
2339
  context.isAuthenticated = true;
@@ -2183,6 +2347,10 @@ var DefaultLoginPage = function (_a) {
2183
2347
  });
2184
2348
  }); }), handleSubmitCredentials = _c.handleSubmitCredentials, isCredAuthLoading = _c.loading, setIsCredAuthLoading = _c.setLoading;
2185
2349
  var handleMSALLogin = function () {
2350
+ if (typeof window !== "undefined" && !window.crypto) {
2351
+ toast.error("Crypto API not available. Please use a modern browser.");
2352
+ return;
2353
+ }
2186
2354
  if (authMode === "MSAL") {
2187
2355
  login();
2188
2356
  }
@@ -2191,17 +2359,15 @@ var DefaultLoginPage = function (_a) {
2191
2359
  console.warn("Regular CAMS login requires configuration");
2192
2360
  }
2193
2361
  };
2194
- var handleRegister = function (data) { return __awaiter(void 0, void 0, void 0, function () {
2362
+ var handleRegister = function (data) { return __awaiter$1(void 0, void 0, void 0, function () {
2195
2363
  var options, attestationResponse, error_1;
2196
- return __generator(this, function (_a) {
2364
+ return __generator$1(this, function (_a) {
2197
2365
  switch (_a.label) {
2198
2366
  case 0:
2199
2367
  _a.trys.push([0, 4, , 5]);
2200
2368
  // 1. Fetch challenge from your server
2201
2369
  console.log("Requesting registration challenge from server...");
2202
- return [4 /*yield*/, axios.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data), {
2203
- headers: APIHeaders,
2204
- })];
2370
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data))];
2205
2371
  case 1:
2206
2372
  options = (_a.sent()).data;
2207
2373
  console.log("Received challenge:", options);
@@ -2213,9 +2379,7 @@ var DefaultLoginPage = function (_a) {
2213
2379
  console.log("Passkey created on client:", attestationResponse);
2214
2380
  // 3. Send the response back to the server for verification
2215
2381
  console.log("Sending attestation to server for verification...");
2216
- return [4 /*yield*/, axios.post(MFAEndpoints.RegisterVerify, attestationResponse, {
2217
- headers: APIHeaders
2218
- })];
2382
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterVerify + "?username=".concat(data.username), attestationResponse)];
2219
2383
  case 3:
2220
2384
  _a.sent();
2221
2385
  toast.success("✅ Registration successful! Passkey created.");
@@ -2229,15 +2393,15 @@ var DefaultLoginPage = function (_a) {
2229
2393
  }
2230
2394
  });
2231
2395
  }); };
2232
- 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
2396
+ 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
2233
2397
  // variant="outline"
2234
2398
  , {
2235
2399
  // variant="outline"
2236
2400
  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
2237
2401
  ? "Logging in..."
2238
- : "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) {
2402
+ : "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) {
2239
2403
  var username = _b.username, password = _b.password, MFACode = _b.MFACode;
2240
- return __generator(this, function (_c) {
2404
+ return __generator$1(this, function (_c) {
2241
2405
  // Implement your AD login logic here
2242
2406
  console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
2243
2407
  // Example: await adLoginService(username, password, mfaCode);
@@ -2278,8 +2442,8 @@ var MFAGate = function (_a) {
2278
2442
  if (!success)
2279
2443
  Logger.error("MFA authentication failed");
2280
2444
  }, []);
2281
- var handleAuthFailed = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
2282
- return __generator(this, function (_a) {
2445
+ var handleAuthFailed = useCallback(function () { return __awaiter$1(void 0, void 0, void 0, function () {
2446
+ return __generator$1(this, function (_a) {
2283
2447
  switch (_a.label) {
2284
2448
  case 0: return [4 /*yield*/, context.logout()];
2285
2449
  case 1:
@@ -2288,7 +2452,6 @@ var MFAGate = function (_a) {
2288
2452
  }
2289
2453
  });
2290
2454
  }); }, [context.logout]);
2291
- Logger.debug("MFA Endpoint >>>", { MFAEndpoints: MFAEndpoints });
2292
2455
  if (useADLogin && !CredentialsAuthEndpoint)
2293
2456
  return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
2294
2457
  if (!validatedMFAEndpoints)