@frontegg/react-hooks 6.161.0 → 6.162.0-alpha.0

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/auth/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export * from './apiTokens';
5
5
  export * from './forgotPassword';
6
6
  export * from './resetPhoneNumber';
7
7
  export * from './login';
8
+ export * from './stepUp';
8
9
  export * from './mfa';
9
10
  export * from './profile';
10
11
  export * from './signup';
package/auth/index.js CHANGED
@@ -5,6 +5,7 @@ export * from './apiTokens';
5
5
  export * from './forgotPassword';
6
6
  export * from './resetPhoneNumber';
7
7
  export * from './login';
8
+ export * from './stepUp';
8
9
  export * from './mfa';
9
10
  export * from './profile';
10
11
  export * from './signup';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * The name of the query param that contains the max age of the step up
3
+ */
4
+ export declare const STEP_UP_MAX_AGE_PARAM_NAME = "maxAge";
@@ -0,0 +1,4 @@
1
+ /**
2
+ * The name of the query param that contains the max age of the step up
3
+ */
4
+ export const STEP_UP_MAX_AGE_PARAM_NAME = 'maxAge';
@@ -0,0 +1,2 @@
1
+ export * from './stepUp';
2
+ export * from './interfaces';
@@ -0,0 +1,2 @@
1
+ export * from './stepUp';
2
+ export * from './interfaces';
@@ -0,0 +1,14 @@
1
+ import { StepUpState } from '@frontegg/redux-store';
2
+ export declare type StepUpStateMapper<S> = (state: StepUpState) => S;
3
+ /**
4
+ * Step up options (for stepUp function)
5
+ */
6
+ export interface StepUpOptions {
7
+ maxAge?: number;
8
+ }
9
+ /**
10
+ * useIsSteppedUp hook options
11
+ */
12
+ export interface UseIsSteppedUpOptions {
13
+ maxAge?: number;
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ import { StepUpState, StepUpActions } from '@frontegg/redux-store';
2
+ import { RedirectOptions } from '@frontegg/rest-api';
3
+ import { StepUpStateMapper, UseIsSteppedUpOptions } from './interfaces';
4
+ export declare function useStepUpState(): StepUpState;
5
+ export declare function useStepUpState<S>(stateMapper: StepUpStateMapper<S>): S;
6
+ export declare const useStepUpActions: () => StepUpActions;
7
+ /**
8
+ * Redirects to the step up url with the max age param and set the redirect url in the local storage
9
+ * The redirect url will be used after the step up flow is done
10
+ * @param stepUpUrl - step up url to redirect to
11
+ * @param onRedirectTo - redirect to function
12
+ * @param maxAge - max age of step up
13
+ */
14
+ export declare const redirectByStepUpUrl: (stepUpUrl: string, onRedirectTo: (path: string, opts?: RedirectOptions | undefined) => void, maxAge?: number | undefined) => void;
15
+ /**
16
+ * @returns max age from the query param as a number or null if not exists
17
+ */
18
+ export declare const getMaxAgeFromQueryParam: () => number | undefined;
19
+ /**
20
+ * @returns step up function that redirects to the step up url with the max age param and set the redirect url in the local storage
21
+ */
22
+ export declare const useStepUp: () => any;
23
+ /**
24
+ * @param options.maxAge - max age of step up
25
+ * @returns true when the user is stepped up, false otherwise
26
+ */
27
+ export declare const useIsSteppedUp: ({ maxAge }?: UseIsSteppedUpOptions) => boolean;
@@ -0,0 +1,66 @@
1
+ import { FRONTEGG_AFTER_AUTH_REDIRECT_URL, stepUpReducers, stepUpActions, getSearchParam, isSteppedUp } from '@frontegg/redux-store';
2
+ import { reducerActionsGenerator, stateHookGenerator, useAuthRoutes, useAuthUser, useOnRedirectTo } from '../hooks';
3
+ import { useCallback } from 'react';
4
+ import { STEP_UP_MAX_AGE_PARAM_NAME } from './consts';
5
+ const defaultMapper = state => state;
6
+ export function useStepUpState(stateMapper = defaultMapper) {
7
+ return stateHookGenerator(stateMapper, 'stepUpState');
8
+ }
9
+ export const useStepUpActions = () => reducerActionsGenerator(stepUpActions, stepUpReducers);
10
+
11
+ /**
12
+ * Redirects to the step up url with the max age param and set the redirect url in the local storage
13
+ * The redirect url will be used after the step up flow is done
14
+ * @param stepUpUrl - step up url to redirect to
15
+ * @param onRedirectTo - redirect to function
16
+ * @param maxAge - max age of step up
17
+ */
18
+ export const redirectByStepUpUrl = (stepUpUrl, onRedirectTo, maxAge) => {
19
+ const encodedRedirectUrl = window.location.pathname + window.location.search;
20
+ const maxAgePart = maxAge !== undefined ? `?${STEP_UP_MAX_AGE_PARAM_NAME}=${maxAge}` : '';
21
+ window.localStorage.setItem(FRONTEGG_AFTER_AUTH_REDIRECT_URL, encodedRedirectUrl);
22
+ onRedirectTo(`${stepUpUrl}${maxAgePart}`, {
23
+ refresh: false
24
+ });
25
+ };
26
+
27
+ /**
28
+ * @returns max age from the query param as a number or null if not exists
29
+ */
30
+ export const getMaxAgeFromQueryParam = () => {
31
+ const str = getSearchParam(STEP_UP_MAX_AGE_PARAM_NAME);
32
+ return str === undefined ? undefined : +str;
33
+ };
34
+
35
+ /**
36
+ * @returns step up function that redirects to the step up url with the max age param and set the redirect url in the local storage
37
+ */
38
+ export const useStepUp = () => {
39
+ const {
40
+ stepUpUrl
41
+ } = useAuthRoutes();
42
+ const onRedirectTo = useOnRedirectTo();
43
+ return useCallback(options => {
44
+ redirectByStepUpUrl(stepUpUrl, onRedirectTo, options == null ? void 0 : options.maxAge);
45
+ }, [stepUpUrl, onRedirectTo]);
46
+ };
47
+
48
+ /**
49
+ * @param options.maxAge - max age of step up
50
+ * @returns true when the user is stepped up, false otherwise
51
+ */
52
+ export const useIsSteppedUp = ({
53
+ maxAge
54
+ } = {}) => {
55
+ const {
56
+ amr = [],
57
+ acr = '',
58
+ auth_time
59
+ } = useAuthUser();
60
+ return isSteppedUp({
61
+ amr,
62
+ acr,
63
+ auth_time,
64
+ maxAge
65
+ });
66
+ };
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.161.0
1
+ /** @license Frontegg v6.162.0-alpha.0
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
@@ -141,6 +141,18 @@ Object.keys(_login).forEach(function (key) {
141
141
  }
142
142
  });
143
143
  });
144
+ var _stepUp = require("./stepUp");
145
+ Object.keys(_stepUp).forEach(function (key) {
146
+ if (key === "default" || key === "__esModule") return;
147
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
148
+ if (key in exports && exports[key] === _stepUp[key]) return;
149
+ Object.defineProperty(exports, key, {
150
+ enumerable: true,
151
+ get: function () {
152
+ return _stepUp[key];
153
+ }
154
+ });
155
+ });
144
156
  var _mfa = require("./mfa");
145
157
  Object.keys(_mfa).forEach(function (key) {
146
158
  if (key === "default" || key === "__esModule") return;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.STEP_UP_MAX_AGE_PARAM_NAME = void 0;
7
+ /**
8
+ * The name of the query param that contains the max age of the step up
9
+ */
10
+ const STEP_UP_MAX_AGE_PARAM_NAME = 'maxAge';
11
+ exports.STEP_UP_MAX_AGE_PARAM_NAME = STEP_UP_MAX_AGE_PARAM_NAME;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _stepUp = require("./stepUp");
7
+ Object.keys(_stepUp).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _stepUp[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _stepUp[key];
14
+ }
15
+ });
16
+ });
17
+ var _interfaces = require("./interfaces");
18
+ Object.keys(_interfaces).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _interfaces[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _interfaces[key];
25
+ }
26
+ });
27
+ });
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useStepUpActions = exports.useStepUp = exports.useIsSteppedUp = exports.redirectByStepUpUrl = exports.getMaxAgeFromQueryParam = void 0;
7
+ exports.useStepUpState = useStepUpState;
8
+ var _reduxStore = require("@frontegg/redux-store");
9
+ var _hooks = require("../hooks");
10
+ var _react = require("react");
11
+ var _consts = require("./consts");
12
+ const defaultMapper = state => state;
13
+ function useStepUpState(stateMapper = defaultMapper) {
14
+ return (0, _hooks.stateHookGenerator)(stateMapper, 'stepUpState');
15
+ }
16
+ const useStepUpActions = () => (0, _hooks.reducerActionsGenerator)(_reduxStore.stepUpActions, _reduxStore.stepUpReducers);
17
+
18
+ /**
19
+ * Redirects to the step up url with the max age param and set the redirect url in the local storage
20
+ * The redirect url will be used after the step up flow is done
21
+ * @param stepUpUrl - step up url to redirect to
22
+ * @param onRedirectTo - redirect to function
23
+ * @param maxAge - max age of step up
24
+ */
25
+ exports.useStepUpActions = useStepUpActions;
26
+ const redirectByStepUpUrl = (stepUpUrl, onRedirectTo, maxAge) => {
27
+ const encodedRedirectUrl = window.location.pathname + window.location.search;
28
+ const maxAgePart = maxAge !== undefined ? `?${_consts.STEP_UP_MAX_AGE_PARAM_NAME}=${maxAge}` : '';
29
+ window.localStorage.setItem(_reduxStore.FRONTEGG_AFTER_AUTH_REDIRECT_URL, encodedRedirectUrl);
30
+ onRedirectTo(`${stepUpUrl}${maxAgePart}`, {
31
+ refresh: false
32
+ });
33
+ };
34
+
35
+ /**
36
+ * @returns max age from the query param as a number or null if not exists
37
+ */
38
+ exports.redirectByStepUpUrl = redirectByStepUpUrl;
39
+ const getMaxAgeFromQueryParam = () => {
40
+ const str = (0, _reduxStore.getSearchParam)(_consts.STEP_UP_MAX_AGE_PARAM_NAME);
41
+ return str === undefined ? undefined : +str;
42
+ };
43
+
44
+ /**
45
+ * @returns step up function that redirects to the step up url with the max age param and set the redirect url in the local storage
46
+ */
47
+ exports.getMaxAgeFromQueryParam = getMaxAgeFromQueryParam;
48
+ const useStepUp = () => {
49
+ const {
50
+ stepUpUrl
51
+ } = (0, _hooks.useAuthRoutes)();
52
+ const onRedirectTo = (0, _hooks.useOnRedirectTo)();
53
+ return (0, _react.useCallback)(options => {
54
+ redirectByStepUpUrl(stepUpUrl, onRedirectTo, options == null ? void 0 : options.maxAge);
55
+ }, [stepUpUrl, onRedirectTo]);
56
+ };
57
+
58
+ /**
59
+ * @param options.maxAge - max age of step up
60
+ * @returns true when the user is stepped up, false otherwise
61
+ */
62
+ exports.useStepUp = useStepUp;
63
+ const useIsSteppedUp = ({
64
+ maxAge
65
+ } = {}) => {
66
+ const {
67
+ amr = [],
68
+ acr = '',
69
+ auth_time
70
+ } = (0, _hooks.useAuthUser)();
71
+ return (0, _reduxStore.isSteppedUp)({
72
+ amr,
73
+ acr,
74
+ auth_time,
75
+ maxAge
76
+ });
77
+ };
78
+ exports.useIsSteppedUp = useIsSteppedUp;
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.161.0
1
+ /** @license Frontegg v6.162.0-alpha.0
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@frontegg/react-hooks",
3
- "version": "6.161.0",
3
+ "version": "6.162.0-alpha.0",
4
4
  "main": "./node/index.js",
5
5
  "license": "MIT",
6
6
  "author": "Frontegg LTD",
7
7
  "dependencies": {
8
8
  "@babel/runtime": "^7.18.6",
9
- "@frontegg/redux-store": "6.161.0",
10
- "@frontegg/types": "6.161.0",
9
+ "@frontegg/redux-store": "6.162.0-alpha.0",
10
+ "@frontegg/types": "6.162.0-alpha.0",
11
11
  "@types/react": "*",
12
12
  "get-value": "^3.0.1",
13
13
  "react-redux": "^7.x"