@nibssplc/cams-sdk-react 1.0.0-rc.21 → 1.0.0-rc.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -361,12 +361,12 @@ function useCAMSAuth(options) {
361
361
  };
362
362
  }
363
363
 
364
- var setCookie$1 = function (name, value, days) {
365
- if (days === void 0) { days = 1; }
364
+ var setCookie = function (name, value, days) {
366
365
  var expires = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString();
366
+ console.log("Auth Cookie Expires >>>", { name: name, value: value, expires: expires });
367
367
  document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
368
368
  };
369
- var getCookie$1 = function (name) {
369
+ var getCookie = function (name) {
370
370
  var _a;
371
371
  return ((_a = document.cookie
372
372
  .split("; ")
@@ -377,21 +377,21 @@ var getCookie$1 = function (name) {
377
377
  .split("=")[1])
378
378
  : null;
379
379
  };
380
- var deleteCookie$1 = function (name) {
380
+ var deleteCookie = function (name) {
381
381
  document.cookie = name + "=; Max-Age=-99999999; path=/";
382
382
  };
383
383
 
384
384
  function useCAMSMSALAuth(options) {
385
385
  var _this = this;
386
- 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;
386
+ var optStorageKey = options.storageKey, optScopes = options.scopes, prompt = options.prompt, appCode = options.appCode, MFAEndpoint = options.MFAEndpoint, onAuthSuccess = options.onAuthSuccess, onAuthError = options.onAuthError;
387
387
  var storageKey = optStorageKey || "CAMS-MSAL-AUTH-SDK";
388
- var _b = useMsal(), instance = _b.instance, inProgress = _b.inProgress, accounts = _b.accounts;
388
+ var _a = useMsal(), instance = _a.instance, inProgress = _a.inProgress, accounts = _a.accounts;
389
389
  var account = useAccount(accounts[0] || {});
390
- var _c = useState(null), error = _c[0], setError = _c[1];
391
- var _d = useState(""), idToken = _d[0], setIdToken = _d[1];
392
- var _e = useState(""), accessToken = _e[0], setAccessToken = _e[1];
393
- var _f = useState(null), mfaAuthenticator = _f[0], setMfaAuthenticator = _f[1];
394
- var _g = useState(false), requiresMFA = _g[0], setRequiresMFA = _g[1];
390
+ var _b = useState(null), error = _b[0], setError = _b[1];
391
+ var _c = useState(""), idToken = _c[0], setIdToken = _c[1];
392
+ var _d = useState(""), accessToken = _d[0], setAccessToken = _d[1];
393
+ var _e = useState(null), mfaAuthenticator = _e[0], setMfaAuthenticator = _e[1];
394
+ var _f = useState(false), requiresMFA = _f[0], setRequiresMFA = _f[1];
395
395
  var isLoading = inProgress !== InteractionStatus.None;
396
396
  var isAuthenticated = !!account && !!accessToken && !requiresMFA;
397
397
  var scopes = optScopes || ["openid", "profile", "email"];
@@ -558,7 +558,7 @@ function useCAMSMSALAuth(options) {
558
558
  accessToken: accessToken,
559
559
  idToken: idToken,
560
560
  }));
561
- setCookie$1("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), activeCookiePeriod);
561
+ setCookie("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), 1);
562
562
  setRequiresMFA(false);
563
563
  // Set requiresMFA to false after storage update
564
564
  Logger.debug("MFA completed successfully, storage updated", {
@@ -577,7 +577,7 @@ function useCAMSMSALAuth(options) {
577
577
  }
578
578
  return [2 /*return*/];
579
579
  });
580
- }); }, [mfaAuthenticator, accessToken, idToken, storageKey, activeCookiePeriod]);
580
+ }); }, [mfaAuthenticator, accessToken, idToken, storageKey]);
581
581
  var sendEmailOTP = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
582
582
  return __generator$1(this, function (_a) {
583
583
  switch (_a.label) {
@@ -633,8 +633,7 @@ function useCAMSMSALAuth(options) {
633
633
  requiresMFA: requiresMFA,
634
634
  completeMFA: completeMFA,
635
635
  sendEmailOTP: sendEmailOTP,
636
- setRequiresMFA: setRequiresMFA,
637
- activeCookiePeriod: activeCookiePeriod,
636
+ setRequiresMFA: setRequiresMFA
638
637
  };
639
638
  }
640
639
 
@@ -1227,26 +1226,6 @@ function ProtectedRoute(_a) {
1227
1226
  }
1228
1227
 
1229
1228
  var CAMSMSALContext = createContext(null);
1230
- var setCookie = function (name, value, days) {
1231
- if (days === void 0) { days = 1; }
1232
- var expires = new Date(Date.now() + days * 864e5).toUTCString();
1233
- Logger.debug("Auth Cookie Expires >>>", { name: name, value: value, expires: expires });
1234
- document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
1235
- };
1236
- var getCookie = function (name) {
1237
- var _a;
1238
- return ((_a = document.cookie
1239
- .split("; ")
1240
- .find(function (row) { return row.startsWith(name + "="); })) === null || _a === void 0 ? void 0 : _a.split("=")[1])
1241
- ? decodeURIComponent(document.cookie
1242
- .split("; ")
1243
- .find(function (row) { return row.startsWith(name + "="); })
1244
- .split("=")[1])
1245
- : null;
1246
- };
1247
- var deleteCookie = function (name) {
1248
- document.cookie = name + "=; Max-Age=-99999999; path=/";
1249
- };
1250
1229
  var isTokenValid = function (token) {
1251
1230
  try {
1252
1231
  var payload = JSON.parse(atob(token.split(".")[1]));
@@ -1303,7 +1282,7 @@ function CAMSMSALProviderInner(_a) {
1303
1282
  useEffect(function () {
1304
1283
  if (typeof window !== "undefined") {
1305
1284
  if (userProfile) {
1306
- setCookie(profileStorageKey, JSON.stringify(userProfile), auth.activeCookiePeriod); // Store for 1 day
1285
+ setCookie(profileStorageKey, JSON.stringify(userProfile), 1); // Store for 1 day
1307
1286
  }
1308
1287
  else {
1309
1288
  deleteCookie(profileStorageKey);
@@ -1330,9 +1309,7 @@ function CAMSMSALProviderInner(_a) {
1330
1309
  }
1331
1310
  function CAMSMSALProvider(props) {
1332
1311
  var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
1333
- var instance = typeof window !== "undefined"
1334
- ? msalInstance || new PublicClientApplication(msalConfig)
1335
- : null;
1312
+ var instance = msalInstance || new PublicClientApplication(msalConfig);
1336
1313
  return (jsxRuntimeExports.jsx(MsalProvider, { instance: instance, children: jsxRuntimeExports.jsx(CAMSMSALProviderInner, __assign({}, props)) }));
1337
1314
  }
1338
1315
  function useCAMSMSALContext() {
@@ -1381,7 +1358,7 @@ function CAMSProviderCore(props) {
1381
1358
  if (typeof window === "undefined")
1382
1359
  return null;
1383
1360
  try {
1384
- var storedProfile = getCookie$1(profileStorageKey);
1361
+ var storedProfile = getCookie(profileStorageKey);
1385
1362
  return storedProfile ? JSON.parse(storedProfile) : null;
1386
1363
  }
1387
1364
  catch (_a) {
@@ -1391,7 +1368,7 @@ function CAMSProviderCore(props) {
1391
1368
  var _a = useState(getInitialProfile), userProfile = _a[0], setUserProfile = _a[1];
1392
1369
  useEffect(function () {
1393
1370
  if (typeof window !== "undefined") {
1394
- var storedProfile = getCookie$1(profileStorageKey);
1371
+ var storedProfile = getCookie(profileStorageKey);
1395
1372
  if (storedProfile) {
1396
1373
  try {
1397
1374
  setUserProfile(JSON.parse(storedProfile));
@@ -1403,10 +1380,10 @@ function CAMSProviderCore(props) {
1403
1380
  useEffect(function () {
1404
1381
  if (typeof window !== "undefined") {
1405
1382
  if (userProfile) {
1406
- setCookie$1(profileStorageKey, JSON.stringify(userProfile), 1);
1383
+ setCookie(profileStorageKey, JSON.stringify(userProfile), 1);
1407
1384
  }
1408
1385
  else {
1409
- deleteCookie$1(profileStorageKey);
1386
+ deleteCookie(profileStorageKey);
1410
1387
  }
1411
1388
  }
1412
1389
  }, [userProfile, profileStorageKey]);
@@ -1418,7 +1395,7 @@ function CAMSProviderCore(props) {
1418
1395
  _a.sent();
1419
1396
  setUserProfile(null);
1420
1397
  if (typeof window !== "undefined") {
1421
- deleteCookie$1(profileStorageKey);
1398
+ deleteCookie(profileStorageKey);
1422
1399
  }
1423
1400
  return [2 /*return*/];
1424
1401
  }
@@ -1463,13 +1440,11 @@ function UnifiedCAMSProvider(props) {
1463
1440
  // Validate appCode is a valid GUID
1464
1441
  var appCodeValidation = GuidSchema.safeParse(props.appCode);
1465
1442
  if (!appCodeValidation.success) {
1466
- throw new Error("Invalid appCode: ".concat(appCodeValidation.error.issues[0].message));
1443
+ throw new Error("Invalid CAS APP CODE: ".concat(appCodeValidation.error.issues[0].message));
1467
1444
  }
1468
1445
  if (props.mode === "MSAL") {
1469
1446
  var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
1470
- var instance = typeof window !== "undefined"
1471
- ? msalInstance || new PublicClientApplication(msalConfig)
1472
- : null;
1447
+ var instance = msalInstance || new PublicClientApplication(msalConfig);
1473
1448
  return (jsxRuntimeExports.jsx(MsalProvider, { instance: instance, children: jsxRuntimeExports.jsx(CAMSProviderCore, __assign({}, props)) }));
1474
1449
  }
1475
1450
  return (jsxRuntimeExports.jsx(ClientOnly, { fallback: jsxRuntimeExports.jsx("div", { children: "Loading..." }), children: jsxRuntimeExports.jsx(CAMSProviderCore, __assign({}, props)) }));