@nibssplc/cams-sdk-react 0.0.1-beta.46 → 0.0.1-beta.47

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
@@ -1,6 +1,6 @@
1
1
  import * as React__default from 'react';
2
2
  import React__default__default, { useState, useRef, useEffect, useCallback, useMemo, useReducer, useContext, createContext } from 'react';
3
- import { CAMSSessionManager, CAMSError, CAMSErrorType, Logger as Logger$1 } from '@nibssplc/cams-sdk';
3
+ import { CAMSSessionManager, CAMSError, CAMSErrorType, Logger as Logger$1, ProfileSchema, AuthFailureMessageSchema, ErrorMessageSchema } from '@nibssplc/cams-sdk';
4
4
  export * from '@nibssplc/cams-sdk';
5
5
 
6
6
  /******************************************************************************
@@ -16802,15 +16802,63 @@ function useCAMSMSALAuth(options) {
16802
16802
  // Center the popup window
16803
16803
  var left = (window.screen.width - 500) / 2;
16804
16804
  var top_1 = (window.screen.height - 600) / 2;
16805
- var authWindow = window.open(options.mfaUrl, "_blank", "width=500,height=600,left=".concat(left, ",top=").concat(top_1, ",scrollbars=yes,resizable=yes"));
16806
- if (!authWindow) {
16805
+ var authWindow_1 = window.open(options.mfaUrl, "_blank", "width=500,height=600,left=".concat(left, ",top=").concat(top_1, ",scrollbars=yes,resizable=yes"));
16806
+ if (!authWindow_1) {
16807
16807
  Logger$1.error("Popup window blocked");
16808
16808
  throw new CAMSError(CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
16809
16809
  }
16810
- if (authWindow.closed) {
16810
+ if (authWindow_1.closed) {
16811
16811
  Logger$1.error("Popup immediately closed by blocker");
16812
16812
  throw new CAMSError(CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
16813
16813
  }
16814
+ var cleanup_1 = function () {
16815
+ window.removeEventListener('message', listener_1);
16816
+ clearInterval(checkClosed_1);
16817
+ };
16818
+ var cleanupAndClose_1 = function (error) {
16819
+ var _a;
16820
+ cleanup_1();
16821
+ try {
16822
+ if (authWindow_1 && !authWindow_1.closed) {
16823
+ authWindow_1.close();
16824
+ }
16825
+ }
16826
+ catch (_b) { }
16827
+ if (error) {
16828
+ setError(error);
16829
+ (_a = options.onAuthError) === null || _a === void 0 ? void 0 : _a.call(options, error);
16830
+ }
16831
+ };
16832
+ var listener_1 = function (event) {
16833
+ if (event.source !== authWindow_1)
16834
+ return;
16835
+ var tokenMsg = ProfileSchema.safeParse(event.data);
16836
+ if (tokenMsg.success) {
16837
+ localStorage.setItem(storageKey, JSON.stringify({
16838
+ isAuthenticated: true,
16839
+ accessToken: response.accessToken,
16840
+ idToken: response.idToken,
16841
+ appCode: ''
16842
+ }));
16843
+ cleanupAndClose_1();
16844
+ return;
16845
+ }
16846
+ var authFailureMsg = AuthFailureMessageSchema.safeParse(event.data);
16847
+ if (authFailureMsg.success) {
16848
+ cleanupAndClose_1(new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, authFailureMsg.data.error));
16849
+ return;
16850
+ }
16851
+ var errorMsg = ErrorMessageSchema.safeParse(event.data);
16852
+ if (errorMsg.success) {
16853
+ cleanupAndClose_1(new CAMSError(CAMSErrorType.USER_CANCELLED, errorMsg.data.error));
16854
+ }
16855
+ };
16856
+ window.addEventListener('message', listener_1);
16857
+ var checkClosed_1 = setInterval(function () {
16858
+ if (authWindow_1.closed) {
16859
+ cleanupAndClose_1(new CAMSError(CAMSErrorType.USER_CANCELLED, 'Authentication cancelled'));
16860
+ }
16861
+ }, 1000);
16814
16862
  (_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
16815
16863
  }
16816
16864
  })];
@@ -16851,6 +16899,7 @@ function useCAMSMSALAuth(options) {
16851
16899
  setToken("");
16852
16900
  setAccessToken("");
16853
16901
  setIdToken("");
16902
+ setAppCode("");
16854
16903
  setError(null);
16855
16904
  if (typeof window !== "undefined") {
16856
16905
  localStorage.removeItem(storageKey);