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

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,158 @@ 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
+ // Ensure crypto object exists
47
+ if (!window.crypto) {
48
+ try {
49
+ Object.defineProperty(window, 'crypto', {
50
+ value: {},
51
+ writable: true,
52
+ configurable: true
53
+ });
54
+ }
55
+ catch (e) {
56
+ // Ignore if crypto cannot be defined
57
+ }
58
+ }
59
+ // Polyfill getRandomValues
60
+ if (window.crypto && !window.crypto.getRandomValues) {
61
+ try {
62
+ Object.defineProperty(window.crypto, 'getRandomValues', {
63
+ value: function (array) {
64
+ var bytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
65
+ for (var i = 0; i < bytes.length; i++) {
66
+ bytes[i] = Math.floor(Math.random() * 256);
67
+ }
68
+ return array;
69
+ },
70
+ writable: true,
71
+ configurable: true
72
+ });
73
+ }
74
+ catch (e) {
75
+ // Ignore if getRandomValues cannot be defined
76
+ }
77
+ }
78
+ // Polyfill crypto.subtle with SHA-256 (handles both undefined and null in non-HTTPS contexts)
79
+ var needsSubtlePolyfill = window.crypto && (!window.crypto.subtle ||
80
+ window.location.protocol === 'http:' ||
81
+ window.location.hostname === 'localhost' ||
82
+ window.location.hostname === '127.0.0.1');
83
+ if (needsSubtlePolyfill) {
84
+ var sha256_1 = function (data) { return __awaiter(void 0, void 0, void 0, function () {
85
+ var bytes, hash, k, ml, msg, i, w, j, j, s0, s1, a, b, c, d, e, f, g, h, j, S1, ch, temp1, S0, maj, temp2, result, i;
86
+ return __generator(this, function (_a) {
87
+ bytes = new Uint8Array(data);
88
+ hash = new Uint32Array(8);
89
+ k = new Uint32Array([
90
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
91
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
92
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
93
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
94
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
95
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
96
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
97
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
98
+ ]);
99
+ hash[0] = 0x6a09e667;
100
+ hash[1] = 0xbb67ae85;
101
+ hash[2] = 0x3c6ef372;
102
+ hash[3] = 0xa54ff53a;
103
+ hash[4] = 0x510e527f;
104
+ hash[5] = 0x9b05688c;
105
+ hash[6] = 0x1f83d9ab;
106
+ hash[7] = 0x5be0cd19;
107
+ ml = bytes.length * 8;
108
+ msg = new Uint8Array(bytes.length + 64 + ((64 - ((bytes.length + 9) % 64)) % 64));
109
+ msg.set(bytes);
110
+ msg[bytes.length] = 0x80;
111
+ new DataView(msg.buffer).setUint32(msg.length - 4, ml, false);
112
+ for (i = 0; i < msg.length; i += 64) {
113
+ w = new Uint32Array(64);
114
+ for (j = 0; j < 16; j++)
115
+ w[j] = new DataView(msg.buffer).getUint32(i + j * 4, false);
116
+ for (j = 16; j < 64; j++) {
117
+ s0 = ((w[j - 15] >>> 7) | (w[j - 15] << 25)) ^ ((w[j - 15] >>> 18) | (w[j - 15] << 14)) ^ (w[j - 15] >>> 3);
118
+ s1 = ((w[j - 2] >>> 17) | (w[j - 2] << 15)) ^ ((w[j - 2] >>> 19) | (w[j - 2] << 13)) ^ (w[j - 2] >>> 10);
119
+ w[j] = (w[j - 16] + s0 + w[j - 7] + s1) >>> 0;
120
+ }
121
+ a = hash[0], b = hash[1], c = hash[2], d = hash[3], e = hash[4], f = hash[5], g = hash[6], h = hash[7];
122
+ for (j = 0; j < 64; j++) {
123
+ S1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7));
124
+ ch = (e & f) ^ (~e & g);
125
+ temp1 = (h + S1 + ch + k[j] + w[j]) >>> 0;
126
+ S0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10));
127
+ maj = (a & b) ^ (a & c) ^ (b & c);
128
+ temp2 = (S0 + maj) >>> 0;
129
+ h = g;
130
+ g = f;
131
+ f = e;
132
+ e = (d + temp1) >>> 0;
133
+ d = c;
134
+ c = b;
135
+ b = a;
136
+ a = (temp1 + temp2) >>> 0;
137
+ }
138
+ hash[0] = (hash[0] + a) >>> 0;
139
+ hash[1] = (hash[1] + b) >>> 0;
140
+ hash[2] = (hash[2] + c) >>> 0;
141
+ hash[3] = (hash[3] + d) >>> 0;
142
+ hash[4] = (hash[4] + e) >>> 0;
143
+ hash[5] = (hash[5] + f) >>> 0;
144
+ hash[6] = (hash[6] + g) >>> 0;
145
+ hash[7] = (hash[7] + h) >>> 0;
146
+ }
147
+ result = new Uint8Array(32);
148
+ for (i = 0; i < 8; i++)
149
+ new DataView(result.buffer).setUint32(i * 4, hash[i], false);
150
+ return [2 /*return*/, result.buffer];
151
+ });
152
+ }); };
153
+ try {
154
+ Object.defineProperty(window.crypto, 'subtle', {
155
+ value: {
156
+ digest: function (algorithm, data) { return __awaiter(void 0, void 0, void 0, function () {
157
+ var alg;
158
+ return __generator(this, function (_a) {
159
+ alg = typeof algorithm === 'string' ? algorithm : algorithm.name;
160
+ if (alg === 'SHA-256')
161
+ return [2 /*return*/, sha256_1(data)];
162
+ console.error("Unsupported crypto algorithm: ".concat(alg));
163
+ throw new Error("Unsupported algorithm: ".concat(alg));
164
+ });
165
+ }); }
166
+ },
167
+ writable: true,
168
+ configurable: true
169
+ });
170
+ }
171
+ catch (e) {
172
+ // Ignore if subtle cannot be defined
173
+ }
174
+ }
175
+ // Polyfill randomUUID
176
+ if (window.crypto && !window.crypto.randomUUID) {
177
+ try {
178
+ Object.defineProperty(window.crypto, 'randomUUID', {
179
+ value: function () {
180
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
181
+ var r = (Math.random() * 16) | 0;
182
+ var v = c === 'x' ? r : (r & 0x3) | 0x8;
183
+ return v.toString(16);
184
+ });
185
+ },
186
+ writable: true,
187
+ configurable: true
188
+ });
189
+ }
190
+ catch (e) {
191
+ // Ignore if randomUUID cannot be defined
192
+ }
193
+ }
194
+ }
195
+
43
196
  /******************************************************************************
44
197
  Copyright (c) Microsoft Corporation.
45
198
 
@@ -80,7 +233,7 @@ function __rest(s, e) {
80
233
  return t;
81
234
  }
82
235
 
83
- function __awaiter(thisArg, _arguments, P, generator) {
236
+ function __awaiter$1(thisArg, _arguments, P, generator) {
84
237
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
85
238
  return new (P || (P = Promise))(function (resolve, reject) {
86
239
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -90,7 +243,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
90
243
  });
91
244
  }
92
245
 
93
- function __generator(thisArg, body) {
246
+ function __generator$1(thisArg, body) {
94
247
  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
248
  return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
96
249
  function verb(n) { return function (v) { return step([n, v]); }; }
@@ -187,10 +340,10 @@ function useCAMSAuth(options) {
187
340
  }
188
341
  }
189
342
  }, [options.storageKey]);
190
- var login = React.useCallback(function (config) { return __awaiter(_this, void 0, void 0, function () {
343
+ var login = React.useCallback(function (config) { return __awaiter$1(_this, void 0, void 0, function () {
191
344
  var loginConfig, userProfile, err_1, e, isPopupClosedError, restoredToken, userProfile;
192
345
  var _a, _b, _c;
193
- return __generator(this, function (_d) {
346
+ return __generator$1(this, function (_d) {
194
347
  switch (_d.label) {
195
348
  case 0:
196
349
  if (!sessionManagerRef.current)
@@ -238,8 +391,8 @@ function useCAMSAuth(options) {
238
391
  }
239
392
  });
240
393
  }); }, [options.idleTimeout]);
241
- var logout = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
242
- return __generator(this, function (_a) {
394
+ var logout = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
395
+ return __generator$1(this, function (_a) {
243
396
  switch (_a.label) {
244
397
  case 0:
245
398
  if (!sessionManagerRef.current)
@@ -269,11 +422,13 @@ function useCAMSAuth(options) {
269
422
  };
270
423
  }
271
424
 
272
- var setCookie$1 = function (name, value, days) {
425
+ var setCookie = function (name, value, days) {
426
+ if (days === void 0) { days = 1; }
273
427
  var expires = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString();
428
+ console.log("Auth Cookie Expires >>>", { name: name, value: value, expires: expires });
274
429
  document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
275
430
  };
276
- var getCookie$1 = function (name) {
431
+ var getCookie = function (name) {
277
432
  var _a;
278
433
  return ((_a = document.cookie
279
434
  .split("; ")
@@ -284,23 +439,24 @@ var getCookie$1 = function (name) {
284
439
  .split("=")[1])
285
440
  : null;
286
441
  };
287
- var deleteCookie$1 = function (name) {
442
+ var deleteCookie = function (name) {
288
443
  document.cookie = name + "=; Max-Age=-99999999; path=/";
289
444
  };
290
445
 
291
446
  function useCAMSMSALAuth(options) {
292
447
  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;
448
+ 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;
449
+ var storageKey = optStorageKey || "CAMS-MSAL-AUTH-SDK";
450
+ var _b = msalReact.useMsal(), instance = _b.instance, inProgress = _b.inProgress, accounts = _b.accounts;
295
451
  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];
452
+ var _c = React.useState(null), error = _c[0], setError = _c[1];
453
+ var _d = React.useState(""), idToken = _d[0], setIdToken = _d[1];
454
+ var _e = React.useState(""), accessToken = _e[0], setAccessToken = _e[1];
455
+ var _f = React.useState(null), mfaAuthenticator = _f[0], setMfaAuthenticator = _f[1];
456
+ var _g = React.useState(false), requiresMFA = _g[0], setRequiresMFA = _g[1];
301
457
  var isLoading = inProgress !== msalBrowser.InteractionStatus.None;
302
458
  var isAuthenticated = !!account && !!accessToken && !requiresMFA;
303
- var scopes = options.scopes || ["openid", "profile", "email"];
459
+ var scopes = optScopes || ["openid", "profile", "email"];
304
460
  var isTokenValid = function (token) {
305
461
  try {
306
462
  var payload = JSON.parse(atob(token.split(".")[1]));
@@ -324,15 +480,14 @@ function useCAMSMSALAuth(options) {
324
480
  var mfaConfig = {
325
481
  accessToken: accessToken_1,
326
482
  idToken: idToken_1,
327
- appCode: options.appCode,
483
+ appCode: appCode,
328
484
  provider: "MSAL",
329
- apiEndpoint: options.MFAEndpoint,
485
+ apiEndpoint: MFAEndpoint,
330
486
  };
331
487
  var authenticator = new camsSdk.CAMSMFAAuthenticator(mfaConfig);
332
488
  setMfaAuthenticator(authenticator);
333
489
  setRequiresMFA(true);
334
490
  }
335
- camsSdk.Logger.debug("App Code", { ">>>": options.appCode });
336
491
  }
337
492
  else {
338
493
  localStorage.removeItem(storageKey);
@@ -374,22 +529,26 @@ function useCAMSMSALAuth(options) {
374
529
  // };
375
530
  // handleRedirect();
376
531
  // }, []);
377
- var login = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
532
+ var login = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
378
533
  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) {
534
+ var _a;
535
+ return __generator$1(this, function (_b) {
536
+ switch (_b.label) {
382
537
  case 0:
538
+ if (inProgress !== msalBrowser.InteractionStatus.None) {
539
+ camsSdk.Logger.warn("Authentication already in progress, ignoring duplicate call");
540
+ return [2 /*return*/];
541
+ }
383
542
  setError(null);
384
- _e.label = 1;
543
+ _b.label = 1;
385
544
  case 1:
386
- _e.trys.push([1, 3, , 4]);
545
+ _b.trys.push([1, 3, , 4]);
387
546
  return [4 /*yield*/, instance.loginPopup({
388
547
  scopes: scopes,
389
- prompt: options.prompt || "login",
548
+ prompt: prompt || "login",
390
549
  })];
391
550
  case 2:
392
- response = _e.sent();
551
+ response = _b.sent();
393
552
  console.log("Login Token response:", {
394
553
  accessToken: response.accessToken,
395
554
  idToken: response.idToken,
@@ -399,9 +558,9 @@ function useCAMSMSALAuth(options) {
399
558
  mfaConfig = {
400
559
  accessToken: response.accessToken,
401
560
  idToken: response.idToken,
402
- appCode: options.appCode,
561
+ appCode: appCode,
403
562
  provider: "MSAL",
404
- apiEndpoint: options.MFAEndpoint,
563
+ apiEndpoint: MFAEndpoint,
405
564
  };
406
565
  authenticator = new camsSdk.CAMSMFAAuthenticator(mfaConfig);
407
566
  setMfaAuthenticator(authenticator);
@@ -415,10 +574,15 @@ function useCAMSMSALAuth(options) {
415
574
  idToken: response.idToken,
416
575
  }));
417
576
  }
418
- (_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
577
+ onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess(response.accessToken);
419
578
  return [3 /*break*/, 4];
420
579
  case 3:
421
- err_1 = _e.sent();
580
+ err_1 = _b.sent();
581
+ // Handle interaction_in_progress error
582
+ if (err_1.errorCode === "interaction_in_progress") {
583
+ camsSdk.Logger.warn("Interaction already in progress, please wait");
584
+ return [2 /*return*/];
585
+ }
422
586
  // Handle user cancellation gracefully
423
587
  if (err_1.errorCode === "user_cancelled") {
424
588
  camsSdk.Logger.error("User cancelled login");
@@ -427,22 +591,22 @@ function useCAMSMSALAuth(options) {
427
591
  }
428
592
  // If popup is blocked
429
593
  if (err_1.errorCode === "popup_window_error" ||
430
- ((_b = err_1.message) === null || _b === void 0 ? void 0 : _b.includes("popup"))) {
594
+ ((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.includes("popup"))) {
431
595
  camsError_1 = new camsSdk.CAMSError(camsSdk.CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
432
596
  setError(camsError_1);
433
- (_c = options.onAuthError) === null || _c === void 0 ? void 0 : _c.call(options, camsError_1);
597
+ onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError_1);
434
598
  return [2 /*return*/];
435
599
  }
436
600
  camsError = new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1.message || err_1);
437
601
  setError(camsError);
438
- (_d = options.onAuthError) === null || _d === void 0 ? void 0 : _d.call(options, camsError);
602
+ onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError);
439
603
  return [3 /*break*/, 4];
440
604
  case 4: return [2 /*return*/];
441
605
  }
442
606
  });
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) {
607
+ }); }, [instance, scopes, prompt, appCode, MFAEndpoint, onAuthSuccess, onAuthError, storageKey, inProgress]);
608
+ var completeMFA = React.useCallback(function (data) { return __awaiter$1(_this, void 0, void 0, function () {
609
+ return __generator$1(this, function (_a) {
446
610
  if (!mfaAuthenticator) {
447
611
  throw new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "MFA Authenticator not initialized");
448
612
  }
@@ -456,7 +620,7 @@ function useCAMSMSALAuth(options) {
456
620
  accessToken: accessToken,
457
621
  idToken: idToken,
458
622
  }));
459
- setCookie$1("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), 1);
623
+ setCookie("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), activeCookiePeriod);
460
624
  setRequiresMFA(false);
461
625
  // Set requiresMFA to false after storage update
462
626
  camsSdk.Logger.debug("MFA completed successfully, storage updated", {
@@ -475,9 +639,9 @@ function useCAMSMSALAuth(options) {
475
639
  }
476
640
  return [2 /*return*/];
477
641
  });
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) {
642
+ }); }, [mfaAuthenticator, accessToken, idToken, storageKey, activeCookiePeriod]);
643
+ var sendEmailOTP = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
644
+ return __generator$1(this, function (_a) {
481
645
  switch (_a.label) {
482
646
  case 0:
483
647
  if (!mfaAuthenticator) {
@@ -488,9 +652,9 @@ function useCAMSMSALAuth(options) {
488
652
  }
489
653
  });
490
654
  }); }, [mfaAuthenticator]);
491
- var logout = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
655
+ var logout = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
492
656
  var err_2, camsError;
493
- return __generator(this, function (_a) {
657
+ return __generator$1(this, function (_a) {
494
658
  switch (_a.label) {
495
659
  case 0:
496
660
  _a.trys.push([0, 2, , 3]);
@@ -526,12 +690,13 @@ function useCAMSMSALAuth(options) {
526
690
  error: error,
527
691
  idToken: idToken,
528
692
  accessToken: accessToken,
529
- appCode: options.appCode,
693
+ appCode: appCode,
530
694
  mfaAuthenticator: mfaAuthenticator,
531
695
  requiresMFA: requiresMFA,
532
696
  completeMFA: completeMFA,
533
697
  sendEmailOTP: sendEmailOTP,
534
698
  setRequiresMFA: setRequiresMFA,
699
+ activeCookiePeriod: activeCookiePeriod,
535
700
  };
536
701
  }
537
702
 
@@ -574,10 +739,10 @@ function arrayBufferToBase64url(buffer) {
574
739
  * @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
575
740
  */
576
741
  function register(options) {
577
- return __awaiter(this, void 0, void 0, function () {
742
+ return __awaiter$1(this, void 0, void 0, function () {
578
743
  var createOptions, credential, publicKeyCredential, attestationResponse, transports, err_1;
579
744
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
580
- return __generator(this, function (_k) {
745
+ return __generator$1(this, function (_k) {
581
746
  switch (_k.label) {
582
747
  case 0:
583
748
  _k.trys.push([0, 2, , 3]);
@@ -635,10 +800,10 @@ function register(options) {
635
800
  * @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
636
801
  */
637
802
  function authenticate(options) {
638
- return __awaiter(this, void 0, void 0, function () {
803
+ return __awaiter$1(this, void 0, void 0, function () {
639
804
  var getOptions, credential, publicKeyCredential, assertionResponse;
640
805
  var _a;
641
- return __generator(this, function (_b) {
806
+ return __generator$1(this, function (_b) {
642
807
  switch (_b.label) {
643
808
  case 0:
644
809
  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 +1289,6 @@ function ProtectedRoute(_a) {
1124
1289
  }
1125
1290
 
1126
1291
  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
1292
  var isTokenValid = function (token) {
1146
1293
  try {
1147
1294
  var payload = JSON.parse(atob(token.split(".")[1]));
@@ -1190,7 +1337,7 @@ function CAMSMSALProviderInner(_a) {
1190
1337
  localStorage.setItem(auth.storageKey, JSON.stringify({
1191
1338
  accessToken: auth.accessToken,
1192
1339
  idToken: auth.idToken,
1193
- appCode: auth.appCode
1340
+ appCode: auth.appCode,
1194
1341
  }));
1195
1342
  }
1196
1343
  }, [auth.accessToken, auth.idToken, auth.storageKey]);
@@ -1206,8 +1353,8 @@ function CAMSMSALProviderInner(_a) {
1206
1353
  }
1207
1354
  }, [userProfile, profileStorageKey]);
1208
1355
  // Enhanced logout that also clears profile
1209
- var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
1210
- return __generator(this, function (_a) {
1356
+ var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
1357
+ return __generator$1(this, function (_a) {
1211
1358
  switch (_a.label) {
1212
1359
  case 0: return [4 /*yield*/, auth.logout()];
1213
1360
  case 1:
@@ -1274,7 +1421,7 @@ function CAMSProviderCore(props) {
1274
1421
  if (typeof window === "undefined")
1275
1422
  return null;
1276
1423
  try {
1277
- var storedProfile = getCookie$1(profileStorageKey);
1424
+ var storedProfile = getCookie(profileStorageKey);
1278
1425
  return storedProfile ? JSON.parse(storedProfile) : null;
1279
1426
  }
1280
1427
  catch (_a) {
@@ -1284,7 +1431,7 @@ function CAMSProviderCore(props) {
1284
1431
  var _a = React.useState(getInitialProfile), userProfile = _a[0], setUserProfile = _a[1];
1285
1432
  React.useEffect(function () {
1286
1433
  if (typeof window !== "undefined") {
1287
- var storedProfile = getCookie$1(profileStorageKey);
1434
+ var storedProfile = getCookie(profileStorageKey);
1288
1435
  if (storedProfile) {
1289
1436
  try {
1290
1437
  setUserProfile(JSON.parse(storedProfile));
@@ -1296,22 +1443,22 @@ function CAMSProviderCore(props) {
1296
1443
  React.useEffect(function () {
1297
1444
  if (typeof window !== "undefined") {
1298
1445
  if (userProfile) {
1299
- setCookie$1(profileStorageKey, JSON.stringify(userProfile), 1);
1446
+ setCookie(profileStorageKey, JSON.stringify(userProfile), 1);
1300
1447
  }
1301
1448
  else {
1302
- deleteCookie$1(profileStorageKey);
1449
+ deleteCookie(profileStorageKey);
1303
1450
  }
1304
1451
  }
1305
1452
  }, [userProfile, profileStorageKey]);
1306
- var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
1307
- return __generator(this, function (_a) {
1453
+ var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
1454
+ return __generator$1(this, function (_a) {
1308
1455
  switch (_a.label) {
1309
1456
  case 0: return [4 /*yield*/, auth.logout()];
1310
1457
  case 1:
1311
1458
  _a.sent();
1312
1459
  setUserProfile(null);
1313
1460
  if (typeof window !== "undefined") {
1314
- deleteCookie$1(profileStorageKey);
1461
+ deleteCookie(profileStorageKey);
1315
1462
  }
1316
1463
  return [2 /*return*/];
1317
1464
  }
@@ -1347,7 +1494,8 @@ function CAMSProviderCore(props) {
1347
1494
  userProfile,
1348
1495
  ]);
1349
1496
  var value = React.useMemo(function () {
1350
- return (__assign(__assign({}, auth), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode }));
1497
+ auth.logout; var authRest = __rest(auth, ["logout"]);
1498
+ return __assign(__assign({}, authRest), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode });
1351
1499
  }, [auth, userProfile, mode]);
1352
1500
  return jsxRuntimeExports.jsx(CAMSContext.Provider, { value: value, children: children });
1353
1501
  }
@@ -1355,7 +1503,7 @@ function UnifiedCAMSProvider(props) {
1355
1503
  // Validate appCode is a valid GUID
1356
1504
  var appCodeValidation = GuidSchema.safeParse(props.appCode);
1357
1505
  if (!appCodeValidation.success) {
1358
- throw new Error("Invalid appCode: ".concat(appCodeValidation.error.issues[0].message));
1506
+ throw new Error("Invalid CAS APP CODE: ".concat(appCodeValidation.error.issues[0].message));
1359
1507
  }
1360
1508
  if (props.mode === "MSAL") {
1361
1509
  var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
@@ -1723,7 +1871,7 @@ styleInject(css_248z);
1723
1871
 
1724
1872
  var LoadingSpinner = function (_a) {
1725
1873
  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..." }))] }));
1874
+ 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
1875
  };
1728
1876
 
1729
1877
  var AuthSuccessAnimation = function (_a) {
@@ -1775,15 +1923,36 @@ var APIHeaders = {
1775
1923
  "X-API-VERSION": "1.0",
1776
1924
  };
1777
1925
 
1926
+ // Creates an Axios instance with a base URL determined by the environment (production or development).
1927
+ var axiosInstance = axios.create({
1928
+ httpsAgent: new https.Agent({ rejectUnauthorized: false }),
1929
+ headers: __assign({ "Content-Type": "application/json" }, APIHeaders),
1930
+ });
1931
+ // Intercepts outgoing requests to add authorization token, version header, and timeout settings.
1932
+ axiosInstance.interceptors.request.use(function (config) {
1933
+ var _a;
1934
+ config.timeout = Number((_a = process.env.NEXT_PUBLIC_API_TIMEOUT) !== null && _a !== void 0 ? _a : 605000);
1935
+ config.timeoutErrorMessage = "Operation Timed Out"; // Custom error message for timeouts.
1936
+ return config; // Returns the modified request configuration.
1937
+ }, function (axiosError) {
1938
+ var _a, _b;
1939
+ // Handles request errors.
1940
+ return {
1941
+ status: (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status, // Extracts HTTP status from the error response.
1942
+ message: axiosError.message, // Extracts the error message.
1943
+ data: (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.data, // Extracts response data from the error.
1944
+ };
1945
+ });
1946
+
1778
1947
  var MAX_ATTEMPTS = 3;
1779
1948
  var useOTPHandler = function (_a) {
1780
1949
  var provider = _a.provider, accessToken = _a.accessToken, idToken = _a.idToken, appCode = _a.appCode, authenticationType = _a.authenticationType, MFAEndpoint = _a.MFAEndpoint, onAuthComplete = _a.onAuthComplete;
1781
1950
  var _b = React.useState(false), loading = _b[0], setLoading = _b[1];
1782
1951
  var _c = React.useState(0), attemptCount = _c[0], setAttemptCount = _c[1];
1783
1952
  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 () {
1953
+ var handleSubmitOTP = React.useMemo(function () { return function (authenticationValue) { return __awaiter$1(void 0, void 0, void 0, function () {
1785
1954
  var currentAttempt, response, error_1, currentAttempt;
1786
- return __generator(this, function (_a) {
1955
+ return __generator$1(this, function (_a) {
1787
1956
  switch (_a.label) {
1788
1957
  case 0:
1789
1958
  if (isMaxAttemptsReached) {
@@ -1800,16 +1969,13 @@ var useOTPHandler = function (_a) {
1800
1969
  setAttemptCount(currentAttempt);
1801
1970
  if (authenticationType === null)
1802
1971
  return [2 /*return*/, false];
1803
- return [4 /*yield*/, axios.post(MFAEndpoint || "/api/auth/verify-mfa", {
1972
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoint || "/api/auth/verify-mfa", {
1804
1973
  provider: provider,
1805
1974
  accessToken: accessToken,
1806
1975
  idToken: idToken,
1807
1976
  authenticationType: authenticationType,
1808
1977
  MFACode: authenticationValue,
1809
1978
  appCode: appCode,
1810
- }, {
1811
- headers: APIHeaders,
1812
- timeout: 605000,
1813
1979
  })];
1814
1980
  case 2:
1815
1981
  response = (_a.sent()).data;
@@ -1876,23 +2042,20 @@ var useCredentialsHandler = function (onAuthComplete) {
1876
2042
  var _b = React.useState(0), attemptCount = _b[0], setAttemptCount = _b[1];
1877
2043
  var _c = React.useState(false), isMaxAttemptsReached = _c[0], setIsMaxAttemptsReached = _c[1];
1878
2044
  var handleSubmitCredentials = React.useMemo(function () {
1879
- return function (CredAuthEndpoint, credentials, appCode) { return __awaiter(void 0, void 0, void 0, function () {
2045
+ return function (CredAuthEndpoint, credentials, appCode) { return __awaiter$1(void 0, void 0, void 0, function () {
1880
2046
  var currentAttempt, response, error_2, currentAttempt;
1881
- return __generator(this, function (_a) {
2047
+ return __generator$1(this, function (_a) {
1882
2048
  switch (_a.label) {
1883
2049
  case 0:
1884
2050
  _a.trys.push([0, 2, 3, 4]);
1885
2051
  setLoading(true);
1886
2052
  currentAttempt = attemptCount + 1;
1887
2053
  setAttemptCount(currentAttempt);
1888
- return [4 /*yield*/, axios.post(CredAuthEndpoint, {
2054
+ return [4 /*yield*/, axiosInstance.post(CredAuthEndpoint, {
1889
2055
  username: credentials.username,
1890
2056
  password: credentials.password,
1891
2057
  MFACode: credentials.MFACode,
1892
2058
  appCode: appCode,
1893
- }, {
1894
- headers: APIHeaders,
1895
- timeout: 605000,
1896
2059
  })];
1897
2060
  case 1:
1898
2061
  response = (_a.sent()).data;
@@ -1953,23 +2116,21 @@ var MFAOptions = function (_a) {
1953
2116
  var context = useCAMSContext();
1954
2117
  var _f = context.authMode === "MSAL" && "sendEmailOTP" in context
1955
2118
  ? context
1956
- : { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
2119
+ : { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter$1(void 0, void 0, void 0, function () { return __generator$1(this, function (_a) {
1957
2120
  return [2 /*return*/];
1958
2121
  }); }); } }, sendEmailOTP = _f.sendEmailOTP, completeMFA = _f.completeMFA, logout = _f.logout;
1959
2122
  var accessToken = context.authMode === "MSAL" ? context.accessToken : "";
1960
2123
  var idToken = context.authMode === "MSAL" ? context.idToken : "";
1961
2124
  var authenticate = useWebAuthn().authenticate;
1962
- var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
2125
+ var handleFIDOLogin = function () { return __awaiter$1(void 0, void 0, void 0, function () {
1963
2126
  var options, assertionResponse, error_1;
1964
- return __generator(this, function (_a) {
2127
+ return __generator$1(this, function (_a) {
1965
2128
  switch (_a.label) {
1966
2129
  case 0:
1967
2130
  _a.trys.push([0, 4, , 5]);
1968
2131
  // 1. Fetch authentication challenge from your server
1969
2132
  console.log("Requesting authentication challenge from server...");
1970
- return [4 /*yield*/, axios.post(MFAEndpoints.RetrieveAuthChallenge, {}, {
1971
- headers: APIHeaders,
1972
- })];
2133
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RetrieveAuthChallenge, {})];
1973
2134
  case 1:
1974
2135
  options = (_a.sent()).data;
1975
2136
  console.log("Received challenge:", options);
@@ -1981,10 +2142,7 @@ var MFAOptions = function (_a) {
1981
2142
  console.log("Authentication assertion received from client:", assertionResponse);
1982
2143
  // 3. Send the assertion back to the server for verification
1983
2144
  console.log("Sending assertion to server for verification...");
1984
- return [4 /*yield*/, axios.post(MFAEndpoints.AuthChallengeVerify, assertionResponse, {
1985
- headers: APIHeaders,
1986
- withCredentials: true, // credentials: 'include'
1987
- })];
2145
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.AuthChallengeVerify, assertionResponse)];
1988
2146
  case 3:
1989
2147
  _a.sent();
1990
2148
  sonner.toast.success("🔑 Sign-in successful!");
@@ -2046,12 +2204,12 @@ var MFAOptions = function (_a) {
2046
2204
  }
2047
2205
  var content = jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {});
2048
2206
  if (!authType) {
2049
- 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 () {
2207
+ 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 () {
2050
2208
  var success;
2051
- return __generator(this, function (_a) {
2209
+ return __generator$1(this, function (_a) {
2052
2210
  switch (_a.label) {
2053
2211
  case 0:
2054
- resetAttempts();
2212
+ // resetAttempts();
2055
2213
  setAuthType("EmailOTP");
2056
2214
  setOtpVisible(true);
2057
2215
  if (!sendEmailOTP) return [3 /*break*/, 2];
@@ -2068,7 +2226,6 @@ var MFAOptions = function (_a) {
2068
2226
  }
2069
2227
  });
2070
2228
  }); }, 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 () {
2071
- resetAttempts();
2072
2229
  setAuthType("AuthenticatorCode");
2073
2230
  setOtpVisible(true);
2074
2231
  }, 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",
@@ -2077,7 +2234,7 @@ var MFAOptions = function (_a) {
2077
2234
  // setAuthType("AuthenticatorCode");
2078
2235
  // setOtpVisible(true);
2079
2236
  // }}
2080
- 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" })] })] }))] })] }));
2237
+ 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" })] })] }))] })] }));
2081
2238
  }
2082
2239
  else if (authType === "EmailOTP") {
2083
2240
  content = (jsxRuntimeExports.jsx(Dialog, { open: otpVisible, onOpenChange: function () {
@@ -2120,16 +2277,16 @@ var ADLoginModal = function (_a) {
2120
2277
  resolver: a$1(credentialsSchema),
2121
2278
  defaultValues: { username: "", password: "" },
2122
2279
  });
2123
- var handleCredentialsSubmit = function (values) { return __awaiter(void 0, void 0, void 0, function () {
2124
- return __generator(this, function (_a) {
2280
+ var handleCredentialsSubmit = function (values) { return __awaiter$1(void 0, void 0, void 0, function () {
2281
+ return __generator$1(this, function (_a) {
2125
2282
  setCredentials(values);
2126
2283
  setStep("mfa");
2127
2284
  return [2 /*return*/];
2128
2285
  });
2129
2286
  }); };
2130
- var handleMFASubmit = function (code) { return __awaiter(void 0, void 0, void 0, function () {
2287
+ var handleMFASubmit = function (code) { return __awaiter$1(void 0, void 0, void 0, function () {
2131
2288
  var error_1;
2132
- return __generator(this, function (_a) {
2289
+ return __generator$1(this, function (_a) {
2133
2290
  switch (_a.label) {
2134
2291
  case 0:
2135
2292
  setIsLoading(true);
@@ -2190,8 +2347,8 @@ var DefaultLoginPage = function (_a) {
2190
2347
  var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
2191
2348
  var _b = React.useState(false), showADModal = _b[0], setShowADModal = _b[1];
2192
2349
  var register = useWebAuthn().register;
2193
- var _c = useCredentialsHandler(function (state, data) { return __awaiter(void 0, void 0, void 0, function () {
2194
- return __generator(this, function (_a) {
2350
+ var _c = useCredentialsHandler(function (state, data) { return __awaiter$1(void 0, void 0, void 0, function () {
2351
+ return __generator$1(this, function (_a) {
2195
2352
  console.log(data);
2196
2353
  if (state && data) {
2197
2354
  context.isAuthenticated = true;
@@ -2205,6 +2362,10 @@ var DefaultLoginPage = function (_a) {
2205
2362
  });
2206
2363
  }); }), handleSubmitCredentials = _c.handleSubmitCredentials, isCredAuthLoading = _c.loading, setIsCredAuthLoading = _c.setLoading;
2207
2364
  var handleMSALLogin = function () {
2365
+ if (typeof window !== "undefined" && !window.crypto) {
2366
+ sonner.toast.error("Crypto API not available. Please use a modern browser.");
2367
+ return;
2368
+ }
2208
2369
  if (authMode === "MSAL") {
2209
2370
  login();
2210
2371
  }
@@ -2213,17 +2374,15 @@ var DefaultLoginPage = function (_a) {
2213
2374
  console.warn("Regular CAMS login requires configuration");
2214
2375
  }
2215
2376
  };
2216
- var handleRegister = function (data) { return __awaiter(void 0, void 0, void 0, function () {
2377
+ var handleRegister = function (data) { return __awaiter$1(void 0, void 0, void 0, function () {
2217
2378
  var options, attestationResponse, error_1;
2218
- return __generator(this, function (_a) {
2379
+ return __generator$1(this, function (_a) {
2219
2380
  switch (_a.label) {
2220
2381
  case 0:
2221
2382
  _a.trys.push([0, 4, , 5]);
2222
2383
  // 1. Fetch challenge from your server
2223
2384
  console.log("Requesting registration challenge from server...");
2224
- return [4 /*yield*/, axios.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data), {
2225
- headers: APIHeaders,
2226
- })];
2385
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data))];
2227
2386
  case 1:
2228
2387
  options = (_a.sent()).data;
2229
2388
  console.log("Received challenge:", options);
@@ -2235,10 +2394,7 @@ var DefaultLoginPage = function (_a) {
2235
2394
  console.log("Passkey created on client:", attestationResponse);
2236
2395
  // 3. Send the response back to the server for verification
2237
2396
  console.log("Sending attestation to server for verification...");
2238
- return [4 /*yield*/, axios.post(MFAEndpoints.RegisterVerify, attestationResponse, {
2239
- headers: APIHeaders,
2240
- withCredentials: true, // credentials: 'include'
2241
- })];
2397
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterVerify + "?username=".concat(data.username), attestationResponse)];
2242
2398
  case 3:
2243
2399
  _a.sent();
2244
2400
  sonner.toast.success("✅ Registration successful! Passkey created.");
@@ -2252,15 +2408,15 @@ var DefaultLoginPage = function (_a) {
2252
2408
  }
2253
2409
  });
2254
2410
  }); };
2255
- 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
2411
+ 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
2256
2412
  // variant="outline"
2257
2413
  , {
2258
2414
  // variant="outline"
2259
2415
  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
2260
2416
  ? "Logging in..."
2261
- : "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) {
2417
+ : "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) {
2262
2418
  var username = _b.username, password = _b.password, MFACode = _b.MFACode;
2263
- return __generator(this, function (_c) {
2419
+ return __generator$1(this, function (_c) {
2264
2420
  // Implement your AD login logic here
2265
2421
  console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
2266
2422
  // Example: await adLoginService(username, password, mfaCode);
@@ -2301,8 +2457,8 @@ var MFAGate = function (_a) {
2301
2457
  if (!success)
2302
2458
  camsSdk.Logger.error("MFA authentication failed");
2303
2459
  }, []);
2304
- var handleAuthFailed = React.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
2305
- return __generator(this, function (_a) {
2460
+ var handleAuthFailed = React.useCallback(function () { return __awaiter$1(void 0, void 0, void 0, function () {
2461
+ return __generator$1(this, function (_a) {
2306
2462
  switch (_a.label) {
2307
2463
  case 0: return [4 /*yield*/, context.logout()];
2308
2464
  case 1:
@@ -2311,7 +2467,6 @@ var MFAGate = function (_a) {
2311
2467
  }
2312
2468
  });
2313
2469
  }); }, [context.logout]);
2314
- camsSdk.Logger.debug("MFA Endpoint >>>", { MFAEndpoints: MFAEndpoints });
2315
2470
  if (useADLogin && !CredentialsAuthEndpoint)
2316
2471
  return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
2317
2472
  if (!validatedMFAEndpoints)