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

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.cjs.js CHANGED
@@ -18,6 +18,7 @@ var DialogPrimitive = require('@radix-ui/react-dialog');
18
18
  var sonner = require('sonner');
19
19
  var framerMotion = require('framer-motion');
20
20
  var axios = require('axios');
21
+ var https = require('https');
21
22
 
22
23
  function _interopNamespaceDefault(e) {
23
24
  var n = Object.create(null);
@@ -40,6 +41,162 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
40
41
  var LabelPrimitive__namespace = /*#__PURE__*/_interopNamespaceDefault(LabelPrimitive);
41
42
  var DialogPrimitive__namespace = /*#__PURE__*/_interopNamespaceDefault(DialogPrimitive);
42
43
 
44
+ // Crypto polyfill for MSAL browser compatibility
45
+ if (typeof window !== "undefined") {
46
+ // Run immediately and synchronously
47
+ // Ensure crypto object exists
48
+ if (!window.crypto) {
49
+ window.crypto = {};
50
+ }
51
+ // Polyfill getRandomValues
52
+ if (!window.crypto.getRandomValues) {
53
+ window.crypto.getRandomValues = function (array) {
54
+ var bytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
55
+ for (var i = 0; i < bytes.length; i++) {
56
+ bytes[i] = Math.floor(Math.random() * 256);
57
+ }
58
+ return array;
59
+ };
60
+ }
61
+ var sha256_1 = function (data) { return __awaiter(void 0, void 0, void 0, function () {
62
+ 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;
63
+ return __generator(this, function (_a) {
64
+ toUint8 = function (src) {
65
+ if (src instanceof ArrayBuffer)
66
+ return new Uint8Array(src);
67
+ if (ArrayBuffer.isView(src)) {
68
+ var view = src;
69
+ return new Uint8Array(view.buffer, view.byteOffset || 0, view.byteLength);
70
+ }
71
+ throw new TypeError("Unsupported BufferSource");
72
+ };
73
+ bytes = toUint8(data);
74
+ hash = new Uint32Array(8);
75
+ k = new Uint32Array([
76
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
77
+ 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
78
+ 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
79
+ 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
80
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
81
+ 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
82
+ 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
83
+ 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
84
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
85
+ 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
86
+ 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
87
+ ]);
88
+ hash[0] = 0x6a09e667;
89
+ hash[1] = 0xbb67ae85;
90
+ hash[2] = 0x3c6ef372;
91
+ hash[3] = 0xa54ff53a;
92
+ hash[4] = 0x510e527f;
93
+ hash[5] = 0x9b05688c;
94
+ hash[6] = 0x1f83d9ab;
95
+ hash[7] = 0x5be0cd19;
96
+ ml = bytes.length * 8;
97
+ msg = new Uint8Array(bytes.length + 64 + ((64 - ((bytes.length + 9) % 64)) % 64));
98
+ msg.set(bytes);
99
+ msg[bytes.length] = 0x80;
100
+ dv = new DataView(msg.buffer);
101
+ high = Math.floor(ml / 0x100000000);
102
+ low = ml >>> 0;
103
+ dv.setUint32(msg.length - 8, high, false);
104
+ dv.setUint32(msg.length - 4, low, false);
105
+ for (i = 0; i < msg.length; i += 64) {
106
+ w = new Uint32Array(64);
107
+ for (j = 0; j < 16; j++)
108
+ w[j] = new DataView(msg.buffer).getUint32(i + j * 4, false);
109
+ for (j = 16; j < 64; j++) {
110
+ s0 = ((w[j - 15] >>> 7) | (w[j - 15] << 25)) ^
111
+ ((w[j - 15] >>> 18) | (w[j - 15] << 14)) ^
112
+ (w[j - 15] >>> 3);
113
+ s1 = ((w[j - 2] >>> 17) | (w[j - 2] << 15)) ^
114
+ ((w[j - 2] >>> 19) | (w[j - 2] << 13)) ^
115
+ (w[j - 2] >>> 10);
116
+ w[j] = (w[j - 16] + s0 + w[j - 7] + s1) >>> 0;
117
+ }
118
+ a = hash[0], b = hash[1], c = hash[2], d = hash[3], e = hash[4], f = hash[5], g = hash[6], h = hash[7];
119
+ for (j = 0; j < 64; j++) {
120
+ S1 = ((e >>> 6) | (e << 26)) ^
121
+ ((e >>> 11) | (e << 21)) ^
122
+ ((e >>> 25) | (e << 7));
123
+ ch = (e & f) ^ (~e & g);
124
+ temp1 = (h + S1 + ch + k[j] + w[j]) >>> 0;
125
+ S0 = ((a >>> 2) | (a << 30)) ^
126
+ ((a >>> 13) | (a << 19)) ^
127
+ ((a >>> 22) | (a << 10));
128
+ maj = (a & b) ^ (a & c) ^ (b & c);
129
+ temp2 = (S0 + maj) >>> 0;
130
+ h = g;
131
+ g = f;
132
+ f = e;
133
+ e = (d + temp1) >>> 0;
134
+ d = c;
135
+ c = b;
136
+ b = a;
137
+ a = (temp1 + temp2) >>> 0;
138
+ }
139
+ hash[0] = (hash[0] + a) >>> 0;
140
+ hash[1] = (hash[1] + b) >>> 0;
141
+ hash[2] = (hash[2] + c) >>> 0;
142
+ hash[3] = (hash[3] + d) >>> 0;
143
+ hash[4] = (hash[4] + e) >>> 0;
144
+ hash[5] = (hash[5] + f) >>> 0;
145
+ hash[6] = (hash[6] + g) >>> 0;
146
+ hash[7] = (hash[7] + h) >>> 0;
147
+ }
148
+ result = new Uint8Array(32);
149
+ for (i = 0; i < 8; i++)
150
+ new DataView(result.buffer).setUint32(i * 4, hash[i], false);
151
+ return [2 /*return*/, result.buffer];
152
+ });
153
+ }); };
154
+ // Store reference to original subtle if it exists
155
+ var originalSubtle_1 = window.crypto.subtle;
156
+ // Create the polyfilled subtle object
157
+ var polyfillSubtle = {
158
+ digest: function (algorithm, data) { return __awaiter(void 0, void 0, void 0, function () {
159
+ var alg;
160
+ return __generator(this, function (_a) {
161
+ alg = typeof algorithm === "string"
162
+ ? algorithm
163
+ : algorithm.name;
164
+ if (alg === "SHA-256")
165
+ return [2 /*return*/, sha256_1(data)];
166
+ if (originalSubtle_1 === null || originalSubtle_1 === void 0 ? void 0 : originalSubtle_1.digest)
167
+ return [2 /*return*/, originalSubtle_1.digest(algorithm, data)];
168
+ throw new Error("Unsupported algorithm: ".concat(alg));
169
+ });
170
+ }); },
171
+ };
172
+ // Try to define the property, fallback to assignment if needed
173
+ try {
174
+ Object.defineProperty(window.crypto, "subtle", {
175
+ configurable: true,
176
+ enumerable: true,
177
+ writable: true,
178
+ value: polyfillSubtle,
179
+ });
180
+ }
181
+ catch (_a) {
182
+ // Some environments prevent redefining built-ins
183
+ window.crypto.subtle = polyfillSubtle;
184
+ }
185
+ // Polyfill randomUUID
186
+ if (!window.crypto.randomUUID) {
187
+ window.crypto.randomUUID =
188
+ function () {
189
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
190
+ var r = (Math.random() * 16) | 0;
191
+ var v = c === "x" ? r : (r & 0x3) | 0x8;
192
+ return v.toString(16);
193
+ });
194
+ };
195
+ }
196
+ // Log success for debugging
197
+ console.log("Crypto polyfill loaded successfully");
198
+ }
199
+
43
200
  /******************************************************************************
44
201
  Copyright (c) Microsoft Corporation.
45
202
 
@@ -80,7 +237,7 @@ function __rest(s, e) {
80
237
  return t;
81
238
  }
82
239
 
83
- function __awaiter(thisArg, _arguments, P, generator) {
240
+ function __awaiter$1(thisArg, _arguments, P, generator) {
84
241
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
85
242
  return new (P || (P = Promise))(function (resolve, reject) {
86
243
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -90,7 +247,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
90
247
  });
91
248
  }
92
249
 
93
- function __generator(thisArg, body) {
250
+ function __generator$1(thisArg, body) {
94
251
  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);
95
252
  return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
96
253
  function verb(n) { return function (v) { return step([n, v]); }; }
@@ -187,10 +344,10 @@ function useCAMSAuth(options) {
187
344
  }
188
345
  }
189
346
  }, [options.storageKey]);
190
- var login = React.useCallback(function (config) { return __awaiter(_this, void 0, void 0, function () {
347
+ var login = React.useCallback(function (config) { return __awaiter$1(_this, void 0, void 0, function () {
191
348
  var loginConfig, userProfile, err_1, e, isPopupClosedError, restoredToken, userProfile;
192
349
  var _a, _b, _c;
193
- return __generator(this, function (_d) {
350
+ return __generator$1(this, function (_d) {
194
351
  switch (_d.label) {
195
352
  case 0:
196
353
  if (!sessionManagerRef.current)
@@ -238,8 +395,8 @@ function useCAMSAuth(options) {
238
395
  }
239
396
  });
240
397
  }); }, [options.idleTimeout]);
241
- var logout = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
242
- return __generator(this, function (_a) {
398
+ var logout = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
399
+ return __generator$1(this, function (_a) {
243
400
  switch (_a.label) {
244
401
  case 0:
245
402
  if (!sessionManagerRef.current)
@@ -269,11 +426,13 @@ function useCAMSAuth(options) {
269
426
  };
270
427
  }
271
428
 
272
- var setCookie$1 = function (name, value, days) {
429
+ var setCookie = function (name, value, days) {
430
+ if (days === void 0) { days = 1; }
273
431
  var expires = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString();
432
+ console.log("Auth Cookie Expires >>>", { name: name, value: value, expires: expires });
274
433
  document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
275
434
  };
276
- var getCookie$1 = function (name) {
435
+ var getCookie = function (name) {
277
436
  var _a;
278
437
  return ((_a = document.cookie
279
438
  .split("; ")
@@ -284,23 +443,24 @@ var getCookie$1 = function (name) {
284
443
  .split("=")[1])
285
444
  : null;
286
445
  };
287
- var deleteCookie$1 = function (name) {
446
+ var deleteCookie = function (name) {
288
447
  document.cookie = name + "=; Max-Age=-99999999; path=/";
289
448
  };
290
449
 
291
450
  function useCAMSMSALAuth(options) {
292
451
  var _this = this;
293
- var storageKey = options.storageKey || "CAMS-MSAL-AUTH-SDK";
294
- var _a = msalReact.useMsal(), instance = _a.instance, inProgress = _a.inProgress, accounts = _a.accounts;
452
+ 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;
453
+ var storageKey = optStorageKey || "CAMS-MSAL-AUTH-SDK";
454
+ var _b = msalReact.useMsal(), instance = _b.instance, inProgress = _b.inProgress, accounts = _b.accounts;
295
455
  var account = msalReact.useAccount(accounts[0] || {});
296
- var _b = React.useState(null), error = _b[0], setError = _b[1];
297
- var _c = React.useState(""), idToken = _c[0], setIdToken = _c[1];
298
- var _d = React.useState(""), accessToken = _d[0], setAccessToken = _d[1];
299
- var _e = React.useState(null), mfaAuthenticator = _e[0], setMfaAuthenticator = _e[1];
300
- var _f = React.useState(false), requiresMFA = _f[0], setRequiresMFA = _f[1];
456
+ var _c = React.useState(null), error = _c[0], setError = _c[1];
457
+ var _d = React.useState(""), idToken = _d[0], setIdToken = _d[1];
458
+ var _e = React.useState(""), accessToken = _e[0], setAccessToken = _e[1];
459
+ var _f = React.useState(null), mfaAuthenticator = _f[0], setMfaAuthenticator = _f[1];
460
+ var _g = React.useState(false), requiresMFA = _g[0], setRequiresMFA = _g[1];
301
461
  var isLoading = inProgress !== msalBrowser.InteractionStatus.None;
302
462
  var isAuthenticated = !!account && !!accessToken && !requiresMFA;
303
- var scopes = options.scopes || ["openid", "profile", "email"];
463
+ var scopes = optScopes || ["openid", "profile", "email"];
304
464
  var isTokenValid = function (token) {
305
465
  try {
306
466
  var payload = JSON.parse(atob(token.split(".")[1]));
@@ -324,15 +484,14 @@ function useCAMSMSALAuth(options) {
324
484
  var mfaConfig = {
325
485
  accessToken: accessToken_1,
326
486
  idToken: idToken_1,
327
- appCode: options.appCode,
487
+ appCode: appCode,
328
488
  provider: "MSAL",
329
- apiEndpoint: options.MFAEndpoint,
489
+ apiEndpoint: MFAEndpoint,
330
490
  };
331
491
  var authenticator = new camsSdk.CAMSMFAAuthenticator(mfaConfig);
332
492
  setMfaAuthenticator(authenticator);
333
493
  setRequiresMFA(true);
334
494
  }
335
- camsSdk.Logger.debug("App Code", { ">>>": options.appCode });
336
495
  }
337
496
  else {
338
497
  localStorage.removeItem(storageKey);
@@ -374,22 +533,26 @@ function useCAMSMSALAuth(options) {
374
533
  // };
375
534
  // handleRedirect();
376
535
  // }, []);
377
- var login = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
536
+ var login = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
378
537
  var response, mfaConfig, authenticator, err_1, camsError_1, camsError;
379
- var _a, _b, _c, _d;
380
- return __generator(this, function (_e) {
381
- switch (_e.label) {
538
+ var _a;
539
+ return __generator$1(this, function (_b) {
540
+ switch (_b.label) {
382
541
  case 0:
542
+ if (inProgress !== msalBrowser.InteractionStatus.None) {
543
+ camsSdk.Logger.warn("Authentication already in progress, ignoring duplicate call");
544
+ return [2 /*return*/];
545
+ }
383
546
  setError(null);
384
- _e.label = 1;
547
+ _b.label = 1;
385
548
  case 1:
386
- _e.trys.push([1, 3, , 4]);
549
+ _b.trys.push([1, 3, , 4]);
387
550
  return [4 /*yield*/, instance.loginPopup({
388
551
  scopes: scopes,
389
- prompt: options.prompt || "login",
552
+ prompt: prompt || "login",
390
553
  })];
391
554
  case 2:
392
- response = _e.sent();
555
+ response = _b.sent();
393
556
  console.log("Login Token response:", {
394
557
  accessToken: response.accessToken,
395
558
  idToken: response.idToken,
@@ -399,9 +562,9 @@ function useCAMSMSALAuth(options) {
399
562
  mfaConfig = {
400
563
  accessToken: response.accessToken,
401
564
  idToken: response.idToken,
402
- appCode: options.appCode,
565
+ appCode: appCode,
403
566
  provider: "MSAL",
404
- apiEndpoint: options.MFAEndpoint,
567
+ apiEndpoint: MFAEndpoint,
405
568
  };
406
569
  authenticator = new camsSdk.CAMSMFAAuthenticator(mfaConfig);
407
570
  setMfaAuthenticator(authenticator);
@@ -415,10 +578,15 @@ function useCAMSMSALAuth(options) {
415
578
  idToken: response.idToken,
416
579
  }));
417
580
  }
418
- (_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
581
+ onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess(response.accessToken);
419
582
  return [3 /*break*/, 4];
420
583
  case 3:
421
- err_1 = _e.sent();
584
+ err_1 = _b.sent();
585
+ // Handle interaction_in_progress error
586
+ if (err_1.errorCode === "interaction_in_progress") {
587
+ camsSdk.Logger.warn("Interaction already in progress, please wait");
588
+ return [2 /*return*/];
589
+ }
422
590
  // Handle user cancellation gracefully
423
591
  if (err_1.errorCode === "user_cancelled") {
424
592
  camsSdk.Logger.error("User cancelled login");
@@ -427,22 +595,22 @@ function useCAMSMSALAuth(options) {
427
595
  }
428
596
  // If popup is blocked
429
597
  if (err_1.errorCode === "popup_window_error" ||
430
- ((_b = err_1.message) === null || _b === void 0 ? void 0 : _b.includes("popup"))) {
598
+ ((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.includes("popup"))) {
431
599
  camsError_1 = new camsSdk.CAMSError(camsSdk.CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
432
600
  setError(camsError_1);
433
- (_c = options.onAuthError) === null || _c === void 0 ? void 0 : _c.call(options, camsError_1);
601
+ onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError_1);
434
602
  return [2 /*return*/];
435
603
  }
436
604
  camsError = new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1.message || err_1);
437
605
  setError(camsError);
438
- (_d = options.onAuthError) === null || _d === void 0 ? void 0 : _d.call(options, camsError);
606
+ onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError);
439
607
  return [3 /*break*/, 4];
440
608
  case 4: return [2 /*return*/];
441
609
  }
442
610
  });
443
- }); }, [instance, scopes, options]);
444
- var completeMFA = React.useCallback(function (data) { return __awaiter(_this, void 0, void 0, function () {
445
- return __generator(this, function (_a) {
611
+ }); }, [instance, scopes, prompt, appCode, MFAEndpoint, onAuthSuccess, onAuthError, storageKey, inProgress]);
612
+ var completeMFA = React.useCallback(function (data) { return __awaiter$1(_this, void 0, void 0, function () {
613
+ return __generator$1(this, function (_a) {
446
614
  if (!mfaAuthenticator) {
447
615
  throw new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "MFA Authenticator not initialized");
448
616
  }
@@ -456,7 +624,7 @@ function useCAMSMSALAuth(options) {
456
624
  accessToken: accessToken,
457
625
  idToken: idToken,
458
626
  }));
459
- setCookie$1("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), 1);
627
+ setCookie("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), activeCookiePeriod);
460
628
  setRequiresMFA(false);
461
629
  // Set requiresMFA to false after storage update
462
630
  camsSdk.Logger.debug("MFA completed successfully, storage updated", {
@@ -475,9 +643,9 @@ function useCAMSMSALAuth(options) {
475
643
  }
476
644
  return [2 /*return*/];
477
645
  });
478
- }); }, [mfaAuthenticator, accessToken, idToken, storageKey]);
479
- var sendEmailOTP = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
480
- return __generator(this, function (_a) {
646
+ }); }, [mfaAuthenticator, accessToken, idToken, storageKey, activeCookiePeriod]);
647
+ var sendEmailOTP = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
648
+ return __generator$1(this, function (_a) {
481
649
  switch (_a.label) {
482
650
  case 0:
483
651
  if (!mfaAuthenticator) {
@@ -488,9 +656,9 @@ function useCAMSMSALAuth(options) {
488
656
  }
489
657
  });
490
658
  }); }, [mfaAuthenticator]);
491
- var logout = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
659
+ var logout = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
492
660
  var err_2, camsError;
493
- return __generator(this, function (_a) {
661
+ return __generator$1(this, function (_a) {
494
662
  switch (_a.label) {
495
663
  case 0:
496
664
  _a.trys.push([0, 2, , 3]);
@@ -526,12 +694,13 @@ function useCAMSMSALAuth(options) {
526
694
  error: error,
527
695
  idToken: idToken,
528
696
  accessToken: accessToken,
529
- appCode: options.appCode,
697
+ appCode: appCode,
530
698
  mfaAuthenticator: mfaAuthenticator,
531
699
  requiresMFA: requiresMFA,
532
700
  completeMFA: completeMFA,
533
701
  sendEmailOTP: sendEmailOTP,
534
702
  setRequiresMFA: setRequiresMFA,
703
+ activeCookiePeriod: activeCookiePeriod,
535
704
  };
536
705
  }
537
706
 
@@ -574,10 +743,10 @@ function arrayBufferToBase64url(buffer) {
574
743
  * @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
575
744
  */
576
745
  function register(options) {
577
- return __awaiter(this, void 0, void 0, function () {
746
+ return __awaiter$1(this, void 0, void 0, function () {
578
747
  var createOptions, credential, publicKeyCredential, attestationResponse, transports, err_1;
579
748
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
580
- return __generator(this, function (_k) {
749
+ return __generator$1(this, function (_k) {
581
750
  switch (_k.label) {
582
751
  case 0:
583
752
  _k.trys.push([0, 2, , 3]);
@@ -635,10 +804,10 @@ function register(options) {
635
804
  * @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
636
805
  */
637
806
  function authenticate(options) {
638
- return __awaiter(this, void 0, void 0, function () {
807
+ return __awaiter$1(this, void 0, void 0, function () {
639
808
  var getOptions, credential, publicKeyCredential, assertionResponse;
640
809
  var _a;
641
- return __generator(this, function (_b) {
810
+ return __generator$1(this, function (_b) {
642
811
  switch (_b.label) {
643
812
  case 0:
644
813
  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) })); }) });
@@ -1124,24 +1293,6 @@ function ProtectedRoute(_a) {
1124
1293
  }
1125
1294
 
1126
1295
  var CAMSMSALContext = React.createContext(null);
1127
- var setCookie = function (name, value, days) {
1128
- var expires = new Date(Date.now() + days * 864e5).toUTCString();
1129
- document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
1130
- };
1131
- var getCookie = function (name) {
1132
- var _a;
1133
- return ((_a = document.cookie
1134
- .split("; ")
1135
- .find(function (row) { return row.startsWith(name + "="); })) === null || _a === void 0 ? void 0 : _a.split("=")[1])
1136
- ? decodeURIComponent(document.cookie
1137
- .split("; ")
1138
- .find(function (row) { return row.startsWith(name + "="); })
1139
- .split("=")[1])
1140
- : null;
1141
- };
1142
- var deleteCookie = function (name) {
1143
- document.cookie = name + "=; Max-Age=-99999999; path=/";
1144
- };
1145
1296
  var isTokenValid = function (token) {
1146
1297
  try {
1147
1298
  var payload = JSON.parse(atob(token.split(".")[1]));
@@ -1190,7 +1341,7 @@ function CAMSMSALProviderInner(_a) {
1190
1341
  localStorage.setItem(auth.storageKey, JSON.stringify({
1191
1342
  accessToken: auth.accessToken,
1192
1343
  idToken: auth.idToken,
1193
- appCode: auth.appCode
1344
+ appCode: auth.appCode,
1194
1345
  }));
1195
1346
  }
1196
1347
  }, [auth.accessToken, auth.idToken, auth.storageKey]);
@@ -1206,8 +1357,8 @@ function CAMSMSALProviderInner(_a) {
1206
1357
  }
1207
1358
  }, [userProfile, profileStorageKey]);
1208
1359
  // Enhanced logout that also clears profile
1209
- var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
1210
- return __generator(this, function (_a) {
1360
+ var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
1361
+ return __generator$1(this, function (_a) {
1211
1362
  switch (_a.label) {
1212
1363
  case 0: return [4 /*yield*/, auth.logout()];
1213
1364
  case 1:
@@ -1224,7 +1375,12 @@ function CAMSMSALProviderInner(_a) {
1224
1375
  return (jsxRuntimeExports.jsx(CAMSMSALContext.Provider, { value: value, children: children }));
1225
1376
  }
1226
1377
  function CAMSMSALProvider(props) {
1378
+ var _a;
1227
1379
  var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
1380
+ // Ensure crypto is available before creating MSAL instance
1381
+ if (typeof window !== "undefined" && !((_a = window.crypto) === null || _a === void 0 ? void 0 : _a.subtle)) {
1382
+ throw new Error("Crypto API not available. Polyfill failed to load.");
1383
+ }
1228
1384
  var instance = msalInstance || new msalBrowser.PublicClientApplication(msalConfig);
1229
1385
  return (jsxRuntimeExports.jsx(msalReact.MsalProvider, { instance: instance, children: jsxRuntimeExports.jsx(CAMSMSALProviderInner, __assign({}, props)) }));
1230
1386
  }
@@ -1274,7 +1430,7 @@ function CAMSProviderCore(props) {
1274
1430
  if (typeof window === "undefined")
1275
1431
  return null;
1276
1432
  try {
1277
- var storedProfile = getCookie$1(profileStorageKey);
1433
+ var storedProfile = getCookie(profileStorageKey);
1278
1434
  return storedProfile ? JSON.parse(storedProfile) : null;
1279
1435
  }
1280
1436
  catch (_a) {
@@ -1284,7 +1440,7 @@ function CAMSProviderCore(props) {
1284
1440
  var _a = React.useState(getInitialProfile), userProfile = _a[0], setUserProfile = _a[1];
1285
1441
  React.useEffect(function () {
1286
1442
  if (typeof window !== "undefined") {
1287
- var storedProfile = getCookie$1(profileStorageKey);
1443
+ var storedProfile = getCookie(profileStorageKey);
1288
1444
  if (storedProfile) {
1289
1445
  try {
1290
1446
  setUserProfile(JSON.parse(storedProfile));
@@ -1296,22 +1452,22 @@ function CAMSProviderCore(props) {
1296
1452
  React.useEffect(function () {
1297
1453
  if (typeof window !== "undefined") {
1298
1454
  if (userProfile) {
1299
- setCookie$1(profileStorageKey, JSON.stringify(userProfile), 1);
1455
+ setCookie(profileStorageKey, JSON.stringify(userProfile), 1);
1300
1456
  }
1301
1457
  else {
1302
- deleteCookie$1(profileStorageKey);
1458
+ deleteCookie(profileStorageKey);
1303
1459
  }
1304
1460
  }
1305
1461
  }, [userProfile, profileStorageKey]);
1306
- var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
1307
- return __generator(this, function (_a) {
1462
+ var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
1463
+ return __generator$1(this, function (_a) {
1308
1464
  switch (_a.label) {
1309
1465
  case 0: return [4 /*yield*/, auth.logout()];
1310
1466
  case 1:
1311
1467
  _a.sent();
1312
1468
  setUserProfile(null);
1313
1469
  if (typeof window !== "undefined") {
1314
- deleteCookie$1(profileStorageKey);
1470
+ deleteCookie(profileStorageKey);
1315
1471
  }
1316
1472
  return [2 /*return*/];
1317
1473
  }
@@ -1347,7 +1503,8 @@ function CAMSProviderCore(props) {
1347
1503
  userProfile,
1348
1504
  ]);
1349
1505
  var value = React.useMemo(function () {
1350
- return (__assign(__assign({}, auth), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode }));
1506
+ auth.logout; var authRest = __rest(auth, ["logout"]);
1507
+ return __assign(__assign({}, authRest), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode });
1351
1508
  }, [auth, userProfile, mode]);
1352
1509
  return jsxRuntimeExports.jsx(CAMSContext.Provider, { value: value, children: children });
1353
1510
  }
@@ -1355,7 +1512,7 @@ function UnifiedCAMSProvider(props) {
1355
1512
  // Validate appCode is a valid GUID
1356
1513
  var appCodeValidation = GuidSchema.safeParse(props.appCode);
1357
1514
  if (!appCodeValidation.success) {
1358
- throw new Error("Invalid appCode: ".concat(appCodeValidation.error.issues[0].message));
1515
+ throw new Error("Invalid CAS APP CODE: ".concat(appCodeValidation.error.issues[0].message));
1359
1516
  }
1360
1517
  if (props.mode === "MSAL") {
1361
1518
  var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
@@ -1723,7 +1880,7 @@ styleInject(css_248z);
1723
1880
 
1724
1881
  var LoadingSpinner = function (_a) {
1725
1882
  var loadingText = _a.loadingText;
1726
- 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..." }))] }));
1883
+ 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..." }))] }));
1727
1884
  };
1728
1885
 
1729
1886
  var AuthSuccessAnimation = function (_a) {
@@ -1775,15 +1932,36 @@ var APIHeaders = {
1775
1932
  "X-API-VERSION": "1.0",
1776
1933
  };
1777
1934
 
1935
+ // Creates an Axios instance with a base URL determined by the environment (production or development).
1936
+ var axiosInstance = axios.create({
1937
+ httpsAgent: new https.Agent({ rejectUnauthorized: false }),
1938
+ headers: __assign({ "Content-Type": "application/json" }, APIHeaders),
1939
+ });
1940
+ // Intercepts outgoing requests to add authorization token, version header, and timeout settings.
1941
+ axiosInstance.interceptors.request.use(function (config) {
1942
+ var _a;
1943
+ config.timeout = Number((_a = process.env.NEXT_PUBLIC_API_TIMEOUT) !== null && _a !== void 0 ? _a : 605000);
1944
+ config.timeoutErrorMessage = "Operation Timed Out"; // Custom error message for timeouts.
1945
+ return config; // Returns the modified request configuration.
1946
+ }, function (axiosError) {
1947
+ var _a, _b;
1948
+ // Handles request errors.
1949
+ return {
1950
+ status: (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status, // Extracts HTTP status from the error response.
1951
+ message: axiosError.message, // Extracts the error message.
1952
+ data: (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.data, // Extracts response data from the error.
1953
+ };
1954
+ });
1955
+
1778
1956
  var MAX_ATTEMPTS = 3;
1779
1957
  var useOTPHandler = function (_a) {
1780
1958
  var provider = _a.provider, accessToken = _a.accessToken, idToken = _a.idToken, appCode = _a.appCode, authenticationType = _a.authenticationType, MFAEndpoint = _a.MFAEndpoint, onAuthComplete = _a.onAuthComplete;
1781
1959
  var _b = React.useState(false), loading = _b[0], setLoading = _b[1];
1782
1960
  var _c = React.useState(0), attemptCount = _c[0], setAttemptCount = _c[1];
1783
1961
  var _d = React.useState(false), isMaxAttemptsReached = _d[0], setIsMaxAttemptsReached = _d[1];
1784
- var handleSubmitOTP = React.useMemo(function () { return function (authenticationValue) { return __awaiter(void 0, void 0, void 0, function () {
1962
+ var handleSubmitOTP = React.useMemo(function () { return function (authenticationValue) { return __awaiter$1(void 0, void 0, void 0, function () {
1785
1963
  var currentAttempt, response, error_1, currentAttempt;
1786
- return __generator(this, function (_a) {
1964
+ return __generator$1(this, function (_a) {
1787
1965
  switch (_a.label) {
1788
1966
  case 0:
1789
1967
  if (isMaxAttemptsReached) {
@@ -1800,16 +1978,13 @@ var useOTPHandler = function (_a) {
1800
1978
  setAttemptCount(currentAttempt);
1801
1979
  if (authenticationType === null)
1802
1980
  return [2 /*return*/, false];
1803
- return [4 /*yield*/, axios.post(MFAEndpoint || "/api/auth/verify-mfa", {
1981
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoint || "/api/auth/verify-mfa", {
1804
1982
  provider: provider,
1805
1983
  accessToken: accessToken,
1806
1984
  idToken: idToken,
1807
1985
  authenticationType: authenticationType,
1808
1986
  MFACode: authenticationValue,
1809
1987
  appCode: appCode,
1810
- }, {
1811
- headers: APIHeaders,
1812
- timeout: 605000,
1813
1988
  })];
1814
1989
  case 2:
1815
1990
  response = (_a.sent()).data;
@@ -1876,23 +2051,20 @@ var useCredentialsHandler = function (onAuthComplete) {
1876
2051
  var _b = React.useState(0), attemptCount = _b[0], setAttemptCount = _b[1];
1877
2052
  var _c = React.useState(false), isMaxAttemptsReached = _c[0], setIsMaxAttemptsReached = _c[1];
1878
2053
  var handleSubmitCredentials = React.useMemo(function () {
1879
- return function (CredAuthEndpoint, credentials, appCode) { return __awaiter(void 0, void 0, void 0, function () {
2054
+ return function (CredAuthEndpoint, credentials, appCode) { return __awaiter$1(void 0, void 0, void 0, function () {
1880
2055
  var currentAttempt, response, error_2, currentAttempt;
1881
- return __generator(this, function (_a) {
2056
+ return __generator$1(this, function (_a) {
1882
2057
  switch (_a.label) {
1883
2058
  case 0:
1884
2059
  _a.trys.push([0, 2, 3, 4]);
1885
2060
  setLoading(true);
1886
2061
  currentAttempt = attemptCount + 1;
1887
2062
  setAttemptCount(currentAttempt);
1888
- return [4 /*yield*/, axios.post(CredAuthEndpoint, {
2063
+ return [4 /*yield*/, axiosInstance.post(CredAuthEndpoint, {
1889
2064
  username: credentials.username,
1890
2065
  password: credentials.password,
1891
2066
  MFACode: credentials.MFACode,
1892
2067
  appCode: appCode,
1893
- }, {
1894
- headers: APIHeaders,
1895
- timeout: 605000,
1896
2068
  })];
1897
2069
  case 1:
1898
2070
  response = (_a.sent()).data;
@@ -1953,23 +2125,21 @@ var MFAOptions = function (_a) {
1953
2125
  var context = useCAMSContext();
1954
2126
  var _f = context.authMode === "MSAL" && "sendEmailOTP" in context
1955
2127
  ? context
1956
- : { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
2128
+ : { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter$1(void 0, void 0, void 0, function () { return __generator$1(this, function (_a) {
1957
2129
  return [2 /*return*/];
1958
2130
  }); }); } }, sendEmailOTP = _f.sendEmailOTP, completeMFA = _f.completeMFA, logout = _f.logout;
1959
2131
  var accessToken = context.authMode === "MSAL" ? context.accessToken : "";
1960
2132
  var idToken = context.authMode === "MSAL" ? context.idToken : "";
1961
2133
  var authenticate = useWebAuthn().authenticate;
1962
- var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
2134
+ var handleFIDOLogin = function () { return __awaiter$1(void 0, void 0, void 0, function () {
1963
2135
  var options, assertionResponse, error_1;
1964
- return __generator(this, function (_a) {
2136
+ return __generator$1(this, function (_a) {
1965
2137
  switch (_a.label) {
1966
2138
  case 0:
1967
2139
  _a.trys.push([0, 4, , 5]);
1968
2140
  // 1. Fetch authentication challenge from your server
1969
2141
  console.log("Requesting authentication challenge from server...");
1970
- return [4 /*yield*/, axios.post(MFAEndpoints.RetrieveAuthChallenge, {}, {
1971
- headers: APIHeaders,
1972
- })];
2142
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RetrieveAuthChallenge, {})];
1973
2143
  case 1:
1974
2144
  options = (_a.sent()).data;
1975
2145
  console.log("Received challenge:", options);
@@ -1981,9 +2151,7 @@ var MFAOptions = function (_a) {
1981
2151
  console.log("Authentication assertion received from client:", assertionResponse);
1982
2152
  // 3. Send the assertion back to the server for verification
1983
2153
  console.log("Sending assertion to server for verification...");
1984
- return [4 /*yield*/, axios.post(MFAEndpoints.AuthChallengeVerify, assertionResponse, {
1985
- headers: APIHeaders
1986
- })];
2154
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.AuthChallengeVerify, assertionResponse)];
1987
2155
  case 3:
1988
2156
  _a.sent();
1989
2157
  sonner.toast.success("🔑 Sign-in successful!");
@@ -2045,12 +2213,12 @@ var MFAOptions = function (_a) {
2045
2213
  }
2046
2214
  var content = jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {});
2047
2215
  if (!authType) {
2048
- 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 () {
2216
+ 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 () {
2049
2217
  var success;
2050
- return __generator(this, function (_a) {
2218
+ return __generator$1(this, function (_a) {
2051
2219
  switch (_a.label) {
2052
2220
  case 0:
2053
- resetAttempts();
2221
+ // resetAttempts();
2054
2222
  setAuthType("EmailOTP");
2055
2223
  setOtpVisible(true);
2056
2224
  if (!sendEmailOTP) return [3 /*break*/, 2];
@@ -2067,7 +2235,6 @@ var MFAOptions = function (_a) {
2067
2235
  }
2068
2236
  });
2069
2237
  }); }, children: [jsxRuntimeExports.jsx(lucideReact.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 () {
2070
- resetAttempts();
2071
2238
  setAuthType("AuthenticatorCode");
2072
2239
  setOtpVisible(true);
2073
2240
  }, children: [jsxRuntimeExports.jsx("img", { src: MicrosoftAuthenticatorImg, alt: "Authenticator", className: "rounded-full", width: 24, height: 24, onError: function () { return jsxRuntimeExports.jsx(lucideReact.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",
@@ -2076,7 +2243,7 @@ var MFAOptions = function (_a) {
2076
2243
  // setAuthType("AuthenticatorCode");
2077
2244
  // setOtpVisible(true);
2078
2245
  // }}
2079
- 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(lucideReact.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" })] })] }))] })] }));
2246
+ onClick: handleFIDOLogin, disabled: context.isLoading, children: [jsxRuntimeExports.jsx(lucideReact.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" })] })] }))] })] }));
2080
2247
  }
2081
2248
  else if (authType === "EmailOTP") {
2082
2249
  content = (jsxRuntimeExports.jsx(Dialog, { open: otpVisible, onOpenChange: function () {
@@ -2119,16 +2286,16 @@ var ADLoginModal = function (_a) {
2119
2286
  resolver: a$1(credentialsSchema),
2120
2287
  defaultValues: { username: "", password: "" },
2121
2288
  });
2122
- var handleCredentialsSubmit = function (values) { return __awaiter(void 0, void 0, void 0, function () {
2123
- return __generator(this, function (_a) {
2289
+ var handleCredentialsSubmit = function (values) { return __awaiter$1(void 0, void 0, void 0, function () {
2290
+ return __generator$1(this, function (_a) {
2124
2291
  setCredentials(values);
2125
2292
  setStep("mfa");
2126
2293
  return [2 /*return*/];
2127
2294
  });
2128
2295
  }); };
2129
- var handleMFASubmit = function (code) { return __awaiter(void 0, void 0, void 0, function () {
2296
+ var handleMFASubmit = function (code) { return __awaiter$1(void 0, void 0, void 0, function () {
2130
2297
  var error_1;
2131
- return __generator(this, function (_a) {
2298
+ return __generator$1(this, function (_a) {
2132
2299
  switch (_a.label) {
2133
2300
  case 0:
2134
2301
  setIsLoading(true);
@@ -2189,8 +2356,8 @@ var DefaultLoginPage = function (_a) {
2189
2356
  var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
2190
2357
  var _b = React.useState(false), showADModal = _b[0], setShowADModal = _b[1];
2191
2358
  var register = useWebAuthn().register;
2192
- var _c = useCredentialsHandler(function (state, data) { return __awaiter(void 0, void 0, void 0, function () {
2193
- return __generator(this, function (_a) {
2359
+ var _c = useCredentialsHandler(function (state, data) { return __awaiter$1(void 0, void 0, void 0, function () {
2360
+ return __generator$1(this, function (_a) {
2194
2361
  console.log(data);
2195
2362
  if (state && data) {
2196
2363
  context.isAuthenticated = true;
@@ -2204,6 +2371,10 @@ var DefaultLoginPage = function (_a) {
2204
2371
  });
2205
2372
  }); }), handleSubmitCredentials = _c.handleSubmitCredentials, isCredAuthLoading = _c.loading, setIsCredAuthLoading = _c.setLoading;
2206
2373
  var handleMSALLogin = function () {
2374
+ if (typeof window !== "undefined" && !window.crypto) {
2375
+ sonner.toast.error("Crypto API not available. Please use a modern browser.");
2376
+ return;
2377
+ }
2207
2378
  if (authMode === "MSAL") {
2208
2379
  login();
2209
2380
  }
@@ -2212,17 +2383,15 @@ var DefaultLoginPage = function (_a) {
2212
2383
  console.warn("Regular CAMS login requires configuration");
2213
2384
  }
2214
2385
  };
2215
- var handleRegister = function (data) { return __awaiter(void 0, void 0, void 0, function () {
2386
+ var handleRegister = function (data) { return __awaiter$1(void 0, void 0, void 0, function () {
2216
2387
  var options, attestationResponse, error_1;
2217
- return __generator(this, function (_a) {
2388
+ return __generator$1(this, function (_a) {
2218
2389
  switch (_a.label) {
2219
2390
  case 0:
2220
2391
  _a.trys.push([0, 4, , 5]);
2221
2392
  // 1. Fetch challenge from your server
2222
2393
  console.log("Requesting registration challenge from server...");
2223
- return [4 /*yield*/, axios.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data), {
2224
- headers: APIHeaders,
2225
- })];
2394
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data))];
2226
2395
  case 1:
2227
2396
  options = (_a.sent()).data;
2228
2397
  console.log("Received challenge:", options);
@@ -2234,9 +2403,7 @@ var DefaultLoginPage = function (_a) {
2234
2403
  console.log("Passkey created on client:", attestationResponse);
2235
2404
  // 3. Send the response back to the server for verification
2236
2405
  console.log("Sending attestation to server for verification...");
2237
- return [4 /*yield*/, axios.post(MFAEndpoints.RegisterVerify, attestationResponse, {
2238
- headers: APIHeaders
2239
- })];
2406
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterVerify + "?username=".concat(data.username), attestationResponse)];
2240
2407
  case 3:
2241
2408
  _a.sent();
2242
2409
  sonner.toast.success("✅ Registration successful! Passkey created.");
@@ -2250,15 +2417,15 @@ var DefaultLoginPage = function (_a) {
2250
2417
  }
2251
2418
  });
2252
2419
  }); };
2253
- return (jsxRuntimeExports.jsxs("main", { className: "min-h-screen bg-gray-50", children: [jsxRuntimeExports.jsx(framerMotion.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(framerMotion.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
2420
+ return (jsxRuntimeExports.jsxs("main", { className: "min-h-screen bg-gray-50", children: [jsxRuntimeExports.jsx(framerMotion.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(framerMotion.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
2254
2421
  // variant="outline"
2255
2422
  , {
2256
2423
  // variant="outline"
2257
2424
  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(lucideReact.KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsxRuntimeExports.jsx("span", { children: isLoading
2258
2425
  ? "Logging in..."
2259
- : "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(lucideReact.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(lucideReact.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) {
2426
+ : "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(lucideReact.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(lucideReact.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) {
2260
2427
  var username = _b.username, password = _b.password, MFACode = _b.MFACode;
2261
- return __generator(this, function (_c) {
2428
+ return __generator$1(this, function (_c) {
2262
2429
  // Implement your AD login logic here
2263
2430
  console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
2264
2431
  // Example: await adLoginService(username, password, mfaCode);
@@ -2299,8 +2466,8 @@ var MFAGate = function (_a) {
2299
2466
  if (!success)
2300
2467
  camsSdk.Logger.error("MFA authentication failed");
2301
2468
  }, []);
2302
- var handleAuthFailed = React.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
2303
- return __generator(this, function (_a) {
2469
+ var handleAuthFailed = React.useCallback(function () { return __awaiter$1(void 0, void 0, void 0, function () {
2470
+ return __generator$1(this, function (_a) {
2304
2471
  switch (_a.label) {
2305
2472
  case 0: return [4 /*yield*/, context.logout()];
2306
2473
  case 1:
@@ -2309,7 +2476,6 @@ var MFAGate = function (_a) {
2309
2476
  }
2310
2477
  });
2311
2478
  }); }, [context.logout]);
2312
- camsSdk.Logger.debug("MFA Endpoint >>>", { MFAEndpoints: MFAEndpoints });
2313
2479
  if (useADLogin && !CredentialsAuthEndpoint)
2314
2480
  return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
2315
2481
  if (!validatedMFAEndpoints)