@frontegg/redux-store 7.76.0-alpha.0 → 7.76.0-alpha.1
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/ForgotPasswordState/actions.d.ts +2 -1
- package/auth/ForgotPasswordState/actions.js +42 -1
- package/auth/ForgotPasswordState/interfaces.d.ts +8 -1
- package/auth/ForgotPasswordState/interfaces.js +3 -0
- package/auth/ForgotPasswordState/state.js +1 -1
- package/index.js +1 -1
- package/mocks/auth-mocks/forgotPasswordActions.mocks.d.ts +1 -0
- package/node/auth/ForgotPasswordState/actions.js +42 -1
- package/node/auth/ForgotPasswordState/interfaces.js +3 -0
- package/node/auth/ForgotPasswordState/state.js +1 -1
- package/node/index.js +1 -1
- package/package.json +2 -2
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { IGetUserPasswordConfig } from '@frontegg/rest-api';
|
|
2
2
|
import type { FronteggState, RestApi, SharedActions } from '../../interfaces';
|
|
3
|
-
import type { ForgotPasswordState, IForgotPasswordPayload, IResetPasswordPayload } from './interfaces';
|
|
3
|
+
import type { ForgotPasswordState, IForgotPasswordPayload, IResetPasswordPayload, IDeterminePasswordRecoveryStrategyPayload } from './interfaces';
|
|
4
4
|
declare const _default: (store: FronteggState, api: RestApi, sharedActions: SharedActions) => {
|
|
5
5
|
setForgotPasswordState: (payload: Partial<ForgotPasswordState>) => void;
|
|
6
6
|
resetForgotPasswordState: () => void;
|
|
7
7
|
forgotPassword: (payload: IForgotPasswordPayload) => Promise<void>;
|
|
8
8
|
resetPassword: (payload: IResetPasswordPayload) => Promise<void>;
|
|
9
9
|
loadPasswordConfig: (payload?: IGetUserPasswordConfig) => Promise<void>;
|
|
10
|
+
determinePasswordRecoveryStrategy: (payload: IDeterminePasswordRecoveryStrategyPayload) => Promise<void>;
|
|
10
11
|
};
|
|
11
12
|
export default _default;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
2
|
const _excluded = ["callback"];
|
|
3
|
+
import { PasswordRecoveryStrategyEnum } from '@frontegg/rest-api';
|
|
3
4
|
import { ForgotPasswordStep } from './interfaces';
|
|
4
5
|
import { initialState } from './state';
|
|
5
6
|
import { errorHandler, deepResetState } from '../../helpers';
|
|
@@ -33,6 +34,45 @@ export default ((store, api, sharedActions) => {
|
|
|
33
34
|
(_payload$callback2 = payload.callback) == null ? void 0 : _payload$callback2.call(payload, false, e);
|
|
34
35
|
}
|
|
35
36
|
};
|
|
37
|
+
const determinePasswordRecoveryStrategy = async payload => {
|
|
38
|
+
setForgotPasswordState({
|
|
39
|
+
loading: true,
|
|
40
|
+
error: undefined,
|
|
41
|
+
identifier: payload.identifier
|
|
42
|
+
});
|
|
43
|
+
try {
|
|
44
|
+
const strategies = await api.auth.getPasswordRecoveryStrategies();
|
|
45
|
+
const isEmailActive = strategies.some(s => s.strategy === PasswordRecoveryStrategyEnum.Email && s.isActive);
|
|
46
|
+
const isSmsActive = strategies.some(s => s.strategy === PasswordRecoveryStrategyEnum.Sms && s.isActive);
|
|
47
|
+
if (isEmailActive && isSmsActive) {
|
|
48
|
+
setForgotPasswordState({
|
|
49
|
+
loading: false,
|
|
50
|
+
step: ForgotPasswordStep.passwordRecoverySelector
|
|
51
|
+
});
|
|
52
|
+
} else if (isEmailActive) {
|
|
53
|
+
await forgotPassword({
|
|
54
|
+
email: payload.identifier,
|
|
55
|
+
recaptchaToken: payload.recaptchaToken
|
|
56
|
+
});
|
|
57
|
+
} else if (isSmsActive) {
|
|
58
|
+
setForgotPasswordState({
|
|
59
|
+
loading: false,
|
|
60
|
+
step: ForgotPasswordStep.resetPasswordViaSms
|
|
61
|
+
});
|
|
62
|
+
} else {
|
|
63
|
+
const error = 'No active password recovery methods found.';
|
|
64
|
+
setForgotPasswordState({
|
|
65
|
+
loading: false,
|
|
66
|
+
error
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
} catch (e) {
|
|
70
|
+
setForgotPasswordState({
|
|
71
|
+
loading: false,
|
|
72
|
+
error: errorHandler(e, 'An error occurred while determining recovery strategy')
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
};
|
|
36
76
|
const resetPassword = async payload => {
|
|
37
77
|
const {
|
|
38
78
|
callback
|
|
@@ -79,6 +119,7 @@ export default ((store, api, sharedActions) => {
|
|
|
79
119
|
resetForgotPasswordState,
|
|
80
120
|
forgotPassword,
|
|
81
121
|
resetPassword,
|
|
82
|
-
loadPasswordConfig
|
|
122
|
+
loadPasswordConfig,
|
|
123
|
+
determinePasswordRecoveryStrategy
|
|
83
124
|
};
|
|
84
125
|
});
|
|
@@ -2,6 +2,9 @@ import type { IForgotPassword, IResetPassword } from '@frontegg/rest-api';
|
|
|
2
2
|
import type { WithCallback } from '../../interfaces';
|
|
3
3
|
export declare enum ForgotPasswordStep {
|
|
4
4
|
'forgotPassword' = "forgotPassword",
|
|
5
|
+
'resetPasswordViaSms' = "resetPasswordViaSms",
|
|
6
|
+
'passwordRecoverySelector' = "passwordRecoverySelector",
|
|
7
|
+
'resetPasswordPage' = "resetPasswordPage",
|
|
5
8
|
'success' = "success"
|
|
6
9
|
}
|
|
7
10
|
export interface TestConfig {
|
|
@@ -14,7 +17,7 @@ export interface TestConfig {
|
|
|
14
17
|
export interface ForgotPasswordState {
|
|
15
18
|
step: ForgotPasswordStep;
|
|
16
19
|
passwordConfig: Partial<TestConfig> | null;
|
|
17
|
-
|
|
20
|
+
identifier: string;
|
|
18
21
|
loading: boolean;
|
|
19
22
|
error?: any;
|
|
20
23
|
}
|
|
@@ -24,3 +27,7 @@ export interface IForgotPasswordPayload extends WithCallback<IForgotPassword> {
|
|
|
24
27
|
export interface IResetPasswordPayload extends WithCallback<IResetPassword> {
|
|
25
28
|
recaptchaToken?: string;
|
|
26
29
|
}
|
|
30
|
+
export interface IDeterminePasswordRecoveryStrategyPayload {
|
|
31
|
+
identifier: string;
|
|
32
|
+
recaptchaToken?: string;
|
|
33
|
+
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export let ForgotPasswordStep;
|
|
2
2
|
(function (ForgotPasswordStep) {
|
|
3
3
|
ForgotPasswordStep["forgotPassword"] = "forgotPassword";
|
|
4
|
+
ForgotPasswordStep["resetPasswordViaSms"] = "resetPasswordViaSms";
|
|
5
|
+
ForgotPasswordStep["passwordRecoverySelector"] = "passwordRecoverySelector";
|
|
6
|
+
ForgotPasswordStep["resetPasswordPage"] = "resetPasswordPage";
|
|
4
7
|
ForgotPasswordStep["success"] = "success";
|
|
5
8
|
})(ForgotPasswordStep || (ForgotPasswordStep = {}));
|
|
@@ -3,7 +3,7 @@ import { createProxy } from '../../toolkit/proxy';
|
|
|
3
3
|
export const initialState = {
|
|
4
4
|
step: ForgotPasswordStep.forgotPassword,
|
|
5
5
|
loading: false,
|
|
6
|
-
|
|
6
|
+
identifier: '',
|
|
7
7
|
passwordConfig: null
|
|
8
8
|
};
|
|
9
9
|
export default (overrideState => createProxy(initialState, overrideState));
|
package/index.js
CHANGED
|
@@ -6,5 +6,6 @@ declare const _default: (store: FronteggState, api: RestApi, actions: SharedActi
|
|
|
6
6
|
forgotPassword: (payload: import("../..").IForgotPasswordPayload) => Promise<void>;
|
|
7
7
|
resetPassword: (payload: import("../..").IResetPasswordPayload) => Promise<void>;
|
|
8
8
|
loadPasswordConfig: (payload?: IGetUserPasswordConfig) => Promise<void>;
|
|
9
|
+
determinePasswordRecoveryStrategy: (payload: import("../..").IDeterminePasswordRecoveryStrategyPayload) => Promise<void>;
|
|
9
10
|
};
|
|
10
11
|
export default _default;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
9
|
+
var _restApi = require("@frontegg/rest-api");
|
|
9
10
|
var _interfaces = require("./interfaces");
|
|
10
11
|
var _state = require("./state");
|
|
11
12
|
var _helpers = require("../../helpers");
|
|
@@ -40,6 +41,45 @@ var _default = (store, api, sharedActions) => {
|
|
|
40
41
|
(_payload$callback2 = payload.callback) == null ? void 0 : _payload$callback2.call(payload, false, e);
|
|
41
42
|
}
|
|
42
43
|
};
|
|
44
|
+
const determinePasswordRecoveryStrategy = async payload => {
|
|
45
|
+
setForgotPasswordState({
|
|
46
|
+
loading: true,
|
|
47
|
+
error: undefined,
|
|
48
|
+
identifier: payload.identifier
|
|
49
|
+
});
|
|
50
|
+
try {
|
|
51
|
+
const strategies = await api.auth.getPasswordRecoveryStrategies();
|
|
52
|
+
const isEmailActive = strategies.some(s => s.strategy === _restApi.PasswordRecoveryStrategyEnum.Email && s.isActive);
|
|
53
|
+
const isSmsActive = strategies.some(s => s.strategy === _restApi.PasswordRecoveryStrategyEnum.Sms && s.isActive);
|
|
54
|
+
if (isEmailActive && isSmsActive) {
|
|
55
|
+
setForgotPasswordState({
|
|
56
|
+
loading: false,
|
|
57
|
+
step: _interfaces.ForgotPasswordStep.passwordRecoverySelector
|
|
58
|
+
});
|
|
59
|
+
} else if (isEmailActive) {
|
|
60
|
+
await forgotPassword({
|
|
61
|
+
email: payload.identifier,
|
|
62
|
+
recaptchaToken: payload.recaptchaToken
|
|
63
|
+
});
|
|
64
|
+
} else if (isSmsActive) {
|
|
65
|
+
setForgotPasswordState({
|
|
66
|
+
loading: false,
|
|
67
|
+
step: _interfaces.ForgotPasswordStep.resetPasswordViaSms
|
|
68
|
+
});
|
|
69
|
+
} else {
|
|
70
|
+
const error = 'No active password recovery methods found.';
|
|
71
|
+
setForgotPasswordState({
|
|
72
|
+
loading: false,
|
|
73
|
+
error
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
} catch (e) {
|
|
77
|
+
setForgotPasswordState({
|
|
78
|
+
loading: false,
|
|
79
|
+
error: (0, _helpers.errorHandler)(e, 'An error occurred while determining recovery strategy')
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
43
83
|
const resetPassword = async payload => {
|
|
44
84
|
const {
|
|
45
85
|
callback
|
|
@@ -86,7 +126,8 @@ var _default = (store, api, sharedActions) => {
|
|
|
86
126
|
resetForgotPasswordState,
|
|
87
127
|
forgotPassword,
|
|
88
128
|
resetPassword,
|
|
89
|
-
loadPasswordConfig
|
|
129
|
+
loadPasswordConfig,
|
|
130
|
+
determinePasswordRecoveryStrategy
|
|
90
131
|
};
|
|
91
132
|
};
|
|
92
133
|
exports.default = _default;
|
|
@@ -8,5 +8,8 @@ let ForgotPasswordStep;
|
|
|
8
8
|
exports.ForgotPasswordStep = ForgotPasswordStep;
|
|
9
9
|
(function (ForgotPasswordStep) {
|
|
10
10
|
ForgotPasswordStep["forgotPassword"] = "forgotPassword";
|
|
11
|
+
ForgotPasswordStep["resetPasswordViaSms"] = "resetPasswordViaSms";
|
|
12
|
+
ForgotPasswordStep["passwordRecoverySelector"] = "passwordRecoverySelector";
|
|
13
|
+
ForgotPasswordStep["resetPasswordPage"] = "resetPasswordPage";
|
|
11
14
|
ForgotPasswordStep["success"] = "success";
|
|
12
15
|
})(ForgotPasswordStep || (exports.ForgotPasswordStep = ForgotPasswordStep = {}));
|
package/node/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontegg/redux-store",
|
|
3
|
-
"version": "7.76.0-alpha.
|
|
3
|
+
"version": "7.76.0-alpha.1",
|
|
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
9
|
"@frontegg/entitlements-javascript-commons": "1.1.2",
|
|
10
|
-
"@frontegg/rest-api": "7.76.0-alpha.
|
|
10
|
+
"@frontegg/rest-api": "7.76.0-alpha.1",
|
|
11
11
|
"fast-deep-equal": "3.1.3",
|
|
12
12
|
"get-value": "^3.0.1",
|
|
13
13
|
"proxy-compare": "^3.0.0",
|