@nibssplc/cams-sdk-react 0.0.1-beta.29 → 0.0.1-beta.31
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/components/CAMSMSALProvider.d.ts +10 -2
- package/dist/components/CAMSProvider.d.ts +6 -1
- package/dist/hooks/useCAMSMSALAuth.d.ts +1 -1
- package/dist/index.cjs.js +46 -13
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +46 -14
- package/dist/index.esm.js.map +1 -1
- package/package.json +6 -3
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { PublicClientApplication, Configuration } from '@azure/msal-browser';
|
|
3
|
-
|
|
3
|
+
import { UseCAMSMSALAuthReturn, UseCAMSMSALAuthOptions } from '../hooks/useCAMSMSALAuth';
|
|
4
|
+
interface CAMSMSALContextValue extends UseCAMSMSALAuthReturn {
|
|
5
|
+
isAuthenticated: boolean;
|
|
6
|
+
idToken: string | null;
|
|
7
|
+
accessToken: string | null;
|
|
8
|
+
}
|
|
9
|
+
export interface CAMSMSALProviderProps extends UseCAMSMSALAuthOptions {
|
|
4
10
|
children: React.ReactNode;
|
|
5
11
|
msalConfig: Configuration;
|
|
6
12
|
msalInstance?: PublicClientApplication;
|
|
7
13
|
}
|
|
8
|
-
export declare function CAMSMSALProvider(
|
|
14
|
+
export declare function CAMSMSALProvider(props: CAMSMSALProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
export declare function useCAMSMSALContext(): CAMSMSALContextValue;
|
|
16
|
+
export {};
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { CAMSConfig } from '@nibssplc/cams-sdk';
|
|
3
3
|
import { UseCAMSAuthReturn, UseCAMSAuthOptions } from '../hooks/useCAMSAuth';
|
|
4
|
+
import { UseCAMSMSALAuthOptions } from '../hooks/useCAMSMSALAuth';
|
|
4
5
|
interface CAMSContextValue extends UseCAMSAuthReturn {
|
|
5
6
|
defaultConfig?: Partial<CAMSConfig>;
|
|
7
|
+
isAuthenticated: boolean;
|
|
8
|
+
idToken: string | null;
|
|
9
|
+
accessToken: string | null;
|
|
6
10
|
}
|
|
7
11
|
export interface CAMSProviderProps extends UseCAMSAuthOptions {
|
|
8
12
|
children: ReactNode;
|
|
9
13
|
defaultConfig?: Partial<CAMSConfig>;
|
|
14
|
+
msalOptions?: UseCAMSMSALAuthOptions;
|
|
10
15
|
}
|
|
11
|
-
export declare function CAMSProvider({ children, defaultConfig, ...authOptions }: CAMSProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export declare function CAMSProvider({ children, defaultConfig, msalOptions, ...authOptions }: CAMSProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
12
17
|
export declare function useCAMSContext(): CAMSContextValue;
|
|
13
18
|
export {};
|
package/dist/index.cjs.js
CHANGED
|
@@ -16737,7 +16737,7 @@ function useCAMSMSALAuth(options) {
|
|
|
16737
16737
|
setAccessToken(response.accessToken);
|
|
16738
16738
|
setIdToken(response.idToken);
|
|
16739
16739
|
setIsMFAPending(true);
|
|
16740
|
-
if (typeof window !== "undefined") {
|
|
16740
|
+
if (typeof window !== "undefined" && process.env.NODE_ENV !== 'test') {
|
|
16741
16741
|
window.location.href = options.mfaUrl;
|
|
16742
16742
|
}
|
|
16743
16743
|
(_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
|
|
@@ -17252,16 +17252,10 @@ var jsxRuntimeExports = jsxRuntime.exports;
|
|
|
17252
17252
|
|
|
17253
17253
|
var CAMSContext = React__default.createContext(null);
|
|
17254
17254
|
function CAMSProvider(_a) {
|
|
17255
|
-
var children = _a.children, defaultConfig = _a.defaultConfig, authOptions = __rest(_a, ["children", "defaultConfig"]);
|
|
17256
|
-
var _b = React__default.useState(false), mounted = _b[0], setMounted = _b[1];
|
|
17255
|
+
var children = _a.children, defaultConfig = _a.defaultConfig, msalOptions = _a.msalOptions, authOptions = __rest(_a, ["children", "defaultConfig", "msalOptions"]);
|
|
17257
17256
|
var auth = useCAMSAuth(authOptions);
|
|
17258
|
-
|
|
17259
|
-
|
|
17260
|
-
}, []);
|
|
17261
|
-
var value = React__default.useMemo(function () { return (__assign(__assign({}, auth), { defaultConfig: defaultConfig })); }, [auth, defaultConfig]);
|
|
17262
|
-
if (!mounted) {
|
|
17263
|
-
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
17264
|
-
}
|
|
17257
|
+
var msalAuth = useCAMSMSALAuth(msalOptions || { mfaUrl: '/auth/multi-factor' });
|
|
17258
|
+
var value = React__default.useMemo(function () { return (__assign(__assign({}, auth), { defaultConfig: defaultConfig, isAuthenticated: msalAuth.isAuthenticated, idToken: msalAuth.idToken, accessToken: msalAuth.accessToken })); }, [auth, defaultConfig, msalAuth.isAuthenticated, msalAuth.idToken, msalAuth.accessToken]);
|
|
17265
17259
|
return (jsxRuntimeExports.jsx(CAMSContext.Provider, { value: value, children: children }));
|
|
17266
17260
|
}
|
|
17267
17261
|
function useCAMSContext() {
|
|
@@ -17288,10 +17282,48 @@ function ProtectedRoute(_a) {
|
|
|
17288
17282
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
17289
17283
|
}
|
|
17290
17284
|
|
|
17291
|
-
|
|
17292
|
-
|
|
17285
|
+
var CAMSMSALContext = React__default.createContext(null);
|
|
17286
|
+
function CAMSMSALProviderInner(_a) {
|
|
17287
|
+
var children = _a.children, authOptions = __rest(_a, ["children"]);
|
|
17288
|
+
var auth = useCAMSMSALAuth(authOptions);
|
|
17289
|
+
var _b = React__default.useState({
|
|
17290
|
+
isAuthenticated: false,
|
|
17291
|
+
idToken: null,
|
|
17292
|
+
accessToken: null
|
|
17293
|
+
}), persistedAuth = _b[0], setPersistedAuth = _b[1];
|
|
17294
|
+
React__default.useEffect(function () {
|
|
17295
|
+
if (typeof window !== 'undefined') {
|
|
17296
|
+
var stored = localStorage.getItem('cams-msal-auth');
|
|
17297
|
+
if (stored) {
|
|
17298
|
+
setPersistedAuth(JSON.parse(stored));
|
|
17299
|
+
}
|
|
17300
|
+
}
|
|
17301
|
+
}, []);
|
|
17302
|
+
React__default.useEffect(function () {
|
|
17303
|
+
var authState = {
|
|
17304
|
+
isAuthenticated: auth.isAuthenticated,
|
|
17305
|
+
idToken: auth.idToken,
|
|
17306
|
+
accessToken: auth.accessToken
|
|
17307
|
+
};
|
|
17308
|
+
setPersistedAuth(authState);
|
|
17309
|
+
if (typeof window !== 'undefined') {
|
|
17310
|
+
localStorage.setItem('cams-msal-auth', JSON.stringify(authState));
|
|
17311
|
+
}
|
|
17312
|
+
}, [auth.isAuthenticated, auth.idToken, auth.accessToken]);
|
|
17313
|
+
var value = React__default.useMemo(function () { return (__assign(__assign({}, auth), { isAuthenticated: persistedAuth.isAuthenticated, idToken: persistedAuth.idToken, accessToken: persistedAuth.accessToken })); }, [auth, persistedAuth]);
|
|
17314
|
+
return (jsxRuntimeExports.jsx(CAMSMSALContext.Provider, { value: value, children: children }));
|
|
17315
|
+
}
|
|
17316
|
+
function CAMSMSALProvider(props) {
|
|
17317
|
+
var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
|
|
17293
17318
|
var instance = msalInstance || new PublicClientApplication(msalConfig);
|
|
17294
|
-
return (jsxRuntimeExports.jsx(MsalProvider, { instance: instance, children:
|
|
17319
|
+
return (jsxRuntimeExports.jsx(MsalProvider, { instance: instance, children: jsxRuntimeExports.jsx(CAMSMSALProviderInner, __assign({}, props)) }));
|
|
17320
|
+
}
|
|
17321
|
+
function useCAMSMSALContext() {
|
|
17322
|
+
var context = React__default.useContext(CAMSMSALContext);
|
|
17323
|
+
if (!context) {
|
|
17324
|
+
throw new Error('useCAMSMSALContext must be used within a CAMSMSALProvider');
|
|
17325
|
+
}
|
|
17326
|
+
return context;
|
|
17295
17327
|
}
|
|
17296
17328
|
|
|
17297
17329
|
function ClientOnly(_a) {
|
|
@@ -17313,6 +17345,7 @@ exports.ProtectedRoute = ProtectedRoute;
|
|
|
17313
17345
|
exports.useCAMSAuth = useCAMSAuth;
|
|
17314
17346
|
exports.useCAMSContext = useCAMSContext;
|
|
17315
17347
|
exports.useCAMSMSALAuth = useCAMSMSALAuth;
|
|
17348
|
+
exports.useCAMSMSALContext = useCAMSMSALContext;
|
|
17316
17349
|
Object.keys(camsSdk).forEach(function (k) {
|
|
17317
17350
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
17318
17351
|
enumerable: true,
|