@aws-amplify/ui-react-core 0.0.0-studio-e5b8195-20230912200241 → 0.0.0-studio-console-80bb2e2-20230921222703
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/esm/Authenticator/context/{AuthenticatorProvider.js → AuthenticatorProvider.mjs} +4 -5
- package/dist/esm/Authenticator/hooks/useAuthenticator/{useAuthenticator.js → useAuthenticator.mjs} +12 -8
- package/dist/esm/Authenticator/hooks/useAuthenticator/{utils.js → utils.mjs} +7 -11
- package/dist/esm/Authenticator/hooks/useAuthenticatorInitMachine/{useAuthenticatorInitMachine.js → useAuthenticatorInitMachine.mjs} +1 -1
- package/dist/esm/Authenticator/hooks/useAuthenticatorRoute/{useAuthenticatorRoute.js → useAuthenticatorRoute.mjs} +2 -2
- package/dist/esm/Authenticator/hooks/useAuthenticatorRoute/{utils.js → utils.mjs} +43 -16
- package/dist/esm/Authenticator/hooks/{utils.js → utils.mjs} +3 -3
- package/dist/esm/hooks/{useHasValueUpdated.js → useHasValueUpdated.mjs} +1 -1
- package/dist/esm/{index.js → index.mjs} +10 -10
- package/dist/index.js +60 -67
- package/package.json +6 -6
- package/dist/esm/node_modules/tslib/tslib.es6.js +0 -38
- /package/dist/esm/Authenticator/context/{AuthenticatorContext.js → AuthenticatorContext.mjs} +0 -0
- /package/dist/esm/Authenticator/hooks/{constants.js → constants.mjs} +0 -0
- /package/dist/esm/Authenticator/hooks/useAuthenticator/{constants.js → constants.mjs} +0 -0
- /package/dist/esm/Authenticator/hooks/useAuthenticatorRoute/{constants.js → constants.mjs} +0 -0
- /package/dist/esm/components/RenderNothing/{RenderNothing.js → RenderNothing.mjs} +0 -0
- /package/dist/esm/hooks/{useDeprecationWarning.js → useDeprecationWarning.mjs} +0 -0
- /package/dist/esm/hooks/{usePreviousValue.js → usePreviousValue.mjs} +0 -0
package/dist/esm/Authenticator/context/{AuthenticatorProvider.js → AuthenticatorProvider.mjs}
RENAMED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { __awaiter } from '../../node_modules/tslib/tslib.es6.js';
|
|
2
1
|
import React__default, { useContext, useMemo, useEffect } from 'react';
|
|
3
2
|
import { useInterpret } from '@xstate/react';
|
|
4
3
|
import { Auth } from 'aws-amplify';
|
|
5
4
|
import { createAuthenticatorMachine, listenToAuthHub, defaultAuthHubHandler } from '@aws-amplify/ui';
|
|
6
|
-
import { AuthenticatorContext } from './AuthenticatorContext.
|
|
5
|
+
import { AuthenticatorContext } from './AuthenticatorContext.mjs';
|
|
7
6
|
|
|
8
|
-
const createHubHandler = (options) => (data, service) =>
|
|
9
|
-
|
|
10
|
-
}
|
|
7
|
+
const createHubHandler = (options) => async (data, service) => {
|
|
8
|
+
await defaultAuthHubHandler(data, service, options);
|
|
9
|
+
};
|
|
11
10
|
function AuthenticatorProvider({ children, }) {
|
|
12
11
|
// `authStatus` is exposed by `useAuthenticator` but should not be derived directly from the
|
|
13
12
|
// state machine as the machine only updates on `Authenticator` initiated events, which
|
package/dist/esm/Authenticator/hooks/useAuthenticator/{useAuthenticator.js → useAuthenticator.mjs}
RENAMED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { __rest } from '../../../node_modules/tslib/tslib.es6.js';
|
|
2
1
|
import React__default, { useCallback } from 'react';
|
|
3
2
|
import { useSelector } from '@xstate/react';
|
|
4
3
|
import { getServiceFacade } from '@aws-amplify/ui';
|
|
5
4
|
import 'aws-amplify';
|
|
6
|
-
import { AuthenticatorContext } from '../../context/AuthenticatorContext.
|
|
7
|
-
import { USE_AUTHENTICATOR_ERROR } from './constants.
|
|
8
|
-
import { getQRFields, getMachineFields, getTotpSecretCodeCallback, getComparator, defaultComparator } from './utils.
|
|
5
|
+
import { AuthenticatorContext } from '../../context/AuthenticatorContext.mjs';
|
|
6
|
+
import { USE_AUTHENTICATOR_ERROR } from './constants.mjs';
|
|
7
|
+
import { getQRFields, getMachineFields, getTotpSecretCodeCallback, getComparator, defaultComparator } from './utils.mjs';
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* [📖 Docs](https://ui.docs.amplify.aws/react/connected-components/authenticator/headless#useauthenticator-hook)
|
|
@@ -17,13 +16,13 @@ function useAuthenticator(selector) {
|
|
|
17
16
|
}
|
|
18
17
|
const { service } = context;
|
|
19
18
|
const { send } = service;
|
|
20
|
-
const xstateSelector = useCallback((state) => (
|
|
19
|
+
const xstateSelector = useCallback((state) => ({ ...getServiceFacade({ send, state }) }), [send]);
|
|
21
20
|
const comparator = selector ? getComparator(selector) : defaultComparator;
|
|
22
21
|
// the purpose of `context.authStatus`is to intentionally override `facade.authStatus`. `facade.authStatus` does
|
|
23
22
|
// not update on external sign in events (for example when a user is not using the `Authenticator`).
|
|
24
23
|
const { authStatus } = context;
|
|
25
24
|
const facade = useSelector(service, xstateSelector, comparator);
|
|
26
|
-
const { route, totpSecretCode, unverifiedContactMethods, user
|
|
25
|
+
const { route, totpSecretCode, unverifiedContactMethods, user, ...rest } = facade;
|
|
27
26
|
// do not memoize output. `service.getSnapshot` reference remains stable preventing
|
|
28
27
|
// `fields` from updating with current form state on value changes
|
|
29
28
|
const serviceSnapshot = service.getSnapshot();
|
|
@@ -31,13 +30,18 @@ function useAuthenticator(selector) {
|
|
|
31
30
|
const QRFields = route === 'setupTOTP' ? getQRFields(serviceSnapshot) : null;
|
|
32
31
|
// legacy `formFields` values required until form state is removed from state machine
|
|
33
32
|
const fields = getMachineFields(route, serviceSnapshot, unverifiedContactMethods);
|
|
34
|
-
return
|
|
33
|
+
return {
|
|
34
|
+
...rest,
|
|
35
|
+
authStatus,
|
|
35
36
|
route,
|
|
36
37
|
totpSecretCode,
|
|
37
38
|
unverifiedContactMethods,
|
|
38
39
|
user,
|
|
39
40
|
/** @deprecated For internal use only */
|
|
40
|
-
fields,
|
|
41
|
+
fields,
|
|
42
|
+
getTotpSecretCode: getTotpSecretCodeCallback(user),
|
|
43
|
+
QRFields,
|
|
44
|
+
};
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
export { useAuthenticator as default };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { __awaiter } from '../../../node_modules/tslib/tslib.es6.js';
|
|
2
1
|
import { Auth } from 'aws-amplify';
|
|
3
2
|
import { getActorContext, getSortedFormFields, isString, areEmptyArrays, areEmptyObjects } from '@aws-amplify/ui';
|
|
4
|
-
import { isComponentRouteKey } from '../utils.
|
|
3
|
+
import { isComponentRouteKey } from '../utils.mjs';
|
|
5
4
|
|
|
6
5
|
const defaultComparator = () => false;
|
|
7
6
|
/**
|
|
@@ -27,16 +26,13 @@ const getComparator = (selector) => (currentFacade, nextFacade) => {
|
|
|
27
26
|
// Shallow compare the array values
|
|
28
27
|
return areSelectorDepsEqual(currentSelectorDeps, nextSelectorDeps);
|
|
29
28
|
};
|
|
30
|
-
const getQRFields = (state) => {
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
const getQRFields = (state) => ({
|
|
30
|
+
...getActorContext(state)?.formFields?.setupTOTP?.QR,
|
|
31
|
+
});
|
|
32
|
+
const getTotpSecretCodeCallback = (user) => async function getTotpSecretCode() {
|
|
33
|
+
return await Auth.setupTOTP(user);
|
|
33
34
|
};
|
|
34
|
-
const
|
|
35
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
return yield Auth.setupTOTP(user);
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
const flattenFormFields = (fields) => fields.flatMap(([name, options]) => (Object.assign({ name }, options)));
|
|
35
|
+
const flattenFormFields = (fields) => fields.flatMap(([name, options]) => ({ name, ...options }));
|
|
40
36
|
const convertContactMethodsToFields = (unverifiedContactMethods) => {
|
|
41
37
|
return (unverifiedContactMethods &&
|
|
42
38
|
Object.entries(unverifiedContactMethods).map(([name, value]) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React__default from 'react';
|
|
2
|
-
import useAuthenticator from '../useAuthenticator/useAuthenticator.
|
|
2
|
+
import useAuthenticator from '../useAuthenticator/useAuthenticator.mjs';
|
|
3
3
|
|
|
4
4
|
// only select `route` from machine context
|
|
5
5
|
const routeSelector = ({ route }) => [route];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
|
-
import useAuthenticator from '../useAuthenticator/useAuthenticator.
|
|
3
|
-
import { getRouteMachineSelector, resolveDefault, resolveVerifyUserRoute, resolveSignUpRoute, resolveSignInRoute, resolveSetupTOTPRoute, resolveResetPasswordRoute, resolveForceNewPasswordRoute, resolveConfirmVerifyUserRoute, resolveConfirmSignUpRoute, resolveConfirmSignInRoute, resolveConfirmResetPasswordRoute, routeSelector } from './utils.
|
|
2
|
+
import useAuthenticator from '../useAuthenticator/useAuthenticator.mjs';
|
|
3
|
+
import { getRouteMachineSelector, resolveDefault, resolveVerifyUserRoute, resolveSignUpRoute, resolveSignInRoute, resolveSetupTOTPRoute, resolveResetPasswordRoute, resolveForceNewPasswordRoute, resolveConfirmVerifyUserRoute, resolveConfirmSignUpRoute, resolveConfirmSignInRoute, resolveConfirmResetPasswordRoute, routeSelector } from './utils.mjs';
|
|
4
4
|
|
|
5
5
|
function useAuthenticatorRoute({ components, }) {
|
|
6
6
|
const { route } = useAuthenticator(routeSelector);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { MACHINE_PROP_KEYS, EVENT_HANDLER_KEY_MAP } from './constants.js';
|
|
1
|
+
import RenderNothing from '../../../components/RenderNothing/RenderNothing.mjs';
|
|
2
|
+
import { isComponentRouteKey } from '../utils.mjs';
|
|
3
|
+
import { MACHINE_PROP_KEYS, EVENT_HANDLER_KEY_MAP } from './constants.mjs';
|
|
5
4
|
|
|
6
5
|
// only select `route` from machine context
|
|
7
6
|
const routeSelector = ({ route }) => [route];
|
|
@@ -15,47 +14,68 @@ const getRouteMachineSelector = (route) => isComponentRouteKey(route)
|
|
|
15
14
|
: routeSelector;
|
|
16
15
|
const isFormEventHandlerKey = (key) => ['updateBlur', 'updateForm', 'submitForm'].includes(key);
|
|
17
16
|
const convertEventHandlerKey = (key) => EVENT_HANDLER_KEY_MAP[key];
|
|
18
|
-
const getConvertedMachineProps = (route, context) => MACHINE_PROP_KEYS[route].reduce((acc, key) => (
|
|
17
|
+
const getConvertedMachineProps = (route, context) => MACHINE_PROP_KEYS[route].reduce((acc, key) => ({
|
|
18
|
+
...acc,
|
|
19
|
+
[isFormEventHandlerKey(key) ? convertEventHandlerKey(key) : key]: context[key],
|
|
20
|
+
}), {});
|
|
19
21
|
function resolveConfirmResetPasswordRoute(Component, props) {
|
|
20
22
|
return {
|
|
21
23
|
Component,
|
|
22
|
-
props:
|
|
24
|
+
props: {
|
|
25
|
+
...Component,
|
|
26
|
+
...getConvertedMachineProps('confirmResetPassword', props),
|
|
27
|
+
},
|
|
23
28
|
};
|
|
24
29
|
}
|
|
25
30
|
function resolveConfirmSignInRoute(Component, props) {
|
|
26
|
-
const
|
|
31
|
+
const { user, ...machineProps } = getConvertedMachineProps('confirmSignIn', props);
|
|
27
32
|
// prior to the `confirmSignIn` route, `user.username` is populated
|
|
28
33
|
const challengeName = user.challengeName;
|
|
29
|
-
return { Component, props:
|
|
34
|
+
return { Component, props: { ...Component, ...machineProps, challengeName } };
|
|
30
35
|
}
|
|
31
36
|
function resolveConfirmSignUpRoute(Component, props) {
|
|
32
37
|
return {
|
|
33
38
|
Component,
|
|
34
|
-
props:
|
|
39
|
+
props: {
|
|
40
|
+
...Component,
|
|
41
|
+
...getConvertedMachineProps('confirmSignUp', props),
|
|
42
|
+
},
|
|
35
43
|
};
|
|
36
44
|
}
|
|
37
45
|
function resolveConfirmVerifyUserRoute(Component, props) {
|
|
38
46
|
return {
|
|
39
47
|
Component,
|
|
40
|
-
props:
|
|
48
|
+
props: {
|
|
49
|
+
...Component,
|
|
50
|
+
...getConvertedMachineProps('confirmVerifyUser', props),
|
|
51
|
+
},
|
|
41
52
|
};
|
|
42
53
|
}
|
|
43
54
|
function resolveForceNewPasswordRoute(Component, props) {
|
|
44
55
|
return {
|
|
45
56
|
Component,
|
|
46
|
-
props:
|
|
57
|
+
props: {
|
|
58
|
+
...Component,
|
|
59
|
+
...getConvertedMachineProps('forceNewPassword', props),
|
|
60
|
+
},
|
|
47
61
|
};
|
|
48
62
|
}
|
|
49
63
|
function resolveResetPasswordRoute(Component, props) {
|
|
50
64
|
return {
|
|
51
65
|
Component,
|
|
52
|
-
props:
|
|
66
|
+
props: {
|
|
67
|
+
...Component,
|
|
68
|
+
...getConvertedMachineProps('resetPassword', props),
|
|
69
|
+
},
|
|
53
70
|
};
|
|
54
71
|
}
|
|
55
72
|
function resolveSetupTOTPRoute(Component, props) {
|
|
56
73
|
return {
|
|
57
74
|
Component,
|
|
58
|
-
props:
|
|
75
|
+
props: {
|
|
76
|
+
...Component,
|
|
77
|
+
...getConvertedMachineProps('setupTOTP', props),
|
|
78
|
+
},
|
|
59
79
|
};
|
|
60
80
|
}
|
|
61
81
|
function resolveSignInRoute(Component, props) {
|
|
@@ -63,19 +83,26 @@ function resolveSignInRoute(Component, props) {
|
|
|
63
83
|
const hideSignUp = false;
|
|
64
84
|
return {
|
|
65
85
|
Component,
|
|
66
|
-
props:
|
|
86
|
+
props: {
|
|
87
|
+
...Component,
|
|
88
|
+
...getConvertedMachineProps('signIn', props),
|
|
89
|
+
hideSignUp,
|
|
90
|
+
},
|
|
67
91
|
};
|
|
68
92
|
}
|
|
69
93
|
function resolveSignUpRoute(Component, props) {
|
|
70
94
|
return {
|
|
71
95
|
Component,
|
|
72
|
-
props:
|
|
96
|
+
props: { ...Component, ...getConvertedMachineProps('signUp', props) },
|
|
73
97
|
};
|
|
74
98
|
}
|
|
75
99
|
function resolveVerifyUserRoute(Component, props) {
|
|
76
100
|
return {
|
|
77
101
|
Component,
|
|
78
|
-
props:
|
|
102
|
+
props: {
|
|
103
|
+
...Component,
|
|
104
|
+
...getConvertedMachineProps('verifyUser', props),
|
|
105
|
+
},
|
|
79
106
|
};
|
|
80
107
|
}
|
|
81
108
|
function resolveDefault() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { COMPONENT_ROUTE_KEYS, COMPONENT_ROUTE_NAMES } from './constants.
|
|
1
|
+
import { COMPONENT_ROUTE_KEYS, COMPONENT_ROUTE_NAMES } from './constants.mjs';
|
|
2
2
|
|
|
3
3
|
const isComponentRouteKey = (route) => COMPONENT_ROUTE_KEYS.some((componentRoute) => componentRoute === route);
|
|
4
4
|
function resolveAuthenticatorComponents(defaults, overrides) {
|
|
@@ -9,7 +9,7 @@ function resolveAuthenticatorComponents(defaults, overrides) {
|
|
|
9
9
|
const Default = defaults[route];
|
|
10
10
|
const Override = overrides[route];
|
|
11
11
|
if (typeof Override !== 'function') {
|
|
12
|
-
return
|
|
12
|
+
return { ...components, [route]: Default };
|
|
13
13
|
}
|
|
14
14
|
const { Footer, FormFields, Header } = Default;
|
|
15
15
|
// cast to allow assigning of component slots
|
|
@@ -17,7 +17,7 @@ function resolveAuthenticatorComponents(defaults, overrides) {
|
|
|
17
17
|
Component.Footer = Footer;
|
|
18
18
|
Component.FormFields = FormFields;
|
|
19
19
|
Component.Header = Header;
|
|
20
|
-
return
|
|
20
|
+
return { ...components, [route]: Component };
|
|
21
21
|
}, {});
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export { default as AuthenticatorProvider } from './Authenticator/context/AuthenticatorProvider.
|
|
2
|
-
import './Authenticator/context/AuthenticatorContext.
|
|
3
|
-
export { default as useAuthenticator } from './Authenticator/hooks/useAuthenticator/useAuthenticator.
|
|
4
|
-
export { default as useAuthenticatorRoute } from './Authenticator/hooks/useAuthenticatorRoute/useAuthenticatorRoute.
|
|
5
|
-
export { default as useAuthenticatorInitMachine } from './Authenticator/hooks/useAuthenticatorInitMachine/useAuthenticatorInitMachine.
|
|
6
|
-
export { isComponentRouteKey as isAuthenticatorComponentRouteKey, resolveAuthenticatorComponents } from './Authenticator/hooks/utils.
|
|
7
|
-
export { default as RenderNothing } from './components/RenderNothing/RenderNothing.
|
|
8
|
-
export { default as useDeprecationWarning } from './hooks/useDeprecationWarning.
|
|
9
|
-
export { default as useHasValueUpdated } from './hooks/useHasValueUpdated.
|
|
10
|
-
export { default as usePreviousValue } from './hooks/usePreviousValue.
|
|
1
|
+
export { default as AuthenticatorProvider } from './Authenticator/context/AuthenticatorProvider.mjs';
|
|
2
|
+
import './Authenticator/context/AuthenticatorContext.mjs';
|
|
3
|
+
export { default as useAuthenticator } from './Authenticator/hooks/useAuthenticator/useAuthenticator.mjs';
|
|
4
|
+
export { default as useAuthenticatorRoute } from './Authenticator/hooks/useAuthenticatorRoute/useAuthenticatorRoute.mjs';
|
|
5
|
+
export { default as useAuthenticatorInitMachine } from './Authenticator/hooks/useAuthenticatorInitMachine/useAuthenticatorInitMachine.mjs';
|
|
6
|
+
export { isComponentRouteKey as isAuthenticatorComponentRouteKey, resolveAuthenticatorComponents } from './Authenticator/hooks/utils.mjs';
|
|
7
|
+
export { default as RenderNothing } from './components/RenderNothing/RenderNothing.mjs';
|
|
8
|
+
export { default as useDeprecationWarning } from './hooks/useDeprecationWarning.mjs';
|
|
9
|
+
export { default as useHasValueUpdated } from './hooks/useHasValueUpdated.mjs';
|
|
10
|
+
export { default as usePreviousValue } from './hooks/usePreviousValue.mjs';
|
package/dist/index.js
CHANGED
|
@@ -30,43 +30,6 @@ function _interopNamespace(e) {
|
|
|
30
30
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
31
31
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
32
32
|
|
|
33
|
-
/******************************************************************************
|
|
34
|
-
Copyright (c) Microsoft Corporation.
|
|
35
|
-
|
|
36
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
37
|
-
purpose with or without fee is hereby granted.
|
|
38
|
-
|
|
39
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
40
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
41
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
42
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
43
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
44
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
45
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
46
|
-
***************************************************************************** */
|
|
47
|
-
|
|
48
|
-
function __rest(s, e) {
|
|
49
|
-
var t = {};
|
|
50
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
51
|
-
t[p] = s[p];
|
|
52
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
53
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
54
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
55
|
-
t[p[i]] = s[p[i]];
|
|
56
|
-
}
|
|
57
|
-
return t;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
61
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
62
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
63
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
64
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
65
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
66
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
33
|
/**
|
|
71
34
|
* AuthenticatorContext serves static reference to the auth machine service.
|
|
72
35
|
*
|
|
@@ -74,9 +37,9 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
74
37
|
*/
|
|
75
38
|
const AuthenticatorContext = React__default["default"].createContext(null);
|
|
76
39
|
|
|
77
|
-
const createHubHandler = (options) => (data, service) =>
|
|
78
|
-
|
|
79
|
-
}
|
|
40
|
+
const createHubHandler = (options) => async (data, service) => {
|
|
41
|
+
await ui.defaultAuthHubHandler(data, service, options);
|
|
42
|
+
};
|
|
80
43
|
function AuthenticatorProvider({ children, }) {
|
|
81
44
|
// `authStatus` is exposed by `useAuthenticator` but should not be derived directly from the
|
|
82
45
|
// state machine as the machine only updates on `Authenticator` initiated events, which
|
|
@@ -153,7 +116,7 @@ function resolveAuthenticatorComponents(defaults, overrides) {
|
|
|
153
116
|
const Default = defaults[route];
|
|
154
117
|
const Override = overrides[route];
|
|
155
118
|
if (typeof Override !== 'function') {
|
|
156
|
-
return
|
|
119
|
+
return { ...components, [route]: Default };
|
|
157
120
|
}
|
|
158
121
|
const { Footer, FormFields, Header } = Default;
|
|
159
122
|
// cast to allow assigning of component slots
|
|
@@ -161,7 +124,7 @@ function resolveAuthenticatorComponents(defaults, overrides) {
|
|
|
161
124
|
Component.Footer = Footer;
|
|
162
125
|
Component.FormFields = FormFields;
|
|
163
126
|
Component.Header = Header;
|
|
164
|
-
return
|
|
127
|
+
return { ...components, [route]: Component };
|
|
165
128
|
}, {});
|
|
166
129
|
}
|
|
167
130
|
|
|
@@ -189,16 +152,13 @@ const getComparator = (selector) => (currentFacade, nextFacade) => {
|
|
|
189
152
|
// Shallow compare the array values
|
|
190
153
|
return areSelectorDepsEqual(currentSelectorDeps, nextSelectorDeps);
|
|
191
154
|
};
|
|
192
|
-
const getQRFields = (state) => {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
198
|
-
return yield awsAmplify.Auth.setupTOTP(user);
|
|
199
|
-
});
|
|
155
|
+
const getQRFields = (state) => ({
|
|
156
|
+
...ui.getActorContext(state)?.formFields?.setupTOTP?.QR,
|
|
157
|
+
});
|
|
158
|
+
const getTotpSecretCodeCallback = (user) => async function getTotpSecretCode() {
|
|
159
|
+
return await awsAmplify.Auth.setupTOTP(user);
|
|
200
160
|
};
|
|
201
|
-
const flattenFormFields = (fields) => fields.flatMap(([name, options]) => (
|
|
161
|
+
const flattenFormFields = (fields) => fields.flatMap(([name, options]) => ({ name, ...options }));
|
|
202
162
|
const convertContactMethodsToFields = (unverifiedContactMethods) => {
|
|
203
163
|
return (unverifiedContactMethods &&
|
|
204
164
|
Object.entries(unverifiedContactMethods).map(([name, value]) => {
|
|
@@ -232,13 +192,13 @@ function useAuthenticator(selector) {
|
|
|
232
192
|
}
|
|
233
193
|
const { service } = context;
|
|
234
194
|
const { send } = service;
|
|
235
|
-
const xstateSelector = React.useCallback((state) => (
|
|
195
|
+
const xstateSelector = React.useCallback((state) => ({ ...ui.getServiceFacade({ send, state }) }), [send]);
|
|
236
196
|
const comparator = selector ? getComparator(selector) : defaultComparator;
|
|
237
197
|
// the purpose of `context.authStatus`is to intentionally override `facade.authStatus`. `facade.authStatus` does
|
|
238
198
|
// not update on external sign in events (for example when a user is not using the `Authenticator`).
|
|
239
199
|
const { authStatus } = context;
|
|
240
200
|
const facade = react.useSelector(service, xstateSelector, comparator);
|
|
241
|
-
const { route, totpSecretCode, unverifiedContactMethods, user
|
|
201
|
+
const { route, totpSecretCode, unverifiedContactMethods, user, ...rest } = facade;
|
|
242
202
|
// do not memoize output. `service.getSnapshot` reference remains stable preventing
|
|
243
203
|
// `fields` from updating with current form state on value changes
|
|
244
204
|
const serviceSnapshot = service.getSnapshot();
|
|
@@ -246,13 +206,18 @@ function useAuthenticator(selector) {
|
|
|
246
206
|
const QRFields = route === 'setupTOTP' ? getQRFields(serviceSnapshot) : null;
|
|
247
207
|
// legacy `formFields` values required until form state is removed from state machine
|
|
248
208
|
const fields = getMachineFields(route, serviceSnapshot, unverifiedContactMethods);
|
|
249
|
-
return
|
|
209
|
+
return {
|
|
210
|
+
...rest,
|
|
211
|
+
authStatus,
|
|
250
212
|
route,
|
|
251
213
|
totpSecretCode,
|
|
252
214
|
unverifiedContactMethods,
|
|
253
215
|
user,
|
|
254
216
|
/** @deprecated For internal use only */
|
|
255
|
-
fields,
|
|
217
|
+
fields,
|
|
218
|
+
getTotpSecretCode: getTotpSecretCodeCallback(user),
|
|
219
|
+
QRFields,
|
|
220
|
+
};
|
|
256
221
|
}
|
|
257
222
|
|
|
258
223
|
/**
|
|
@@ -350,47 +315,68 @@ const getRouteMachineSelector = (route) => isComponentRouteKey(route)
|
|
|
350
315
|
: routeSelector$1;
|
|
351
316
|
const isFormEventHandlerKey = (key) => ['updateBlur', 'updateForm', 'submitForm'].includes(key);
|
|
352
317
|
const convertEventHandlerKey = (key) => EVENT_HANDLER_KEY_MAP[key];
|
|
353
|
-
const getConvertedMachineProps = (route, context) => MACHINE_PROP_KEYS[route].reduce((acc, key) => (
|
|
318
|
+
const getConvertedMachineProps = (route, context) => MACHINE_PROP_KEYS[route].reduce((acc, key) => ({
|
|
319
|
+
...acc,
|
|
320
|
+
[isFormEventHandlerKey(key) ? convertEventHandlerKey(key) : key]: context[key],
|
|
321
|
+
}), {});
|
|
354
322
|
function resolveConfirmResetPasswordRoute(Component, props) {
|
|
355
323
|
return {
|
|
356
324
|
Component,
|
|
357
|
-
props:
|
|
325
|
+
props: {
|
|
326
|
+
...Component,
|
|
327
|
+
...getConvertedMachineProps('confirmResetPassword', props),
|
|
328
|
+
},
|
|
358
329
|
};
|
|
359
330
|
}
|
|
360
331
|
function resolveConfirmSignInRoute(Component, props) {
|
|
361
|
-
const
|
|
332
|
+
const { user, ...machineProps } = getConvertedMachineProps('confirmSignIn', props);
|
|
362
333
|
// prior to the `confirmSignIn` route, `user.username` is populated
|
|
363
334
|
const challengeName = user.challengeName;
|
|
364
|
-
return { Component, props:
|
|
335
|
+
return { Component, props: { ...Component, ...machineProps, challengeName } };
|
|
365
336
|
}
|
|
366
337
|
function resolveConfirmSignUpRoute(Component, props) {
|
|
367
338
|
return {
|
|
368
339
|
Component,
|
|
369
|
-
props:
|
|
340
|
+
props: {
|
|
341
|
+
...Component,
|
|
342
|
+
...getConvertedMachineProps('confirmSignUp', props),
|
|
343
|
+
},
|
|
370
344
|
};
|
|
371
345
|
}
|
|
372
346
|
function resolveConfirmVerifyUserRoute(Component, props) {
|
|
373
347
|
return {
|
|
374
348
|
Component,
|
|
375
|
-
props:
|
|
349
|
+
props: {
|
|
350
|
+
...Component,
|
|
351
|
+
...getConvertedMachineProps('confirmVerifyUser', props),
|
|
352
|
+
},
|
|
376
353
|
};
|
|
377
354
|
}
|
|
378
355
|
function resolveForceNewPasswordRoute(Component, props) {
|
|
379
356
|
return {
|
|
380
357
|
Component,
|
|
381
|
-
props:
|
|
358
|
+
props: {
|
|
359
|
+
...Component,
|
|
360
|
+
...getConvertedMachineProps('forceNewPassword', props),
|
|
361
|
+
},
|
|
382
362
|
};
|
|
383
363
|
}
|
|
384
364
|
function resolveResetPasswordRoute(Component, props) {
|
|
385
365
|
return {
|
|
386
366
|
Component,
|
|
387
|
-
props:
|
|
367
|
+
props: {
|
|
368
|
+
...Component,
|
|
369
|
+
...getConvertedMachineProps('resetPassword', props),
|
|
370
|
+
},
|
|
388
371
|
};
|
|
389
372
|
}
|
|
390
373
|
function resolveSetupTOTPRoute(Component, props) {
|
|
391
374
|
return {
|
|
392
375
|
Component,
|
|
393
|
-
props:
|
|
376
|
+
props: {
|
|
377
|
+
...Component,
|
|
378
|
+
...getConvertedMachineProps('setupTOTP', props),
|
|
379
|
+
},
|
|
394
380
|
};
|
|
395
381
|
}
|
|
396
382
|
function resolveSignInRoute(Component, props) {
|
|
@@ -398,19 +384,26 @@ function resolveSignInRoute(Component, props) {
|
|
|
398
384
|
const hideSignUp = false;
|
|
399
385
|
return {
|
|
400
386
|
Component,
|
|
401
|
-
props:
|
|
387
|
+
props: {
|
|
388
|
+
...Component,
|
|
389
|
+
...getConvertedMachineProps('signIn', props),
|
|
390
|
+
hideSignUp,
|
|
391
|
+
},
|
|
402
392
|
};
|
|
403
393
|
}
|
|
404
394
|
function resolveSignUpRoute(Component, props) {
|
|
405
395
|
return {
|
|
406
396
|
Component,
|
|
407
|
-
props:
|
|
397
|
+
props: { ...Component, ...getConvertedMachineProps('signUp', props) },
|
|
408
398
|
};
|
|
409
399
|
}
|
|
410
400
|
function resolveVerifyUserRoute(Component, props) {
|
|
411
401
|
return {
|
|
412
402
|
Component,
|
|
413
|
-
props:
|
|
403
|
+
props: {
|
|
404
|
+
...Component,
|
|
405
|
+
...getConvertedMachineProps('verifyUser', props),
|
|
406
|
+
},
|
|
414
407
|
};
|
|
415
408
|
}
|
|
416
409
|
function resolveDefault() {
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/ui-react-core",
|
|
3
|
-
"version": "0.0.0-studio-
|
|
3
|
+
"version": "0.0.0-studio-console-80bb2e2-20230921222703",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
|
-
"module": "dist/esm/index.
|
|
5
|
+
"module": "dist/esm/index.mjs",
|
|
6
6
|
"react-native": "dist/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
-
"import": "./dist/esm/index.
|
|
9
|
+
"import": "./dist/esm/index.mjs",
|
|
10
10
|
"require": "./dist/index.js",
|
|
11
11
|
"types": "./dist/types/index.d.ts"
|
|
12
12
|
},
|
|
@@ -21,16 +21,17 @@
|
|
|
21
21
|
"scripts": {
|
|
22
22
|
"clean": "rimraf dist node_modules",
|
|
23
23
|
"build": "rollup --config",
|
|
24
|
+
"check:esm": "node --input-type=module --eval 'import \"@aws-amplify/ui-react-core\"'",
|
|
24
25
|
"dev": "yarn build --watch",
|
|
25
26
|
"lint": "yarn typecheck && eslint src",
|
|
26
27
|
"prebuild": "rimraf dist",
|
|
27
28
|
"test": "jest",
|
|
28
|
-
"test:ci": "yarn test",
|
|
29
|
+
"test:ci": "yarn test && yarn check:esm",
|
|
29
30
|
"test:watch": "yarn test --watch",
|
|
30
31
|
"typecheck": "tsc --noEmit"
|
|
31
32
|
},
|
|
32
33
|
"dependencies": {
|
|
33
|
-
"@aws-amplify/ui": "0.0.0-studio-
|
|
34
|
+
"@aws-amplify/ui": "0.0.0-studio-console-80bb2e2-20230921222703",
|
|
34
35
|
"@xstate/react": "3.0.1",
|
|
35
36
|
"lodash": "4.17.21",
|
|
36
37
|
"xstate": "^4.33.6"
|
|
@@ -41,7 +42,6 @@
|
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
44
|
"@aws-amplify/eslint-config-amplify-ui": "0.0.0",
|
|
44
|
-
"@rollup/plugin-commonjs": "^22.0.1",
|
|
45
45
|
"@rollup/plugin-typescript": "^8.3.1",
|
|
46
46
|
"@testing-library/react": "^12.0.0",
|
|
47
47
|
"@testing-library/react-hooks": "^7.0.2",
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/******************************************************************************
|
|
2
|
-
Copyright (c) Microsoft Corporation.
|
|
3
|
-
|
|
4
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
-
purpose with or without fee is hereby granted.
|
|
6
|
-
|
|
7
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
-
***************************************************************************** */
|
|
15
|
-
|
|
16
|
-
function __rest(s, e) {
|
|
17
|
-
var t = {};
|
|
18
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
19
|
-
t[p] = s[p];
|
|
20
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
21
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
22
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
23
|
-
t[p[i]] = s[p[i]];
|
|
24
|
-
}
|
|
25
|
-
return t;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
29
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
31
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
32
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
33
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
34
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export { __awaiter, __rest };
|
/package/dist/esm/Authenticator/context/{AuthenticatorContext.js → AuthenticatorContext.mjs}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|