@nibssplc/cams-sdk-react 0.0.1-beta.46 → 0.0.1-beta.48
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/hooks/useCAMSMSALAuth.d.ts +1 -0
- package/dist/index.cjs.js +61 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +62 -4
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
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,72 @@ 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
|
-
|
|
16806
|
-
|
|
16805
|
+
Logger$1.info("source", {
|
|
16806
|
+
origin: window.location.origin,
|
|
16807
|
+
mfaUrl: options.mfaUrl,
|
|
16808
|
+
});
|
|
16809
|
+
var currentOrigin = window.location.origin;
|
|
16810
|
+
var mfaUrlWithOrigin = "".concat(options.mfaUrl, "?origin=").concat(encodeURIComponent(currentOrigin));
|
|
16811
|
+
var authWindow_1 = window.open(mfaUrlWithOrigin, "_blank", "width=500,height=600,left=".concat(left, ",top=").concat(top_1, ",scrollbars=yes,resizable=yes"));
|
|
16812
|
+
if (!authWindow_1) {
|
|
16807
16813
|
Logger$1.error("Popup window blocked");
|
|
16808
16814
|
throw new CAMSError(CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
|
|
16809
16815
|
}
|
|
16810
|
-
if (
|
|
16816
|
+
if (authWindow_1.closed) {
|
|
16811
16817
|
Logger$1.error("Popup immediately closed by blocker");
|
|
16812
16818
|
throw new CAMSError(CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
|
|
16813
16819
|
}
|
|
16820
|
+
var cleanup_1 = function () {
|
|
16821
|
+
window.removeEventListener("message", listener_1);
|
|
16822
|
+
clearInterval(checkClosed_1);
|
|
16823
|
+
};
|
|
16824
|
+
var cleanupAndClose_1 = function (error) {
|
|
16825
|
+
var _a;
|
|
16826
|
+
cleanup_1();
|
|
16827
|
+
try {
|
|
16828
|
+
if (authWindow_1 && !authWindow_1.closed) {
|
|
16829
|
+
authWindow_1.close();
|
|
16830
|
+
}
|
|
16831
|
+
}
|
|
16832
|
+
catch (_b) { }
|
|
16833
|
+
if (error) {
|
|
16834
|
+
setError(error);
|
|
16835
|
+
(_a = options.onAuthError) === null || _a === void 0 ? void 0 : _a.call(options, error);
|
|
16836
|
+
}
|
|
16837
|
+
};
|
|
16838
|
+
var listener_1 = function (event) {
|
|
16839
|
+
if (event.source !== authWindow_1)
|
|
16840
|
+
return;
|
|
16841
|
+
var expectedOrigin = options.messageOrigin || new URL(options.mfaUrl || "").origin;
|
|
16842
|
+
if (expectedOrigin && event.origin !== expectedOrigin)
|
|
16843
|
+
return;
|
|
16844
|
+
var tokenMsg = ProfileSchema.safeParse(event.data);
|
|
16845
|
+
if (tokenMsg.success) {
|
|
16846
|
+
localStorage.setItem(storageKey, JSON.stringify({
|
|
16847
|
+
isAuthenticated: true,
|
|
16848
|
+
accessToken: response.accessToken,
|
|
16849
|
+
idToken: response.idToken,
|
|
16850
|
+
appCode: "",
|
|
16851
|
+
}));
|
|
16852
|
+
cleanupAndClose_1();
|
|
16853
|
+
return;
|
|
16854
|
+
}
|
|
16855
|
+
var authFailureMsg = AuthFailureMessageSchema.safeParse(event.data);
|
|
16856
|
+
if (authFailureMsg.success) {
|
|
16857
|
+
cleanupAndClose_1(new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, authFailureMsg.data.error));
|
|
16858
|
+
return;
|
|
16859
|
+
}
|
|
16860
|
+
var errorMsg = ErrorMessageSchema.safeParse(event.data);
|
|
16861
|
+
if (errorMsg.success) {
|
|
16862
|
+
cleanupAndClose_1(new CAMSError(CAMSErrorType.USER_CANCELLED, errorMsg.data.error));
|
|
16863
|
+
}
|
|
16864
|
+
};
|
|
16865
|
+
window.addEventListener("message", listener_1);
|
|
16866
|
+
var checkClosed_1 = setInterval(function () {
|
|
16867
|
+
if (authWindow_1.closed) {
|
|
16868
|
+
cleanupAndClose_1(new CAMSError(CAMSErrorType.USER_CANCELLED, "Authentication cancelled"));
|
|
16869
|
+
}
|
|
16870
|
+
}, 1000);
|
|
16814
16871
|
(_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
|
|
16815
16872
|
}
|
|
16816
16873
|
})];
|
|
@@ -16851,6 +16908,7 @@ function useCAMSMSALAuth(options) {
|
|
|
16851
16908
|
setToken("");
|
|
16852
16909
|
setAccessToken("");
|
|
16853
16910
|
setIdToken("");
|
|
16911
|
+
setAppCode("");
|
|
16854
16912
|
setError(null);
|
|
16855
16913
|
if (typeof window !== "undefined") {
|
|
16856
16914
|
localStorage.removeItem(storageKey);
|