@aws-amplify/ui-react-core 1.0.4 → 2.0.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.
Files changed (63) hide show
  1. package/dist/esm/Authenticator/context/AuthenticatorContext.js +4 -1
  2. package/dist/esm/Authenticator/context/AuthenticatorProvider.js +8 -4
  3. package/dist/esm/Authenticator/hooks/useAuthenticator/constants.js +4 -2
  4. package/dist/esm/Authenticator/hooks/useAuthenticator/useAuthenticator.js +10 -10
  5. package/dist/esm/Authenticator/hooks/useAuthenticator/utils.js +13 -10
  6. package/dist/esm/InAppMessaging/context/InAppMessagingContext/InAppMessagingContext.js +5 -0
  7. package/dist/esm/InAppMessaging/context/InAppMessagingProvider/InAppMessagingProvider.js +26 -0
  8. package/dist/esm/InAppMessaging/hooks/useInAppMessaging/useInAppMessaging.js +19 -0
  9. package/dist/esm/InAppMessaging/hooks/useMessage/useMessage.js +78 -0
  10. package/dist/esm/InAppMessaging/hooks/useMessage/utils.js +43 -0
  11. package/dist/esm/InAppMessaging/utils/handleMessageAction.js +16 -0
  12. package/dist/esm/components/RenderNothing/RenderNothing.js +8 -0
  13. package/dist/esm/index.js +8 -1
  14. package/dist/esm/node_modules/tslib/tslib.es6.js +38 -0
  15. package/dist/esm/utils/index.js +5 -2
  16. package/dist/index.js +348 -6
  17. package/dist/{esm/Authenticator/hooks/useAuthenticator/types.js → types/Authenticator/context/__tests__/AuthenticatorProvider.test.d.ts} +0 -0
  18. package/dist/types/Authenticator/hooks/useAuthenticator/__tests__/useAuthenticator.spec.d.ts +1 -0
  19. package/dist/types/Authenticator/hooks/useAuthenticator/__tests__/utils.spec.d.ts +1 -0
  20. package/dist/types/Authenticator/hooks/useAuthenticator/types.d.ts +1 -9
  21. package/dist/types/InAppMessaging/context/InAppMessagingContext/InAppMessagingContext.d.ts +9 -0
  22. package/dist/types/InAppMessaging/context/InAppMessagingContext/index.d.ts +1 -0
  23. package/dist/types/InAppMessaging/context/InAppMessagingProvider/InAppMessagingProvider.d.ts +5 -0
  24. package/dist/types/InAppMessaging/context/InAppMessagingProvider/__tests__/InAppMessagingProvider.spec.d.ts +1 -0
  25. package/dist/types/InAppMessaging/context/InAppMessagingProvider/index.d.ts +1 -0
  26. package/dist/types/InAppMessaging/context/index.d.ts +2 -0
  27. package/dist/types/InAppMessaging/hooks/index.d.ts +2 -0
  28. package/dist/types/InAppMessaging/hooks/useInAppMessaging/__tests__/useInAppMessaging.spec.d.ts +1 -0
  29. package/dist/types/InAppMessaging/hooks/useInAppMessaging/index.d.ts +1 -0
  30. package/dist/types/InAppMessaging/hooks/useInAppMessaging/useInAppMessaging.d.ts +7 -0
  31. package/dist/types/InAppMessaging/hooks/useMessage/__tests__/useMessage.spec.d.ts +1 -0
  32. package/dist/types/InAppMessaging/hooks/useMessage/__tests__/utils.spec.d.ts +1 -0
  33. package/dist/types/InAppMessaging/hooks/useMessage/index.d.ts +1 -0
  34. package/dist/types/InAppMessaging/hooks/useMessage/types.d.ts +18 -0
  35. package/dist/types/InAppMessaging/hooks/useMessage/useMessage.d.ts +9 -0
  36. package/dist/types/InAppMessaging/hooks/useMessage/utils.d.ts +9 -0
  37. package/dist/{esm/Authenticator/index.js → types/InAppMessaging/index.d.ts} +3 -1
  38. package/dist/types/InAppMessaging/types.d.ts +52 -0
  39. package/dist/types/InAppMessaging/utils/__tests__/handleMessageAction.spec.d.ts +1 -0
  40. package/dist/types/InAppMessaging/utils/handleMessageAction.d.ts +9 -0
  41. package/dist/types/InAppMessaging/utils/index.d.ts +1 -0
  42. package/dist/types/__tests__/index.spec.d.ts +1 -0
  43. package/dist/types/components/RenderNothing/RenderNothing.d.ts +4 -0
  44. package/dist/types/components/RenderNothing/__tests__/RenderNothing.spec.d.ts +1 -0
  45. package/dist/types/components/RenderNothing/index.d.ts +1 -0
  46. package/dist/types/components/index.d.ts +1 -0
  47. package/dist/types/index.d.ts +1 -0
  48. package/dist/types/utils/__tests__/index.spec.d.ts +1 -0
  49. package/package.json +14 -9
  50. package/dist/Authenticator/context/AuthenticatorContext.js +0 -11
  51. package/dist/Authenticator/context/AuthenticatorProvider.js +0 -26
  52. package/dist/Authenticator/context/index.js +0 -10
  53. package/dist/Authenticator/hooks/index.js +0 -4
  54. package/dist/Authenticator/hooks/useAuthenticator/constants.js +0 -16
  55. package/dist/Authenticator/hooks/useAuthenticator/index.js +0 -8
  56. package/dist/Authenticator/hooks/useAuthenticator/types.js +0 -2
  57. package/dist/Authenticator/hooks/useAuthenticator/useAuthenticator.js +0 -38
  58. package/dist/Authenticator/hooks/useAuthenticator/utils.js +0 -53
  59. package/dist/Authenticator/index.js +0 -5
  60. package/dist/esm/Authenticator/context/index.js +0 -2
  61. package/dist/esm/Authenticator/hooks/index.js +0 -1
  62. package/dist/esm/Authenticator/hooks/useAuthenticator/index.js +0 -1
  63. package/dist/utils/index.js +0 -20
package/dist/index.js CHANGED
@@ -1,6 +1,348 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useAuthenticator = exports.AuthenticatorProvider = void 0;
4
- var Authenticator_1 = require("./Authenticator");
5
- Object.defineProperty(exports, "AuthenticatorProvider", { enumerable: true, get: function () { return Authenticator_1.AuthenticatorProvider; } });
6
- Object.defineProperty(exports, "useAuthenticator", { enumerable: true, get: function () { return Authenticator_1.useAuthenticator; } });
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+ var React = require('react');
7
+ var react = require('@xstate/react');
8
+ var ui = require('@aws-amplify/ui');
9
+ var awsAmplify = require('aws-amplify');
10
+ var isEmpty = require('lodash/isEmpty');
11
+ var isObject = require('lodash/isObject');
12
+ var notifications = require('@aws-amplify/notifications');
13
+ var core = require('@aws-amplify/core');
14
+ var isNil = require('lodash/isNil');
15
+ var isString = require('lodash/isString');
16
+
17
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
+
19
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
20
+ var isEmpty__default = /*#__PURE__*/_interopDefaultLegacy(isEmpty);
21
+ var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
22
+ var isNil__default = /*#__PURE__*/_interopDefaultLegacy(isNil);
23
+ var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString);
24
+
25
+ /**
26
+ * AuthenticatorContext serves static reference to the auth machine service.
27
+ *
28
+ * https://xstate.js.org/docs/recipes/react.html#context-provider
29
+ */
30
+ const AuthenticatorContext = React__default["default"].createContext(null);
31
+
32
+ function AuthenticatorProvider({ children, }) {
33
+ /**
34
+ * Based on use cases, developer might already have added another Provider
35
+ * outside Authenticator. In that case, we sync the two providers by just
36
+ * passing the parent value.
37
+ *
38
+ * TODO(BREAKING): enforce only one provider in App tree
39
+ */
40
+ const parentProviderVal = React.useContext(AuthenticatorContext);
41
+ const service = react.useInterpret(ui.createAuthenticatorMachine);
42
+ const value = React.useMemo(() => (!parentProviderVal ? { service } : parentProviderVal), [parentProviderVal, service]);
43
+ const { service: activeService } = value;
44
+ React.useEffect(() => {
45
+ const unsubscribe = ui.listenToAuthHub(activeService);
46
+ return unsubscribe;
47
+ }, [activeService]);
48
+ return (jsxRuntime.jsx(AuthenticatorContext.Provider, Object.assign({ value: value }, { children: children })));
49
+ }
50
+
51
+ /******************************************************************************
52
+ Copyright (c) Microsoft Corporation.
53
+
54
+ Permission to use, copy, modify, and/or distribute this software for any
55
+ purpose with or without fee is hereby granted.
56
+
57
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
58
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
59
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
60
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
61
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
62
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
63
+ PERFORMANCE OF THIS SOFTWARE.
64
+ ***************************************************************************** */
65
+
66
+ function __rest(s, e) {
67
+ var t = {};
68
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
69
+ t[p] = s[p];
70
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
71
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
72
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
73
+ t[p[i]] = s[p[i]];
74
+ }
75
+ return t;
76
+ }
77
+
78
+ function __awaiter(thisArg, _arguments, P, generator) {
79
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
80
+ return new (P || (P = Promise))(function (resolve, reject) {
81
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
82
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
83
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
84
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
85
+ });
86
+ }
87
+
88
+ const USE_AUTHENTICATOR_ERROR = '`useAuthenticator` must be used inside an `Authenticator.Provider`.';
89
+ const COMPONENT_ROUTE_KEYS = [
90
+ 'signIn',
91
+ 'signUp',
92
+ 'forceNewPassword',
93
+ 'confirmResetPassword',
94
+ 'confirmSignIn',
95
+ 'confirmSignUp',
96
+ 'confirmVerifyUser',
97
+ 'resetPassword',
98
+ 'setupTOTP',
99
+ 'verifyUser',
100
+ ];
101
+
102
+ function isEmptyArray(value) {
103
+ return Array.isArray(value) && isEmpty__default["default"](value);
104
+ }
105
+ function areEmptyArrays(...values) {
106
+ return values.every(isEmptyArray);
107
+ }
108
+ function isEmptyObject(value) {
109
+ return isObject__default["default"](value) && !Array.isArray(value) && isEmpty__default["default"](value);
110
+ }
111
+ function areEmptyObjects(...values) {
112
+ return values.every(isEmptyObject);
113
+ }
114
+
115
+ const defaultComparator = () => false;
116
+ /**
117
+ * Does an ordering and shallow comparison of each array value,
118
+ * plus a value equality check for empty objects and arrays.
119
+ */
120
+ function areSelectorDepsEqual(currentDeps, nextDeps) {
121
+ if (currentDeps.length !== nextDeps.length) {
122
+ return false;
123
+ }
124
+ return currentDeps.every((currentDep, index) => {
125
+ const nextDep = nextDeps[index];
126
+ if (areEmptyArrays(currentDep, nextDep) ||
127
+ areEmptyObjects(currentDep, nextDep)) {
128
+ return true;
129
+ }
130
+ return currentDep === nextDep;
131
+ });
132
+ }
133
+ const getComparator = (selector) => (currentFacade, nextFacade) => {
134
+ const currentSelectorDeps = selector(currentFacade);
135
+ const nextSelectorDeps = selector(nextFacade);
136
+ // Shallow compare the array values
137
+ return areSelectorDepsEqual(currentSelectorDeps, nextSelectorDeps);
138
+ };
139
+ const getTotpSecretCodeCallback = (user) => function getTotpSecretCode() {
140
+ return __awaiter(this, void 0, void 0, function* () {
141
+ return yield awsAmplify.Auth.setupTOTP(user);
142
+ });
143
+ };
144
+ const isComponentRouteKey = (route) => COMPONENT_ROUTE_KEYS.some((componentRoute) => componentRoute === route);
145
+ const flattenFormFields = (fields) => fields.flatMap(([name, options]) => (Object.assign({ name }, options)));
146
+ /**
147
+ * Retrieves legacy form field values from state machine for routes that have fields
148
+ */
149
+ const getLegacyFields = (route, state) =>
150
+ // verifyUser is a component route, but does not have form fields
151
+ isComponentRouteKey(route) && route !== 'verifyUser'
152
+ ? flattenFormFields(ui.getSortedFormFields(route, state))
153
+ : [];
154
+
155
+ /**
156
+ * [📖 Docs](https://ui.docs.amplify.aws/react/connected-components/authenticator/headless#useauthenticator-hook)
157
+ */
158
+ function useAuthenticator(selector) {
159
+ const context = React__default["default"].useContext(AuthenticatorContext);
160
+ if (!context) {
161
+ throw new Error(USE_AUTHENTICATOR_ERROR);
162
+ }
163
+ const { service } = context;
164
+ const { send } = service;
165
+ const xstateSelector = React.useCallback((state) => (Object.assign({}, ui.getServiceFacade({ send, state }))), [send]);
166
+ const comparator = selector ? getComparator(selector) : defaultComparator;
167
+ const facade = react.useSelector(service, xstateSelector, comparator);
168
+ const { route, user } = facade, rest = __rest(facade, ["route", "user"]);
169
+ // do not memoize output. `service.getSnapshot` reference remains stable preventing
170
+ // `fields` from updating with current form state on value changes
171
+ const serviceSnapshot = service.getSnapshot();
172
+ // legacy `formFields` values required until form state is removed from state machine
173
+ const fields = React.useMemo(() => getLegacyFields(route, serviceSnapshot), [route, serviceSnapshot]);
174
+ return Object.assign(Object.assign({}, rest), { getTotpSecretCode: getTotpSecretCodeCallback(user), route,
175
+ user,
176
+ /** @deprecated For internal use only */
177
+ fields });
178
+ }
179
+
180
+ const InAppMessagingContext = React.createContext(null);
181
+
182
+ const { InAppMessaging: InAppMessaging$1 } = notifications.Notifications;
183
+ function InAppMessagingProvider({ children, }) {
184
+ const [message, setMessage] = React.useState(null);
185
+ React.useEffect(() => {
186
+ const listener = InAppMessaging$1.onMessageReceived((message) => {
187
+ setMessage(message);
188
+ });
189
+ return listener.remove;
190
+ }, []);
191
+ const clearMessage = React.useCallback(() => {
192
+ setMessage(null);
193
+ }, []);
194
+ const value = React.useMemo(() => ({
195
+ clearMessage,
196
+ displayMessage: setMessage,
197
+ message,
198
+ }), [clearMessage, message]);
199
+ return (jsxRuntime.jsx(InAppMessagingContext.Provider, Object.assign({ value: value }, { children: children })));
200
+ }
201
+
202
+ /**
203
+ * Utility hook used to access the InAppMessagingContext values
204
+ *
205
+ * @returns {InAppMessagingContextType} InAppMessaging context values
206
+ */
207
+ function useInAppMessaging() {
208
+ const inAppMessagingContext = React.useContext(InAppMessagingContext);
209
+ if (!inAppMessagingContext) {
210
+ throw new Error('InAppMessagingContext is empty, did you forget the InAppMessagingProvider?');
211
+ }
212
+ return inAppMessagingContext;
213
+ }
214
+
215
+ /**
216
+ * Utility component for rendering nothing.
217
+ */
218
+ function RenderNothng(_) {
219
+ return null;
220
+ }
221
+
222
+ const logger$2 = new core.ConsoleLogger('Notifications.InAppMessaging');
223
+ const positions = {
224
+ BOTTOM_BANNER: 'bottom',
225
+ MIDDLE_BANNER: 'middle',
226
+ TOP_BANNER: 'top',
227
+ };
228
+ const getPositionProp = (layout) => positions[layout];
229
+ const getActionHandler = (actionParams, onMessageAction, onActionCallback) => ({
230
+ onAction() {
231
+ try {
232
+ onMessageAction(actionParams);
233
+ }
234
+ catch (e) {
235
+ logger$2.error(`Message action failure: ${e}`);
236
+ }
237
+ finally {
238
+ onActionCallback();
239
+ }
240
+ },
241
+ });
242
+ const getButtonProps = (_a, onMessageAction, onActionCallback) => {
243
+ var { action, url } = _a, baseButtonProps = __rest(_a, ["action", "url"]);
244
+ return (Object.assign(Object.assign({}, baseButtonProps), getActionHandler({ action, url }, onMessageAction, onActionCallback)));
245
+ };
246
+ const getContentProps = (content, onMessageAction, onActionCallback) => {
247
+ const props = {};
248
+ if (!content) {
249
+ return props;
250
+ }
251
+ const { primaryButton, secondaryButton } = content, restContent = __rest(content, ["primaryButton", "secondaryButton"]);
252
+ if (primaryButton) {
253
+ props.primaryButton = getButtonProps(primaryButton, onMessageAction, onActionCallback);
254
+ }
255
+ if (secondaryButton) {
256
+ props.secondaryButton = getButtonProps(secondaryButton, onMessageAction, onActionCallback);
257
+ }
258
+ return Object.assign(Object.assign({}, props), restContent);
259
+ };
260
+
261
+ const EMPTY_PROPS = Object.freeze({});
262
+ const logger$1 = new core.ConsoleLogger('Notifications.InAppMessaging');
263
+ const { InAppMessaging } = notifications.Notifications;
264
+ /**
265
+ * Utility hook for parsing a message and retrieving its corresponding UI component and props
266
+ *
267
+ * @param {UseMessageParams} props - platform specific UI components, action handler, and styles
268
+ * @returns {UseMessage} message UI component and props
269
+ */
270
+ function useMessage({ components, onMessageAction, }) {
271
+ const { clearMessage, message } = useInAppMessaging();
272
+ const { BannerMessage, CarouselMessage, FullScreenMessage, ModalMessage } = components;
273
+ if (isNil__default["default"](message)) {
274
+ return {
275
+ Component: RenderNothng,
276
+ props: EMPTY_PROPS,
277
+ };
278
+ }
279
+ const { content, layout } = message;
280
+ const onActionCallback = () => {
281
+ InAppMessaging.notifyMessageInteraction(message, notifications.InAppMessageInteractionEvent.MESSAGE_ACTION_TAKEN);
282
+ clearMessage();
283
+ };
284
+ const onClose = () => {
285
+ InAppMessaging.notifyMessageInteraction(message, notifications.InAppMessageInteractionEvent.MESSAGE_DISMISSED);
286
+ clearMessage();
287
+ };
288
+ const onDisplay = () => {
289
+ InAppMessaging.notifyMessageInteraction(message, notifications.InAppMessageInteractionEvent.MESSAGE_DISPLAYED);
290
+ };
291
+ switch (layout) {
292
+ case 'BOTTOM_BANNER':
293
+ case 'MIDDLE_BANNER':
294
+ case 'TOP_BANNER': {
295
+ const props = Object.assign(Object.assign({}, getContentProps(content === null || content === void 0 ? void 0 : content[0], onMessageAction, onActionCallback)), { layout,
296
+ onClose,
297
+ onDisplay, position: getPositionProp(layout) });
298
+ return { Component: BannerMessage, props };
299
+ }
300
+ case 'CAROUSEL': {
301
+ const props = {
302
+ data: content === null || content === void 0 ? void 0 : content.map((item) => getContentProps(item, onMessageAction, onActionCallback)),
303
+ layout,
304
+ onClose,
305
+ onDisplay,
306
+ };
307
+ return { Component: CarouselMessage, props };
308
+ }
309
+ case 'FULL_SCREEN': {
310
+ const props = Object.assign(Object.assign({}, getContentProps(content === null || content === void 0 ? void 0 : content[0], onMessageAction, onActionCallback)), { layout,
311
+ onClose,
312
+ onDisplay });
313
+ return { Component: FullScreenMessage, props };
314
+ }
315
+ case 'MODAL': {
316
+ const props = Object.assign(Object.assign({}, getContentProps(content === null || content === void 0 ? void 0 : content[0], onMessageAction, onActionCallback)), { layout,
317
+ onClose,
318
+ onDisplay });
319
+ return { Component: ModalMessage, props };
320
+ }
321
+ default: {
322
+ logger$1.info(`Received unknown InAppMessage layout: ${layout}`);
323
+ return {
324
+ Component: RenderNothng,
325
+ props: EMPTY_PROPS,
326
+ };
327
+ }
328
+ }
329
+ }
330
+
331
+ const logger = new core.ConsoleLogger('Notifications.InAppMessaging');
332
+ const handleMessageAction = ({ action, handleMessageLinkAction, url, }) => {
333
+ logger.info(`Handle action: ${action}`);
334
+ if (action === 'LINK' || action === 'DEEP_LINK') {
335
+ if (!isString__default["default"](url)) {
336
+ logger.warn(`url must be of type string: ${url}`);
337
+ return;
338
+ }
339
+ handleMessageLinkAction(url);
340
+ }
341
+ };
342
+
343
+ exports.AuthenticatorProvider = AuthenticatorProvider;
344
+ exports.InAppMessagingProvider = InAppMessagingProvider;
345
+ exports.handleMessageAction = handleMessageAction;
346
+ exports.useAuthenticator = useAuthenticator;
347
+ exports.useInAppMessaging = useInAppMessaging;
348
+ exports.useMessage = useMessage;
@@ -1,4 +1,4 @@
1
- import { AuthMachineSend, AuthMachineState, AuthenticatorServiceFacade, LegacyFormFieldOptions } from '@aws-amplify/ui';
1
+ import { AuthenticatorServiceFacade, LegacyFormFieldOptions } from '@aws-amplify/ui';
2
2
  /**
3
3
  * These are the "facades" that we provide, which contains contexts respective
4
4
  * to current authenticator state.
@@ -14,18 +14,10 @@ export declare type AuthenticatorLegacyFields = LegacyFormFieldOptions[];
14
14
  * desired value(s) that should trigger re-render.
15
15
  */
16
16
  export declare type Selector = (context: AuthenticatorMachineContext) => AuthenticatorMachineContext[AuthenticatorMachineContextKey][];
17
- declare type InternalAuthenticatorContext = {
18
- _state: AuthMachineState;
19
- _send: AuthMachineSend;
20
- };
21
17
  export interface UseAuthenticator extends AuthenticatorServiceFacade {
22
18
  getTotpSecretCode: () => Promise<string>;
23
19
  /** @deprecated For internal use only */
24
20
  fields: AuthenticatorLegacyFields;
25
- /** @deprecated For internal use only */
26
- _send: InternalAuthenticatorContext['_send'];
27
- /** @deprecated For internal use only */
28
- _state: InternalAuthenticatorContext['_state'];
29
21
  }
30
22
  export declare type Comparator = (currentFacade: AuthenticatorServiceFacade, nextFacade: AuthenticatorServiceFacade) => boolean;
31
23
  export {};
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { Message } from '../../types';
3
+ export interface InAppMessagingContextType {
4
+ clearMessage: () => void;
5
+ displayMessage: (message: Message) => void;
6
+ message: Message | null;
7
+ }
8
+ declare const InAppMessagingContext: import("react").Context<InAppMessagingContextType | null>;
9
+ export default InAppMessagingContext;
@@ -0,0 +1 @@
1
+ export { default as InAppMessagingContext, InAppMessagingContextType, } from './InAppMessagingContext';
@@ -0,0 +1,5 @@
1
+ import { ReactNode } from 'react';
2
+ export interface InAppMessagingProviderProps {
3
+ children: ReactNode;
4
+ }
5
+ export default function InAppMessagingProvider({ children, }: InAppMessagingProviderProps): JSX.Element;
@@ -0,0 +1 @@
1
+ export { default as InAppMessagingProvider } from './InAppMessagingProvider';
@@ -0,0 +1,2 @@
1
+ export * from './InAppMessagingContext';
2
+ export * from './InAppMessagingProvider';
@@ -0,0 +1,2 @@
1
+ export * from './useInAppMessaging';
2
+ export * from './useMessage';
@@ -0,0 +1 @@
1
+ export { default as useInAppMessaging } from './useInAppMessaging';
@@ -0,0 +1,7 @@
1
+ import { InAppMessagingContextType } from '../../context';
2
+ /**
3
+ * Utility hook used to access the InAppMessagingContext values
4
+ *
5
+ * @returns {InAppMessagingContextType} InAppMessaging context values
6
+ */
7
+ export default function useInAppMessaging(): InAppMessagingContextType;
@@ -0,0 +1 @@
1
+ export { default as useMessage } from './useMessage';
@@ -0,0 +1,18 @@
1
+ import { BannerMessageCommonProps, BannerMessageComponent, CarouselMessageCommonProps, CarouselMessageComponent, FullScreenMessageCommonProps, FullScreenMessageComponent, ModalMessageCommonProps, ModalMessageComponent, OnMessageAction } from '../../types';
2
+ interface Components<PlatformStyleProps> {
3
+ BannerMessage: BannerMessageComponent<PlatformStyleProps>;
4
+ CarouselMessage: CarouselMessageComponent<PlatformStyleProps>;
5
+ FullScreenMessage: FullScreenMessageComponent<PlatformStyleProps>;
6
+ ModalMessage: ModalMessageComponent<PlatformStyleProps>;
7
+ }
8
+ export interface UseMessageParams<PlatformStyleProps> {
9
+ components: Components<PlatformStyleProps>;
10
+ onMessageAction: OnMessageAction;
11
+ }
12
+ declare type MessageComponent<PlatformStyleProps> = BannerMessageComponent<PlatformStyleProps> | CarouselMessageComponent<PlatformStyleProps> | FullScreenMessageComponent<PlatformStyleProps> | ModalMessageComponent<PlatformStyleProps>;
13
+ declare type MessageProps<PlatformStyleProps> = BannerMessageCommonProps<PlatformStyleProps> | CarouselMessageCommonProps<PlatformStyleProps> | FullScreenMessageCommonProps<PlatformStyleProps> | ModalMessageCommonProps<PlatformStyleProps>;
14
+ export interface UseMessage<PlatformStyleProps> {
15
+ Component: MessageComponent<PlatformStyleProps>;
16
+ props: MessageProps<PlatformStyleProps>;
17
+ }
18
+ export {};
@@ -0,0 +1,9 @@
1
+ import { UseMessage, UseMessageParams } from './types';
2
+ export declare const EMPTY_PROPS: Readonly<{}>;
3
+ /**
4
+ * Utility hook for parsing a message and retrieving its corresponding UI component and props
5
+ *
6
+ * @param {UseMessageParams} props - platform specific UI components, action handler, and styles
7
+ * @returns {UseMessage} message UI component and props
8
+ */
9
+ export default function useMessage<PlatformStyleProps>({ components, onMessageAction, }: UseMessageParams<PlatformStyleProps>): UseMessage<PlatformStyleProps>;
@@ -0,0 +1,9 @@
1
+ import { BannerMessageLayouts, MessageAction, MessageComponentPosition, MessageContent, MessageContentProps, OnMessageAction } from '../../types';
2
+ export declare const getPositionProp: (layout: BannerMessageLayouts) => MessageComponentPosition;
3
+ export declare const getActionHandler: (actionParams: {
4
+ action: MessageAction;
5
+ url?: string;
6
+ }, onMessageAction: OnMessageAction, onActionCallback: () => void) => {
7
+ onAction: () => void;
8
+ };
9
+ export declare const getContentProps: (content: MessageContent, onMessageAction: OnMessageAction, onActionCallback: () => void) => MessageContentProps;
@@ -1,2 +1,4 @@
1
- export * from './context';
2
1
  export * from './hooks';
2
+ export * from './context';
3
+ export * from './types';
4
+ export * from './utils';
@@ -0,0 +1,52 @@
1
+ import React from 'react';
2
+ import { InAppMessage, InAppMessageAction, InAppMessageButton, InAppMessageContent, InAppMessageImage, InAppMessageLayout, InAppMessageStyle, InAppMessageTextAlign } from '@aws-amplify/notifications';
3
+ export declare type Message = InAppMessage;
4
+ export declare type MessageAction = InAppMessageAction;
5
+ export declare type MessageButton = InAppMessageButton;
6
+ export declare type MessageContent = InAppMessageContent;
7
+ export declare type MessageImage = InAppMessageImage;
8
+ export declare type MessageLayout = InAppMessageLayout;
9
+ export declare type MessageStyle = InAppMessageStyle;
10
+ export declare type MessageTextAlign = InAppMessageTextAlign;
11
+ export declare type OnMessageAction = (params: {
12
+ action: MessageAction;
13
+ url?: string | undefined;
14
+ }) => void;
15
+ export interface MessageButtonProps extends Omit<MessageButton, 'action' | 'url'> {
16
+ onAction: () => void;
17
+ }
18
+ export interface MessageContentProps extends Omit<MessageContent, 'primaryButton' | 'secondaryButton'> {
19
+ primaryButton?: MessageButtonProps;
20
+ secondaryButton?: MessageButtonProps;
21
+ }
22
+ export interface MessageComponentBaseProps<Style = unknown> extends MessageCommonProps<Style>, MessageContentProps {
23
+ }
24
+ export interface MessageCommonProps<PlatformStyleProps> {
25
+ layout: MessageLayout;
26
+ onClose?: () => void;
27
+ onDisplay?: () => void;
28
+ style?: PlatformStyleProps;
29
+ }
30
+ export declare type BannerMessageLayouts = 'BOTTOM_BANNER' | 'MIDDLE_BANNER' | 'TOP_BANNER';
31
+ export declare type MessageComponentPosition = 'bottom' | 'middle' | 'top';
32
+ export interface BannerMessageCommonProps<PlatformStyleProps> extends MessageCommonProps<PlatformStyleProps>, MessageContentProps {
33
+ position?: MessageComponentPosition;
34
+ }
35
+ export interface CarouselMessageCommonProps<PlatformStyleProps> extends MessageCommonProps<PlatformStyleProps> {
36
+ data?: MessageContentProps[];
37
+ }
38
+ export interface FullScreenMessageCommonProps<PlatformStyleProps> extends MessageCommonProps<PlatformStyleProps>, MessageContentProps {
39
+ }
40
+ export interface ModalMessageCommonProps<PlatformStyleProps> extends MessageCommonProps<PlatformStyleProps>, MessageContentProps {
41
+ }
42
+ export interface MessagePayloadStyle {
43
+ body?: MessageStyle;
44
+ container?: MessageStyle;
45
+ header?: MessageStyle;
46
+ primaryButton?: MessageStyle;
47
+ secondaryButton?: MessageStyle;
48
+ }
49
+ export declare type BannerMessageComponent<PlatformStyleProps> = React.ComponentType<BannerMessageCommonProps<PlatformStyleProps>>;
50
+ export declare type CarouselMessageComponent<PlatformStyleProps> = React.ComponentType<CarouselMessageCommonProps<PlatformStyleProps>>;
51
+ export declare type FullScreenMessageComponent<PlatformStyleProps> = React.ComponentType<FullScreenMessageCommonProps<PlatformStyleProps>>;
52
+ export declare type ModalMessageComponent<PlatformStyleProps> = React.ComponentType<ModalMessageCommonProps<PlatformStyleProps>>;
@@ -0,0 +1,9 @@
1
+ import { MessageAction } from '../types';
2
+ export declare type HandleMessageLinkAction = (url: string) => void | Promise<void>;
3
+ interface HandleMessageActionParams {
4
+ action: MessageAction;
5
+ handleMessageLinkAction: HandleMessageLinkAction;
6
+ url: string | undefined;
7
+ }
8
+ declare const handleMessageAction: ({ action, handleMessageLinkAction, url, }: HandleMessageActionParams) => void;
9
+ export default handleMessageAction;
@@ -0,0 +1 @@
1
+ export { default as handleMessageAction, HandleMessageLinkAction, } from './handleMessageAction';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Utility component for rendering nothing.
3
+ */
4
+ export default function RenderNothng<Props>(_: Props): JSX.Element | null;
@@ -0,0 +1 @@
1
+ export { default as RenderNothing } from './RenderNothing';
@@ -0,0 +1 @@
1
+ export { RenderNothing } from './RenderNothing';
@@ -1 +1,2 @@
1
1
  export { AuthenticatorProvider, useAuthenticator, UseAuthenticator, } from './Authenticator';
2
+ export { BannerMessageCommonProps, BannerMessageComponent, CarouselMessageCommonProps, CarouselMessageComponent, FullScreenMessageCommonProps, FullScreenMessageComponent, handleMessageAction, HandleMessageLinkAction, InAppMessagingProvider, MessageButtonProps, MessageCommonProps, MessageComponentBaseProps, MessageContentProps, MessageImage, MessageLayout, MessagePayloadStyle, MessageTextAlign, ModalMessageCommonProps, ModalMessageComponent, OnMessageAction, useInAppMessaging, useMessage, } from './InAppMessaging';
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@aws-amplify/ui-react-core",
3
- "version": "1.0.4",
3
+ "version": "2.0.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/esm/index.js",
6
+ "react-native": "dist/index.js",
6
7
  "exports": {
7
8
  ".": {
8
9
  "import": "./dist/esm/index.js",
@@ -19,25 +20,26 @@
19
20
  "scripts": {
20
21
  "clean": "rimraf dist node_modules",
21
22
  "prebuild": "rimraf dist",
22
- "build": "yarn build:cjs && yarn build:esm",
23
- "build:cjs": "tsc --project tsconfig.cjs.json",
24
- "build:esm": "tsc --project tsconfig.esm.json",
23
+ "build": "rollup --config",
25
24
  "dev": "yarn build:esm --watch",
26
25
  "lint": "tsc --noEmit && eslint src",
27
26
  "test": "jest --coverage --verbose",
28
27
  "test:watch": "yarn test --watch"
29
28
  },
30
29
  "dependencies": {
31
- "@aws-amplify/ui": "4.0.1",
30
+ "@aws-amplify/ui": "5.0.0",
32
31
  "@xstate/react": "3.0.1",
32
+ "lodash": "4.17.21",
33
33
  "xstate": "^4.33.6"
34
34
  },
35
35
  "peerDependencies": {
36
- "aws-amplify": "3.x.x || 4.x.x",
37
- "react": ">= 16.8.0",
38
- "react-dom": ">= 16.8.0"
36
+ "aws-amplify": "5.x.x",
37
+ "react": ">= 16.14.0",
38
+ "react-dom": ">= 16.14.0"
39
39
  },
40
40
  "devDependencies": {
41
+ "@rollup/plugin-commonjs": "^22.0.1",
42
+ "@rollup/plugin-typescript": "^8.3.1",
41
43
  "@testing-library/react": "^12.0.0",
42
44
  "@testing-library/react-hooks": "^7.0.2",
43
45
  "@types/jest": "^26.0.23",
@@ -60,8 +62,11 @@
60
62
  "react-dom": "^17.0.2",
61
63
  "react-test-renderer": "^17.0.2",
62
64
  "rimraf": "^3.0.2",
65
+ "rollup": "^2.70.0",
66
+ "rollup-plugin-node-externals": "^4.1.1",
63
67
  "ts-jest": "^27.1.3",
64
68
  "ts-node": "^10.2.1",
65
69
  "typescript": "^4.3.2"
66
- }
70
+ },
71
+ "sideEffects": false
67
72
  }