@aws-amplify/ui 5.8.1 → 6.0.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.
Files changed (343) hide show
  1. package/dist/esm/helpers/accountSettings/utils.mjs +33 -1
  2. package/dist/esm/helpers/accountSettings/validator.mjs +120 -1
  3. package/dist/esm/helpers/authenticator/actor.mjs +20 -1
  4. package/dist/esm/helpers/authenticator/constants.mjs +144 -1
  5. package/dist/esm/helpers/authenticator/defaultAuthHubHandler.mjs +52 -0
  6. package/dist/esm/helpers/authenticator/facade.mjs +137 -1
  7. package/dist/esm/helpers/authenticator/form.mjs +43 -1
  8. package/dist/esm/helpers/authenticator/formFields/defaults.mjs +132 -1
  9. package/dist/esm/helpers/authenticator/formFields/formFields.mjs +62 -1
  10. package/dist/esm/helpers/authenticator/formFields/utils.mjs +35 -0
  11. package/dist/esm/helpers/authenticator/getRoute.mjs +47 -0
  12. package/dist/esm/helpers/authenticator/textUtil.mjs +112 -1
  13. package/dist/esm/helpers/authenticator/utils.mjs +38 -1
  14. package/dist/esm/helpers/utils.mjs +5 -1
  15. package/dist/esm/i18n/country-dial-codes.mjs +210 -1
  16. package/dist/esm/i18n/dictionaries/authenticator/de.mjs +87 -1
  17. package/dist/esm/i18n/dictionaries/authenticator/defaultTexts.mjs +83 -1
  18. package/dist/esm/i18n/dictionaries/authenticator/en.mjs +74 -1
  19. package/dist/esm/i18n/dictionaries/authenticator/es.mjs +83 -1
  20. package/dist/esm/i18n/dictionaries/authenticator/fr.mjs +92 -1
  21. package/dist/esm/i18n/dictionaries/authenticator/he.mjs +54 -1
  22. package/dist/esm/i18n/dictionaries/authenticator/id.mjs +96 -1
  23. package/dist/esm/i18n/dictionaries/authenticator/it.mjs +82 -1
  24. package/dist/esm/i18n/dictionaries/authenticator/ja.mjs +86 -1
  25. package/dist/esm/i18n/dictionaries/authenticator/kr.mjs +71 -1
  26. package/dist/esm/i18n/dictionaries/authenticator/nb.mjs +95 -1
  27. package/dist/esm/i18n/dictionaries/authenticator/nl.mjs +67 -1
  28. package/dist/esm/i18n/dictionaries/authenticator/pl.mjs +71 -1
  29. package/dist/esm/i18n/dictionaries/authenticator/pt.mjs +61 -1
  30. package/dist/esm/i18n/dictionaries/authenticator/ru.mjs +61 -1
  31. package/dist/esm/i18n/dictionaries/authenticator/sv.mjs +82 -1
  32. package/dist/esm/i18n/dictionaries/authenticator/tr.mjs +76 -1
  33. package/dist/esm/i18n/dictionaries/authenticator/ua.mjs +84 -1
  34. package/dist/esm/i18n/dictionaries/authenticator/zh.mjs +74 -1
  35. package/dist/esm/i18n/dictionaries/index.mjs +47 -1
  36. package/dist/esm/i18n/translations.mjs +67 -1
  37. package/dist/esm/index.mjs +28 -1
  38. package/dist/esm/machines/authenticator/actions.mjs +188 -1
  39. package/dist/esm/machines/authenticator/actors/forgotPassword.mjs +184 -0
  40. package/dist/esm/machines/authenticator/actors/signIn.mjs +328 -1
  41. package/dist/esm/machines/authenticator/actors/signOut.mjs +28 -1
  42. package/dist/esm/machines/authenticator/actors/signUp.mjs +295 -0
  43. package/dist/esm/machines/authenticator/actors/verifyUserAttributes.mjs +106 -0
  44. package/dist/esm/machines/authenticator/defaultServices.mjs +102 -1
  45. package/dist/esm/machines/authenticator/guards.mjs +70 -0
  46. package/dist/esm/machines/authenticator/index.mjs +368 -1
  47. package/dist/esm/machines/authenticator/utils.mjs +71 -0
  48. package/dist/esm/theme/breakpoints.mjs +14 -1
  49. package/dist/esm/theme/createTheme.mjs +156 -1
  50. package/dist/esm/theme/defaultDarkModeOverride.mjs +128 -1
  51. package/dist/esm/theme/defaultTheme.mjs +10 -1
  52. package/dist/esm/theme/tokens/borderWidths.mjs +7 -1
  53. package/dist/esm/theme/tokens/colors.mjs +166 -1
  54. package/dist/esm/theme/tokens/components/accordion.mjs +47 -0
  55. package/dist/esm/theme/tokens/components/alert.mjs +35 -1
  56. package/dist/esm/theme/tokens/components/authenticator.mjs +39 -1
  57. package/dist/esm/theme/tokens/components/autocomplete.mjs +42 -1
  58. package/dist/esm/theme/tokens/components/badge.mjs +44 -1
  59. package/dist/esm/theme/tokens/components/breadcrumbs.mjs +34 -1
  60. package/dist/esm/theme/tokens/components/button.mjs +685 -1
  61. package/dist/esm/theme/tokens/components/card.mjs +27 -1
  62. package/dist/esm/theme/tokens/components/checkbox.mjs +87 -1
  63. package/dist/esm/theme/tokens/components/checkboxField.mjs +8 -1
  64. package/dist/esm/theme/tokens/components/collection.mjs +72 -1
  65. package/dist/esm/theme/tokens/components/copy.mjs +18 -1
  66. package/dist/esm/theme/tokens/components/dialCodeSelect.mjs +7 -1
  67. package/dist/esm/theme/tokens/components/divider.mjs +22 -1
  68. package/dist/esm/theme/tokens/components/dropZone.mjs +46 -1
  69. package/dist/esm/theme/tokens/components/field.mjs +20 -1
  70. package/dist/esm/theme/tokens/components/fieldControl.mjs +131 -1
  71. package/dist/esm/theme/tokens/components/fieldGroup.mjs +11 -1
  72. package/dist/esm/theme/tokens/components/fieldMessages.mjs +13 -1
  73. package/dist/esm/theme/tokens/components/fieldset.mjs +40 -1
  74. package/dist/esm/theme/tokens/components/flex.mjs +9 -1
  75. package/dist/esm/theme/tokens/components/heading.mjs +30 -1
  76. package/dist/esm/theme/tokens/components/highlightMatch.mjs +7 -1
  77. package/dist/esm/theme/tokens/components/icon.mjs +6 -1
  78. package/dist/esm/theme/tokens/components/image.mjs +8 -1
  79. package/dist/esm/theme/tokens/components/inAppMessaging.mjs +23 -1
  80. package/dist/esm/theme/tokens/components/index.mjs +111 -1
  81. package/dist/esm/theme/tokens/components/input.mjs +12 -1
  82. package/dist/esm/theme/tokens/components/link.mjs +9 -1
  83. package/dist/esm/theme/tokens/components/liveness.mjs +7 -1
  84. package/dist/esm/theme/tokens/components/loader.mjs +42 -1
  85. package/dist/esm/theme/tokens/components/menu.mjs +27 -1
  86. package/dist/esm/theme/tokens/components/message.mjs +102 -1
  87. package/dist/esm/theme/tokens/components/pagination.mjs +40 -1
  88. package/dist/esm/theme/tokens/components/passwordField.mjs +38 -1
  89. package/dist/esm/theme/tokens/components/phoneNumberField.mjs +10 -1
  90. package/dist/esm/theme/tokens/components/placeholder.mjs +18 -1
  91. package/dist/esm/theme/tokens/components/radio.mjs +67 -1
  92. package/dist/esm/theme/tokens/components/radioGroup.mjs +19 -1
  93. package/dist/esm/theme/tokens/components/rating.mjs +9 -1
  94. package/dist/esm/theme/tokens/components/searchField.mjs +39 -1
  95. package/dist/esm/theme/tokens/components/select.mjs +63 -1
  96. package/dist/esm/theme/tokens/components/selectField.mjs +16 -1
  97. package/dist/esm/theme/tokens/components/sliderField.mjs +70 -1
  98. package/dist/esm/theme/tokens/components/stepperField.mjs +33 -1
  99. package/dist/esm/theme/tokens/components/storagemanager.mjs +97 -1
  100. package/dist/esm/theme/tokens/components/switchField.mjs +61 -1
  101. package/dist/esm/theme/tokens/components/table.mjs +105 -1
  102. package/dist/esm/theme/tokens/components/tabs.mjs +59 -1
  103. package/dist/esm/theme/tokens/components/text.mjs +28 -1
  104. package/dist/esm/theme/tokens/components/textAreaField.mjs +11 -1
  105. package/dist/esm/theme/tokens/components/textField.mjs +12 -1
  106. package/dist/esm/theme/tokens/components/toggleButton.mjs +96 -1
  107. package/dist/esm/theme/tokens/components/toggleButtonGroup.mjs +7 -1
  108. package/dist/esm/theme/tokens/fontSizes.mjs +14 -1
  109. package/dist/esm/theme/tokens/fontWeights.mjs +13 -1
  110. package/dist/esm/theme/tokens/fonts.mjs +19 -1
  111. package/dist/esm/theme/tokens/index.mjs +65 -1
  112. package/dist/esm/theme/tokens/lineHeights.mjs +7 -1
  113. package/dist/esm/theme/tokens/opacities.mjs +15 -1
  114. package/dist/esm/theme/tokens/outlineOffsets.mjs +7 -1
  115. package/dist/esm/theme/tokens/outlineWidths.mjs +7 -1
  116. package/dist/esm/theme/tokens/radii.mjs +11 -1
  117. package/dist/esm/theme/tokens/shadows.mjs +28 -1
  118. package/dist/esm/theme/tokens/space.mjs +29 -1
  119. package/dist/esm/theme/tokens/time.mjs +7 -1
  120. package/dist/esm/theme/tokens/transforms.mjs +10 -1
  121. package/dist/esm/theme/utils.mjs +81 -1
  122. package/dist/esm/types/authenticator/attributes.mjs +41 -1
  123. package/dist/esm/types/authenticator/user.mjs +18 -1
  124. package/dist/esm/types/authenticator/utils.mjs +5 -1
  125. package/dist/esm/types/primitives/componentClassName.mjs +164 -1
  126. package/dist/esm/utils/classNames.mjs +39 -0
  127. package/dist/esm/utils/setUserAgent/constants.mjs +43 -0
  128. package/dist/esm/utils/setUserAgent/setUserAgent.mjs +65 -0
  129. package/dist/esm/utils/utils.mjs +227 -0
  130. package/dist/esm/validators/index.mjs +19 -1
  131. package/dist/index.js +8396 -1
  132. package/dist/styles/StorageManager.css +138 -0
  133. package/dist/styles/StorageManager.layer.css +140 -0
  134. package/dist/styles/_fieldControl.css +0 -0
  135. package/dist/styles/_fieldControl.layer.css +3 -0
  136. package/dist/styles/accordion.css +64 -0
  137. package/dist/styles/accordion.layer.css +66 -0
  138. package/dist/styles/alert.css +44 -0
  139. package/dist/styles/alert.layer.css +46 -0
  140. package/dist/styles/authenticator.css +72 -0
  141. package/dist/styles/authenticator.layer.css +74 -0
  142. package/dist/styles/autocomplete.css +48 -0
  143. package/dist/styles/autocomplete.layer.css +50 -0
  144. package/dist/styles/badge.css +35 -0
  145. package/dist/styles/badge.layer.css +37 -0
  146. package/dist/styles/base.css +1491 -0
  147. package/dist/styles/base.layer.css +1493 -0
  148. package/dist/styles/breadcrumbs.css +40 -0
  149. package/dist/styles/breadcrumbs.layer.css +42 -0
  150. package/dist/styles/button.css +1122 -0
  151. package/dist/styles/button.layer.css +1124 -0
  152. package/dist/styles/card.css +26 -0
  153. package/dist/styles/card.layer.css +28 -0
  154. package/dist/styles/checkbox.css +95 -0
  155. package/dist/styles/checkbox.layer.css +97 -0
  156. package/dist/styles/checkboxField.css +6 -0
  157. package/dist/styles/checkboxField.layer.css +8 -0
  158. package/dist/styles/collection.css +70 -0
  159. package/dist/styles/collection.layer.css +72 -0
  160. package/dist/styles/copy.css +27 -0
  161. package/dist/styles/copy.layer.css +29 -0
  162. package/dist/styles/dialCodeSelect.css +3 -0
  163. package/dist/styles/dialCodeSelect.layer.css +5 -0
  164. package/dist/styles/divider.css +47 -0
  165. package/dist/styles/divider.layer.css +49 -0
  166. package/dist/styles/dropZone.css +45 -0
  167. package/dist/styles/dropZone.layer.css +47 -0
  168. package/dist/styles/field.css +17 -0
  169. package/dist/styles/field.layer.css +19 -0
  170. package/dist/styles/fieldGroup.css +130 -0
  171. package/dist/styles/fieldGroup.layer.css +132 -0
  172. package/dist/styles/fieldMessages.css +10 -0
  173. package/dist/styles/fieldMessages.layer.css +12 -0
  174. package/dist/styles/fieldModifiers.css +15 -0
  175. package/dist/styles/fieldModifiers.layer.css +17 -0
  176. package/dist/styles/fieldset.css +37 -0
  177. package/dist/styles/fieldset.layer.css +39 -0
  178. package/dist/styles/flex.css +8 -0
  179. package/dist/styles/flex.layer.css +10 -0
  180. package/dist/styles/grid.css +3 -0
  181. package/dist/styles/grid.layer.css +5 -0
  182. package/dist/styles/heading.css +40 -0
  183. package/dist/styles/heading.layer.css +42 -0
  184. package/dist/styles/highlightMatch.css +3 -0
  185. package/dist/styles/highlightMatch.layer.css +5 -0
  186. package/dist/styles/icon.css +14 -0
  187. package/dist/styles/icon.layer.css +16 -0
  188. package/dist/styles/image.css +9 -0
  189. package/dist/styles/image.layer.css +11 -0
  190. package/dist/styles/inAppMessaging.css +179 -0
  191. package/dist/styles/inAppMessaging.layer.css +181 -0
  192. package/dist/styles/input.css +83 -0
  193. package/dist/styles/input.layer.css +85 -0
  194. package/dist/styles/link.css +26 -0
  195. package/dist/styles/link.layer.css +28 -0
  196. package/dist/styles/liveness.css +423 -0
  197. package/dist/styles/liveness.layer.css +425 -0
  198. package/dist/styles/loader.css +108 -0
  199. package/dist/styles/loader.layer.css +110 -0
  200. package/dist/styles/menu.css +54 -0
  201. package/dist/styles/menu.layer.css +56 -0
  202. package/dist/styles/message.css +111 -0
  203. package/dist/styles/message.layer.css +113 -0
  204. package/dist/styles/pagination.css +41 -0
  205. package/dist/styles/pagination.layer.css +43 -0
  206. package/dist/styles/passwordField.css +49 -0
  207. package/dist/styles/passwordField.layer.css +51 -0
  208. package/dist/styles/phoneNumberField.css +30 -0
  209. package/dist/styles/phoneNumberField.layer.css +32 -0
  210. package/dist/styles/placeholder.css +31 -0
  211. package/dist/styles/placeholder.layer.css +33 -0
  212. package/dist/styles/radio.css +82 -0
  213. package/dist/styles/radio.layer.css +84 -0
  214. package/dist/styles/radioGroupField.css +25 -0
  215. package/dist/styles/radioGroupField.layer.css +27 -0
  216. package/dist/styles/radiogroup.css +5 -0
  217. package/dist/styles/radiogroup.layer.css +7 -0
  218. package/dist/styles/rating.css +33 -0
  219. package/dist/styles/rating.layer.css +35 -0
  220. package/dist/styles/reset.css +76 -0
  221. package/dist/styles/reset.layer.css +78 -0
  222. package/dist/styles/scrollView.css +4 -0
  223. package/dist/styles/scrollView.layer.css +6 -0
  224. package/dist/styles/searchField.css +29 -0
  225. package/dist/styles/searchField.layer.css +31 -0
  226. package/dist/styles/select.css +128 -0
  227. package/dist/styles/select.layer.css +130 -0
  228. package/dist/styles/selectField.css +18 -0
  229. package/dist/styles/selectField.layer.css +20 -0
  230. package/dist/styles/sliderField.css +143 -0
  231. package/dist/styles/sliderField.layer.css +145 -0
  232. package/dist/styles/stepperField.css +77 -0
  233. package/dist/styles/stepperField.layer.css +79 -0
  234. package/dist/styles/switchField.css +76 -0
  235. package/dist/styles/switchField.layer.css +78 -0
  236. package/dist/styles/table.css +146 -0
  237. package/dist/styles/table.layer.css +148 -0
  238. package/dist/styles/tabs.css +87 -0
  239. package/dist/styles/tabs.layer.css +89 -0
  240. package/dist/styles/text.css +40 -0
  241. package/dist/styles/text.layer.css +42 -0
  242. package/dist/styles/textArea.css +71 -0
  243. package/dist/styles/textArea.layer.css +73 -0
  244. package/dist/styles/textAreaField.css +12 -0
  245. package/dist/styles/textAreaField.layer.css +14 -0
  246. package/dist/styles/textField.css +14 -0
  247. package/dist/styles/textField.layer.css +16 -0
  248. package/dist/styles/toggleButton.css +280 -0
  249. package/dist/styles/toggleButton.layer.css +282 -0
  250. package/dist/styles/toggleButtonGroup.css +31 -0
  251. package/dist/styles/toggleButtonGroup.layer.css +33 -0
  252. package/dist/styles/visuallyHidden.css +12 -0
  253. package/dist/styles/visuallyHidden.layer.css +14 -0
  254. package/dist/styles.css +343 -680
  255. package/dist/styles.layer.css +6164 -0
  256. package/dist/theme.css +93 -156
  257. package/dist/types/helpers/accountSettings/utils.d.ts +1 -3
  258. package/dist/types/helpers/authenticator/actor.d.ts +1 -1
  259. package/dist/types/helpers/authenticator/constants.d.ts +5 -0
  260. package/dist/types/helpers/authenticator/defaultAuthHubHandler.d.ts +15 -0
  261. package/dist/types/helpers/authenticator/facade.d.ts +35 -6
  262. package/dist/types/helpers/authenticator/formFields/defaults.d.ts +3 -1
  263. package/dist/types/helpers/authenticator/formFields/formFields.d.ts +2 -1
  264. package/dist/types/helpers/authenticator/formFields/index.d.ts +1 -1
  265. package/dist/types/helpers/authenticator/formFields/{util.d.ts → utils.d.ts} +2 -0
  266. package/dist/types/helpers/authenticator/getRoute.d.ts +2 -0
  267. package/dist/types/helpers/authenticator/index.d.ts +2 -1
  268. package/dist/types/helpers/authenticator/textUtil.d.ts +8 -7
  269. package/dist/types/{types/authenticator/stateMachine/authMachine.d.ts → helpers/authenticator/types.d.ts} +5 -5
  270. package/dist/types/helpers/authenticator/utils.d.ts +0 -25
  271. package/dist/types/helpers/index.d.ts +0 -1
  272. package/dist/types/helpers/utils.d.ts +2 -2
  273. package/dist/types/i18n/translations.d.ts +2 -3
  274. package/dist/types/machines/authenticator/actions.d.ts +4 -62
  275. package/dist/types/machines/authenticator/actors/{resetPassword.d.ts → forgotPassword.d.ts} +3 -3
  276. package/dist/types/machines/authenticator/actors/index.d.ts +3 -1
  277. package/dist/types/machines/authenticator/actors/signIn.d.ts +3 -3
  278. package/dist/types/machines/authenticator/actors/signOut.d.ts +2 -2
  279. package/dist/types/machines/authenticator/{signUp.d.ts → actors/signUp.d.ts} +3 -3
  280. package/dist/types/machines/authenticator/actors/verifyUserAttributes.d.ts +5 -0
  281. package/dist/types/machines/authenticator/defaultServices.d.ts +208 -28
  282. package/dist/types/machines/authenticator/getAuthenticatorConfig.d.ts +14 -0
  283. package/dist/types/machines/authenticator/guards.d.ts +4 -0
  284. package/dist/types/machines/authenticator/index.d.ts +4 -2
  285. package/dist/types/machines/authenticator/types.d.ts +125 -0
  286. package/dist/types/machines/authenticator/utils.d.ts +7 -0
  287. package/dist/types/machines/index.d.ts +1 -0
  288. package/dist/types/theme/tokens/borderWidths.d.ts +2 -2
  289. package/dist/types/theme/tokens/colors.d.ts +7 -9
  290. package/dist/types/theme/tokens/components/accordion.d.ts +12 -0
  291. package/dist/types/theme/tokens/components/index.d.ts +2 -4
  292. package/dist/types/theme/tokens/components/radioGroup.d.ts +1 -1
  293. package/dist/types/theme/tokens/components/storagemanager.d.ts +18 -3
  294. package/dist/types/theme/tokens/components/tabs.d.ts +4 -3
  295. package/dist/types/theme/tokens/fontSizes.d.ts +2 -2
  296. package/dist/types/theme/tokens/fontWeights.d.ts +2 -2
  297. package/dist/types/theme/tokens/fonts.d.ts +2 -2
  298. package/dist/types/theme/tokens/lineHeights.d.ts +2 -2
  299. package/dist/types/theme/tokens/opacities.d.ts +2 -2
  300. package/dist/types/theme/tokens/outlineOffsets.d.ts +2 -2
  301. package/dist/types/theme/tokens/outlineWidths.d.ts +2 -2
  302. package/dist/types/theme/tokens/radii.d.ts +2 -2
  303. package/dist/types/theme/tokens/shadows.d.ts +2 -2
  304. package/dist/types/theme/tokens/space.d.ts +2 -2
  305. package/dist/types/theme/tokens/time.d.ts +2 -2
  306. package/dist/types/theme/tokens/types/designToken.d.ts +12 -6
  307. package/dist/types/theme/types.d.ts +5 -1
  308. package/dist/types/types/authenticator/attributes.d.ts +10 -4
  309. package/dist/types/types/authenticator/form.d.ts +7 -6
  310. package/dist/types/types/authenticator/index.d.ts +0 -1
  311. package/dist/types/types/authenticator/user.d.ts +3 -29
  312. package/dist/types/types/authenticator/validator.d.ts +2 -2
  313. package/dist/types/types/displayText.d.ts +84 -0
  314. package/dist/types/types/index.d.ts +1 -0
  315. package/dist/types/types/primitives/componentClassName.d.ts +162 -180
  316. package/dist/types/types/util.d.ts +0 -5
  317. package/dist/types/utils/classNames.d.ts +4 -0
  318. package/dist/types/utils/index.d.ts +3 -135
  319. package/dist/types/utils/setUserAgent/constants.d.ts +7 -0
  320. package/dist/types/utils/setUserAgent/index.d.ts +1 -0
  321. package/dist/types/utils/setUserAgent/setUserAgent.d.ts +19 -0
  322. package/dist/types/utils/utils.d.ts +147 -0
  323. package/dist/types/validators/index.d.ts +2 -2
  324. package/package.json +5 -19
  325. package/dist/esm/helpers/authenticator/context.mjs +0 -1
  326. package/dist/esm/helpers/authenticator/formFields/util.mjs +0 -1
  327. package/dist/esm/helpers/storage/fileUploader/utils/uploader.mjs +0 -1
  328. package/dist/esm/machines/authenticator/actors/resetPassword.mjs +0 -1
  329. package/dist/esm/machines/authenticator/signUp.mjs +0 -1
  330. package/dist/esm/theme/tokens/components/expander.mjs +0 -1
  331. package/dist/esm/theme/tokens/components/fileUploader.mjs +0 -1
  332. package/dist/esm/utils/index.mjs +0 -1
  333. package/dist/types/helpers/authenticator/context.d.ts +0 -13
  334. package/dist/types/helpers/storage/fileUploader/index.d.ts +0 -1
  335. package/dist/types/helpers/storage/fileUploader/utils/index.d.ts +0 -1
  336. package/dist/types/helpers/storage/fileUploader/utils/uploader.d.ts +0 -28
  337. package/dist/types/helpers/storage/index.d.ts +0 -1
  338. package/dist/types/theme/tokens/components/expander.d.ts +0 -22
  339. package/dist/types/theme/tokens/components/fileUploader.d.ts +0 -23
  340. package/dist/types/types/authenticator/stateMachine/context.d.ts +0 -109
  341. package/dist/types/types/authenticator/stateMachine/event.d.ts +0 -17
  342. package/dist/types/types/authenticator/stateMachine/index.d.ts +0 -4
  343. package/dist/types/types/authenticator/stateMachine/state.d.ts +0 -10
@@ -0,0 +1,106 @@
1
+ import { createMachine, sendUpdate } from 'xstate';
2
+ import { sendUserAttributeVerificationCode, confirmUserAttribute } from 'aws-amplify/auth';
3
+ import { runValidators } from '../../../validators/index.mjs';
4
+ import ACTIONS from '../actions.mjs';
5
+ import { defaultServices } from '../defaultServices.mjs';
6
+
7
+ function verifyUserAttributesActor() {
8
+ return createMachine({
9
+ id: 'verifyUserAttributesActor',
10
+ initial: 'selectUserAttributes',
11
+ predictableActionArguments: true,
12
+ states: {
13
+ selectUserAttributes: {
14
+ initial: 'edit',
15
+ exit: ['clearError', 'clearTouched', 'sendUpdate'],
16
+ states: {
17
+ edit: {
18
+ entry: 'sendUpdate',
19
+ on: {
20
+ SUBMIT: { actions: 'handleSubmit', target: 'submit' },
21
+ SKIP: { target: '#verifyUserAttributesActor.resolved' },
22
+ CHANGE: { actions: 'handleInput' },
23
+ },
24
+ },
25
+ submit: {
26
+ tags: 'pending',
27
+ entry: ['clearError', 'sendUpdate'],
28
+ invoke: {
29
+ src: 'sendUserAttributeVerificationCode',
30
+ onDone: {
31
+ actions: [
32
+ 'setSelectedUserAttribute',
33
+ 'setCodeDeliveryDetails',
34
+ ],
35
+ target: '#verifyUserAttributesActor.confirmVerifyUserAttribute',
36
+ },
37
+ onError: {
38
+ actions: 'setRemoteError',
39
+ target: 'edit',
40
+ },
41
+ },
42
+ },
43
+ },
44
+ },
45
+ confirmVerifyUserAttribute: {
46
+ initial: 'edit',
47
+ exit: ['clearError', 'clearFormValues', 'clearTouched'],
48
+ states: {
49
+ edit: {
50
+ entry: 'sendUpdate',
51
+ on: {
52
+ SUBMIT: { actions: 'handleSubmit', target: 'submit' },
53
+ SKIP: '#verifyUserAttributesActor.resolved',
54
+ CHANGE: { actions: 'handleInput' },
55
+ },
56
+ },
57
+ submit: {
58
+ tags: 'pending',
59
+ entry: ['clearError', 'sendUpdate'],
60
+ invoke: {
61
+ src: 'confirmVerifyUserAttribute',
62
+ onDone: {
63
+ actions: [
64
+ 'setConfirmAttributeCompleteStep',
65
+ 'clearSelectedUserAttribute',
66
+ ],
67
+ target: '#verifyUserAttributesActor.resolved',
68
+ },
69
+ onError: {
70
+ actions: 'setRemoteError',
71
+ target: 'edit',
72
+ },
73
+ },
74
+ },
75
+ },
76
+ },
77
+ resolved: { type: 'final', data: ({ step }) => ({ step }) },
78
+ },
79
+ }, {
80
+ // sendUpdate is a HOC
81
+ actions: { ...ACTIONS, sendUpdate: sendUpdate() },
82
+ services: {
83
+ sendUserAttributeVerificationCode({ formValues: { unverifiedAttr } }) {
84
+ const input = {
85
+ userAttributeKey: unverifiedAttr,
86
+ };
87
+ return sendUserAttributeVerificationCode(input);
88
+ },
89
+ async confirmVerifyUserAttribute({ formValues: { confirmation_code: confirmationCode }, selectedUserAttribute, }) {
90
+ const input = {
91
+ confirmationCode,
92
+ userAttributeKey: selectedUserAttribute,
93
+ };
94
+ return confirmUserAttribute(input);
95
+ },
96
+ async validateFields(context) {
97
+ return runValidators(context.formValues, context.touched, context.passwordSettings, [
98
+ defaultServices.validateFormPassword,
99
+ defaultServices.validateConfirmPassword,
100
+ ]);
101
+ },
102
+ },
103
+ });
104
+ }
105
+
106
+ export { verifyUserAttributesActor };
@@ -1 +1,102 @@
1
- import{__awaiter as r}from"tslib";import{Amplify as t,Auth as s}from"aws-amplify";import"../../types/authenticator/user.mjs";import"../../types/authenticator/attributes.mjs";import"../../types/primitives/componentClassName.mjs";import"../../i18n/translations.mjs";import{hasSpecialChars as n}from"../../helpers/authenticator/utils.mjs";import"../../helpers/accountSettings/utils.mjs";const o={getAmplifyConfig(){return r(this,void 0,void 0,(function*(){return t.configure()}))},getCurrentUser(){return r(this,void 0,void 0,(function*(){return s.currentAuthenticatedUser()}))},handleSignUp(t){return r(this,void 0,void 0,(function*(){return s.signUp(Object.assign(Object.assign({},t),{autoSignIn:{enabled:!0}}))}))},handleSignIn({username:t,password:n}){return r(this,void 0,void 0,(function*(){return s.signIn(t,n)}))},handleConfirmSignIn({user:t,code:n,mfaType:o}){return r(this,void 0,void 0,(function*(){return s.confirmSignIn(t,n,o)}))},handleConfirmSignUp({username:t,code:n}){return r(this,void 0,void 0,(function*(){return yield s.confirmSignUp(t,n)}))},handleForgotPasswordSubmit({username:t,code:n,password:o}){return r(this,void 0,void 0,(function*(){return s.forgotPasswordSubmit(t,n,o)}))},handleForgotPassword(t){return r(this,void 0,void 0,(function*(){return s.forgotPassword(t)}))},validateCustomSignUp(t,s){return r(this,void 0,void 0,(function*(){}))},validateFormPassword(t,s,o){return r(this,void 0,void 0,(function*(){const{password:r}=t,{password:e}=s;if(!e||!o)return null;const i=[],a=+(null==o?void 0:o.passwordPolicyMinLength);r.length<a&&i.push(`Password must have at least ${a} characters`);const u=null==o?void 0:o.passwordPolicyCharacters;return null==u||u.forEach((t=>{switch(t){case"REQUIRES_LOWERCASE":/[a-z]/.test(r)||i.push("Password must have lower case letters");break;case"REQUIRES_UPPERCASE":/[A-Z]/.test(r)||i.push("Password must have upper case letters");break;case"REQUIRES_NUMBERS":/[0-9]/.test(r)||i.push("Password must have numbers");break;case"REQUIRES_SYMBOLS":n(r)||i.push("Password must have special characters")}})),0!==i.length?{password:i}:null}))},validateConfirmPassword(t,s){return r(this,void 0,void 0,(function*(){const{password:r,confirm_password:n}=t,{confirm_password:o,password:e}=s;return r||n?(r||n)&&r!==n&&(o&&e||(null==r?void 0:r.length)>=6&&(null==n?void 0:n.length)>=6)?{confirm_password:"Your passwords must match"}:void 0:null}))},validatePreferredUsername(t,s){return r(this,void 0,void 0,(function*(){}))}};export{o as defaultServices};
1
+ import { Amplify } from 'aws-amplify';
2
+ import { getCurrentUser, signIn, signUp, confirmSignIn, confirmSignUp, confirmResetPassword, resetPassword } from 'aws-amplify/auth';
3
+ import 'aws-amplify/utils';
4
+ import '@aws-amplify/core/internals/utils';
5
+ import '../../utils/setUserAgent/constants.mjs';
6
+ import '../../types/authenticator/user.mjs';
7
+ import '../../types/authenticator/attributes.mjs';
8
+ import { hasSpecialChars } from '../../helpers/authenticator/utils.mjs';
9
+ import '../../helpers/accountSettings/utils.mjs';
10
+
11
+ // Cognito does not allow a password length less then 8 characters
12
+ const DEFAULT_COGNITO_PASSWORD_MIN_LENGTH = 8;
13
+ const defaultServices = {
14
+ async getAmplifyConfig() {
15
+ const result = Amplify.getConfig();
16
+ const cliConfig = result.Auth?.Cognito;
17
+ const { loginWith, userAttributes } = result.Auth?.Cognito ?? {};
18
+ const parsedLoginMechanisms = loginWith
19
+ ? Object.entries(loginWith)
20
+ .filter(([key, _value]) => key !== 'oauth')
21
+ .filter(([_key, value]) => !!value)
22
+ .map((keyValueArray) => {
23
+ return keyValueArray[0] === 'phone' // the key for phone_number is phone in getConfig but everywhere else we treat is as phone_number
24
+ ? 'phone_number'
25
+ : keyValueArray[0];
26
+ })
27
+ : undefined;
28
+ const parsedSignupAttributes = userAttributes
29
+ ? Object.entries(userAttributes).map(([_key, value]) => Object.keys(value)[0])
30
+ : undefined;
31
+ const parsedSocialProviders = loginWith?.oauth?.providers
32
+ ? loginWith.oauth.providers?.map((provider) => provider.toString().toLowerCase())
33
+ : undefined;
34
+ return {
35
+ ...cliConfig,
36
+ loginMechanisms: parsedLoginMechanisms,
37
+ signUpAttributes: parsedSignupAttributes,
38
+ socialProviders: parsedSocialProviders,
39
+ };
40
+ },
41
+ getCurrentUser,
42
+ handleSignIn: signIn,
43
+ handleSignUp: signUp,
44
+ handleConfirmSignIn: confirmSignIn,
45
+ handleConfirmSignUp: confirmSignUp,
46
+ handleForgotPasswordSubmit: confirmResetPassword,
47
+ handleForgotPassword: resetPassword,
48
+ // Validation hooks for overriding
49
+ async validateCustomSignUp(formData, touchData) { },
50
+ async validateFormPassword(formData, touchData, passwordSettings) {
51
+ const { password } = formData;
52
+ const { password: touched_password } = touchData;
53
+ /**
54
+ * If the password is not touched,
55
+ * or if the password settings are not set, we don't need to validate it.
56
+ */
57
+ if (!touched_password || !passwordSettings)
58
+ return null;
59
+ const password_complexity = [];
60
+ const policyMinLength = passwordSettings.minLength ?? DEFAULT_COGNITO_PASSWORD_MIN_LENGTH;
61
+ if (password.length < policyMinLength) {
62
+ password_complexity.push(`Password must have at least ${policyMinLength} characters`);
63
+ }
64
+ if (passwordSettings.requireLowercase && !/[a-z]/.test(password))
65
+ password_complexity.push('Password must have lower case letters');
66
+ if (passwordSettings.requireUppercase && !/[A-Z]/.test(password))
67
+ password_complexity.push('Password must have upper case letters');
68
+ if (passwordSettings.requireNumbers && !/[0-9]/.test(password))
69
+ password_complexity.push('Password must have numbers');
70
+ // https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-policies.html
71
+ if (passwordSettings.requireSpecialCharacters && !hasSpecialChars(password))
72
+ password_complexity.push('Password must have special characters');
73
+ /**
74
+ * Only return an error if there is at least one error.
75
+ */
76
+ return password_complexity.length !== 0
77
+ ? { password: password_complexity }
78
+ : null;
79
+ },
80
+ async validateConfirmPassword(formData, touchData) {
81
+ const { password, confirm_password } = formData;
82
+ const { confirm_password: touched_confirm_password, password: touched_password, } = touchData;
83
+ if (!password && !confirm_password) {
84
+ // these inputs are clean, don't complain yet
85
+ return null;
86
+ }
87
+ else if ((password || confirm_password) &&
88
+ password !== confirm_password &&
89
+ ((touched_confirm_password && touched_password) ||
90
+ (password?.length >= 6 && confirm_password?.length >= 6))) {
91
+ // Only return an error if both fields have text entered,
92
+ // the passwords do not match, and the fields have been
93
+ // touched or the password and confirm password is longer then or equal to 6.
94
+ return {
95
+ confirm_password: 'Your passwords must match',
96
+ };
97
+ }
98
+ },
99
+ async validatePreferredUsername(formData, touchData) { },
100
+ };
101
+
102
+ export { defaultServices };
@@ -0,0 +1,70 @@
1
+ const SIGN_IN_STEP_MFA_CONFIRMATION = [
2
+ 'CONFIRM_SIGN_IN_WITH_SMS_CODE',
3
+ 'CONFIRM_SIGN_IN_WITH_TOTP_CODE',
4
+ ];
5
+ // response next step guards
6
+ const shouldConfirmSignInWithNewPassword = (_, { data }) => data?.nextStep.signInStep ===
7
+ 'CONFIRM_SIGN_IN_WITH_NEW_PASSWORD_REQUIRED';
8
+ const shouldResetPasswordFromSignIn = (_, { data }) => data?.nextStep?.signInStep === 'RESET_PASSWORD';
9
+ const shouldConfirmSignUpFromSignIn = (_, { data }) => data?.nextStep.signInStep === 'CONFIRM_SIGN_UP';
10
+ const shouldAutoSignIn = (_, { data }) => data?.nextStep.signUpStep === 'COMPLETE_AUTO_SIGN_IN';
11
+ const hasCompletedSignIn = (_, { data }) => data?.nextStep.signInStep === 'DONE';
12
+ const hasCompletedSignUp = (_, { data }) => data?.nextStep.signUpStep === 'DONE';
13
+ const hasCompletedResetPassword = (_, { data }) => data?.nextStep.resetPasswordStep === 'DONE';
14
+ // actor done guards read `step` from actor exit event
15
+ const hasCompletedAttributeConfirmation = (_, { data }) => data?.step === 'CONFIRM_ATTRIBUTE_COMPLETE';
16
+ const isConfirmUserAttributeStep = (_, { data }) => data?.step === 'CONFIRM_ATTRIBUTE_WITH_CODE';
17
+ const isShouldConfirmUserAttributeStep = (_, { data }) => data?.step === 'SHOULD_CONFIRM_USER_ATTRIBUTE';
18
+ const isResetPasswordStep = (_, { data }) => data?.step === 'RESET_PASSWORD';
19
+ const isConfirmSignUpStep = (_, { data }) => data?.step === 'CONFIRM_SIGN_UP';
20
+ // actor entry guards read `step` from actor context
21
+ const shouldConfirmSignIn = ({ step }) => SIGN_IN_STEP_MFA_CONFIRMATION.includes(step);
22
+ const shouldSetupTotp = ({ step }) => step === 'CONTINUE_SIGN_IN_WITH_TOTP_SETUP';
23
+ const shouldResetPassword = ({ step }) => step === 'RESET_PASSWORD';
24
+ const shouldConfirmResetPassword = ({ step }) => step === 'CONFIRM_RESET_PASSWORD_WITH_CODE';
25
+ const shouldConfirmSignUp = ({ step }) => step === 'CONFIRM_SIGN_UP';
26
+ // miscellaneous guards
27
+ const shouldVerifyAttribute = (_, { data }) => {
28
+ const { phone_number_verified, email_verified } = data;
29
+ // email/phone_verified is returned as a string
30
+ const emailNotVerified = email_verified === undefined || email_verified === 'false';
31
+ const phoneNotVerified = phone_number_verified === undefined || phone_number_verified === 'false';
32
+ // only request verification if both email and phone are not verified
33
+ return emailNotVerified && phoneNotVerified;
34
+ };
35
+ /**
36
+ * This guard covers an edge case that exists in the current state of the UI.
37
+ * As of now, our ConfirmSignUp screen only supports showing an input for a
38
+ * confirmation code. However, a Cognito UserPool can instead verify users
39
+ * through a link that gets emailed to them. If a user verifies through the
40
+ * link and then they click on the "Resend Code" button, they will get an error
41
+ * saying that the user has already been confirmed. If we encounter that error,
42
+ * we want to just funnel them through the rest of the flow. In the future, we will
43
+ * want to update our UI to support both confirmation codes and links.
44
+ *
45
+ * https://github.com/aws-amplify/amplify-ui/issues/219
46
+ */
47
+ const isUserAlreadyConfirmed = (_, { data }) => data.message === 'User is already confirmed.';
48
+ const GUARDS = {
49
+ hasCompletedAttributeConfirmation,
50
+ hasCompletedResetPassword,
51
+ hasCompletedSignIn,
52
+ hasCompletedSignUp,
53
+ isConfirmSignUpStep,
54
+ isConfirmUserAttributeStep,
55
+ isResetPasswordStep,
56
+ isShouldConfirmUserAttributeStep,
57
+ isUserAlreadyConfirmed,
58
+ shouldAutoSignIn,
59
+ shouldConfirmResetPassword,
60
+ shouldConfirmSignIn,
61
+ shouldConfirmSignInWithNewPassword,
62
+ shouldConfirmSignUp,
63
+ shouldConfirmSignUpFromSignIn,
64
+ shouldResetPassword,
65
+ shouldResetPasswordFromSignIn,
66
+ shouldSetupTotp,
67
+ shouldVerifyAttribute,
68
+ };
69
+
70
+ export { GUARDS as default };
@@ -1 +1,368 @@
1
- import{__rest as t}from"tslib";import{createMachine as o,forwardTo as i,assign as n,spawn as e,actions as r}from"xstate";import{stopActor as s}from"./actions.mjs";import{signInActor as a}from"./actors/signIn.mjs";import{signOutActor as c}from"./actors/signOut.mjs";import{resetPasswordActor as d}from"./actors/resetPassword.mjs";import{defaultServices as u}from"./defaultServices.mjs";import{createSignUpMachine as l}from"./signUp.mjs";const{choose:g}=r;function v(){return o({id:"authenticator",initial:"idle",context:{user:void 0,config:{},services:u,actorRef:void 0,hasSetup:!1},predictableActionArguments:!0,states:{idle:{invoke:{src:"getCurrentUser",onDone:{actions:"setUser",target:"authenticated"},onError:{target:"setup"}}},setup:{initial:"waitConfig",states:{waitConfig:{on:{INIT:{actions:["configure","setHasSetup"],target:"applyConfig"}}},applyConfig:{invoke:{src:"getAmplifyConfig",onDone:{actions:"applyAmplifyConfig",target:"goToInitialState"}}},goToInitialState:{always:[{target:"#authenticator.signUp",cond:"isInitialStateSignUp"},{target:"#authenticator.resetPassword",cond:"isInitialStateResetPassword"},{target:"#authenticator.signIn"}]}}},signIn:{initial:"spawnActor",states:{spawnActor:{always:{actions:"spawnSignInActor",target:"runActor"}},runActor:{entry:"clearActorDoneData",exit:"stopSignInActor"}},on:{SIGN_UP:"signUp",RESET_PASSWORD:"resetPassword","done.invoke.signInActor":[{target:"signUp",actions:"setActorDoneData",cond:"shouldRedirectToSignUp"},{target:"resetPassword",actions:"setActorDoneData",cond:"shouldRedirectToResetPassword"},{target:"authenticated",actions:"setActorDoneData"}]}},signUp:{initial:"spawnActor",states:{spawnActor:{always:{actions:"spawnSignUpActor",target:"runActor"}},runActor:{entry:"clearActorDoneData",exit:"stopSignUpActor"},autoSignIn:{invoke:{src:"getCurrentUser",onDone:"#authenticator.authenticated",onError:"#authenticator.setup.goToInitialState"}}},on:{SIGN_IN:"signIn","done.invoke.signUpActor":{target:"#authenticator.signIn",actions:"setActorDoneData",cond:"shouldAutoSignIn"}}},resetPassword:{initial:"spawnActor",states:{spawnActor:{always:{actions:"spawnResetPasswordActor",target:"runActor"}},runActor:{entry:"clearActorDoneData",exit:"stopResetPasswordActor"}},on:{SIGN_IN:"signIn","done.invoke.resetPasswordActor":{target:"signIn",actions:"setActorDoneData"}}},signOut:{initial:"spawnActor",states:{spawnActor:{always:{actions:"spawnSignOutActor",target:"runActor"}},runActor:{entry:"clearActorDoneData",exit:["stopSignOutActor","clearUser"]}},on:{"done.invoke.signOutActor":[{target:"setup",cond:"shouldSetup"},{target:"setup.goToInitialState"}]}},authenticated:{initial:"idle",states:{idle:{on:{TOKEN_REFRESH:"refreshUser"}},refreshUser:{invoke:{src:"getCurrentUser",onDone:{actions:"setUser",target:"idle"},onError:{target:"#authenticator.signOut"}}}},on:{SIGN_OUT:"signOut"}}},on:{CHANGE:{actions:"forwardToActor"},BLUR:{actions:"forwardToActor"},SUBMIT:{actions:"forwardToActor"},FEDERATED_SIGN_IN:{actions:"forwardToActor"},AUTO_SIGN_IN:{actions:"forwardToActor"},RESEND:{actions:"forwardToActor"},SIGN_IN:{actions:"forwardToActor"},SKIP:{actions:"forwardToActor"}}},{actions:{forwardToActor:g([{cond:"hasActor",actions:i((t=>t.actorRef))}]),setUser:n({user:(t,o)=>o.data}),setActorDoneData:n({actorDoneData:(t,o)=>{var i,n;return{authAttributes:Object.assign({},null===(i=o.data)||void 0===i?void 0:i.authAttributes),intent:null===(n=o.data)||void 0===n?void 0:n.intent}},user:(t,o)=>{var i;return null===(i=o.data)||void 0===i?void 0:i.user}}),clearUser:n({user:void 0}),clearActorDoneData:n({actorDoneData:void 0}),applyAmplifyConfig:n({config(t,o){var i,n,e,r,s,a,c,d,u;const l=null!==(n=null===(i=o.data.aws_cognito_username_attributes)||void 0===i?void 0:i.map((t=>t.toLowerCase())))&&void 0!==n?n:[],g=null!==(r=null===(e=o.data.aws_cognito_verification_mechanisms)||void 0===e?void 0:e.map((t=>t.toLowerCase())))&&void 0!==r?r:[],v=null!==(a=null===(s=o.data.aws_cognito_signup_attributes)||void 0===s?void 0:s.map((t=>t.toLowerCase())))&&void 0!==a?a:[],A=null!==(d=null===(c=o.data.aws_cognito_social_providers)||void 0===c?void 0:c.map((t=>t.toLowerCase())))&&void 0!==d?d:[],f=o.data.aws_cognito_password_protection_settings||{};0===l.length&&l.push("username");const{loginMechanisms:w,signUpAttributes:S,socialProviders:m,initialState:h,formFields:D}=t.config;return{loginMechanisms:null!=w?w:l,formFields:null!==(u=p(D))&&void 0!==u?u:{},passwordSettings:f,signUpAttributes:null!=S?S:Array.from(new Set([...g,...v])),socialProviders:null!=m?m:A.sort(),initialState:h}}}),spawnSignInActor:n({actorRef:(t,o)=>{var i,n,r,s,c,d,u;const{services:l}=t,g=a({services:l}).withContext({authAttributes:null!==(n=null===(i=t.actorDoneData)||void 0===i?void 0:i.authAttributes)&&void 0!==n?n:{},user:t.user,intent:null===(r=t.actorDoneData)||void 0===r?void 0:r.intent,country_code:"+1",formValues:{},touched:{},validationError:{},passwordSettings:null===(s=t.config)||void 0===s?void 0:s.passwordSettings,loginMechanisms:null===(c=t.config)||void 0===c?void 0:c.loginMechanisms,socialProviders:null===(d=t.config)||void 0===d?void 0:d.socialProviders,formFields:null===(u=t.config)||void 0===u?void 0:u.formFields});return e(g,{name:"signInActor"})}}),spawnSignUpActor:n({actorRef:(t,o)=>{var i,n,r,s,a,c,d;const{services:u}=t,g=l({services:u}).withContext({authAttributes:null!==(n=null===(i=t.actorDoneData)||void 0===i?void 0:i.authAttributes)&&void 0!==n?n:{},country_code:"+1",intent:null===(r=t.actorDoneData)||void 0===r?void 0:r.intent,formValues:{},touched:{},validationError:{},loginMechanisms:null===(s=t.config)||void 0===s?void 0:s.loginMechanisms,socialProviders:null===(a=t.config)||void 0===a?void 0:a.socialProviders,formFields:null===(c=t.config)||void 0===c?void 0:c.formFields,passwordSettings:null===(d=t.config)||void 0===d?void 0:d.passwordSettings});return e(g,{name:"signUpActor"})}}),spawnResetPasswordActor:n({actorRef:(t,o)=>{var i,n,r,s,a;const{services:c}=t,u=d({services:c}).withContext({formValues:{},touched:{},intent:null===(i=t.actorDoneData)||void 0===i?void 0:i.intent,username:null===(r=null===(n=t.actorDoneData)||void 0===n?void 0:n.authAttributes)||void 0===r?void 0:r.username,formFields:null===(s=t.config)||void 0===s?void 0:s.formFields,validationError:{},passwordSettings:null===(a=t.config)||void 0===a?void 0:a.passwordSettings});return e(u,{name:"resetPasswordActor"})}}),spawnSignOutActor:n({actorRef:t=>{const o=c.withContext({user:t.user});return e(o,{name:"signOutActor"})}}),stopSignInActor:s("signInActor"),stopSignUpActor:s("signUpActor"),stopResetPasswordActor:s("resetPasswordActor"),stopSignOutActor:s("signOutActor"),configure:n(((o,i)=>{const n=i.data,{services:e}=n,r=t(n,["services"]);return{services:Object.assign(Object.assign({},u),e),config:r}})),setHasSetup:n({hasSetup:!0})},guards:{isInitialStateSignUp:t=>"signUp"===t.config.initialState,isInitialStateResetPassword:t=>"resetPassword"===t.config.initialState,shouldRedirectToSignUp:(t,o)=>{var i;return"confirmSignUp"===(null===(i=o.data)||void 0===i?void 0:i.intent)},shouldRedirectToResetPassword:(t,o)=>{var i;return"confirmPasswordReset"===(null===(i=o.data)||void 0===i?void 0:i.intent)},shouldAutoSignIn:(t,o)=>{var i,n;return"autoSignIn"===(null===(i=o.data)||void 0===i?void 0:i.intent)||"autoSignInSubmit"===(null===(n=o.data)||void 0===n?void 0:n.intent)},shouldSetup:t=>!1===t.hasSetup,hasActor:t=>!!t.actorRef},services:{getCurrentUser:(t,o)=>t.services.getCurrentUser(),getAmplifyConfig:(t,o)=>t.services.getAmplifyConfig()}})}function p(t){return t&&Object.keys(t).forEach((o=>{Object.keys(t[o]).forEach((i=>{let n=t[o][i];n.required=n.isRequired}))})),t}export{v as createAuthenticatorMachine};
1
+ import { createMachine, forwardTo, assign, spawn, actions } from 'xstate';
2
+ import '@aws-amplify/core/internals/utils';
3
+ import '../../utils/setUserAgent/constants.mjs';
4
+ import { isEmptyObject } from '../../utils/utils.mjs';
5
+ import ACTIONS from './actions.mjs';
6
+ import GUARDS from './guards.mjs';
7
+ import { forgotPasswordActor } from './actors/forgotPassword.mjs';
8
+ import { signInActor } from './actors/signIn.mjs';
9
+ import { signUpActor } from './actors/signUp.mjs';
10
+ import { signOutActor } from './actors/signOut.mjs';
11
+ import { verifyUserAttributesActor } from './actors/verifyUserAttributes.mjs';
12
+ import { defaultServices } from './defaultServices.mjs';
13
+
14
+ const getActorContext = (context, defaultStep) => ({
15
+ ...context.actorDoneData,
16
+ step: context?.actorDoneData?.step ?? defaultStep,
17
+ // initialize empty objects on actor start
18
+ formValues: {},
19
+ touched: {},
20
+ validationError: {},
21
+ // values included on `context.config` that should be available in actors
22
+ formFields: context.config?.formFields,
23
+ loginMechanisms: context.config?.loginMechanisms,
24
+ passwordSettings: context.config?.passwordSettings,
25
+ signUpAttributes: context.config?.signUpAttributes,
26
+ socialProviders: context.config?.socialProviders,
27
+ });
28
+ const { choose, stop } = actions;
29
+ const stopActor = (machineId) => stop(machineId);
30
+ // setup step waits for ui to emit INIT action to proceed to configure
31
+ const LEGACY_WAIT_CONFIG = {
32
+ on: {
33
+ INIT: {
34
+ actions: ['configure'],
35
+ target: 'getConfig',
36
+ },
37
+ },
38
+ };
39
+ // setup step proceeds directly to configure
40
+ const NEXT_WAIT_CONFIG = {
41
+ always: { actions: ['configure'], target: 'getConfig' },
42
+ };
43
+ function createAuthenticatorMachine(options) {
44
+ const { useNextWaitConfig, ...overrideConfigServices } = options ?? {};
45
+ const initConfig = useNextWaitConfig ? NEXT_WAIT_CONFIG : LEGACY_WAIT_CONFIG;
46
+ return createMachine({
47
+ id: 'authenticator',
48
+ initial: 'idle',
49
+ context: {
50
+ user: undefined,
51
+ config: {},
52
+ services: defaultServices,
53
+ actorRef: undefined,
54
+ hasSetup: false,
55
+ },
56
+ predictableActionArguments: true,
57
+ states: {
58
+ // See: https://xstate.js.org/docs/guides/communication.html#invoking-promises
59
+ idle: {
60
+ invoke: {
61
+ src: 'handleGetCurrentUser',
62
+ onDone: { actions: 'setUser', target: 'authenticated' },
63
+ onError: { target: 'setup' },
64
+ },
65
+ },
66
+ setup: {
67
+ initial: 'initConfig',
68
+ states: {
69
+ initConfig,
70
+ getConfig: {
71
+ invoke: {
72
+ src: 'getAmplifyConfig',
73
+ onDone: {
74
+ actions: ['applyAmplifyConfig', 'setHasSetup'],
75
+ target: 'goToInitialState',
76
+ },
77
+ },
78
+ },
79
+ goToInitialState: {
80
+ always: [
81
+ {
82
+ cond: 'isInitialStateSignUp',
83
+ target: '#authenticator.signUpActor',
84
+ },
85
+ {
86
+ cond: 'isInitialStateResetPassword',
87
+ target: '#authenticator.forgotPasswordActor',
88
+ },
89
+ { target: '#authenticator.signInActor' },
90
+ ],
91
+ },
92
+ },
93
+ },
94
+ getCurrentUser: {
95
+ invoke: {
96
+ src: 'handleGetCurrentUser',
97
+ onDone: {
98
+ actions: 'setUser',
99
+ target: '#authenticator.authenticated',
100
+ },
101
+ onError: { target: '#authenticator.setup' },
102
+ },
103
+ },
104
+ signInActor: {
105
+ initial: 'spawnActor',
106
+ states: {
107
+ spawnActor: {
108
+ always: { actions: 'spawnSignInActor', target: 'runActor' },
109
+ },
110
+ runActor: {
111
+ entry: 'clearActorDoneData',
112
+ exit: stopActor('signInActor'),
113
+ },
114
+ },
115
+ on: {
116
+ FORGOT_PASSWORD: 'forgotPasswordActor',
117
+ SIGN_IN: 'signInActor',
118
+ SIGN_UP: 'signUpActor',
119
+ 'done.invoke.signInActor': [
120
+ {
121
+ cond: 'hasCompletedAttributeConfirmation',
122
+ target: '#authenticator.getCurrentUser',
123
+ },
124
+ {
125
+ cond: 'isShouldConfirmUserAttributeStep',
126
+ actions: 'setActorDoneData',
127
+ target: '#authenticator.verifyUserAttributesActor',
128
+ },
129
+ {
130
+ cond: 'isResetPasswordStep',
131
+ actions: 'setActorDoneData',
132
+ target: '#authenticator.forgotPasswordActor',
133
+ },
134
+ {
135
+ cond: 'isConfirmSignUpStep',
136
+ actions: 'setActorDoneData',
137
+ target: '#authenticator.signUpActor',
138
+ },
139
+ ],
140
+ },
141
+ },
142
+ signUpActor: {
143
+ initial: 'spawnActor',
144
+ states: {
145
+ spawnActor: {
146
+ always: { actions: 'spawnSignUpActor', target: 'runActor' },
147
+ },
148
+ runActor: {
149
+ entry: 'clearActorDoneData',
150
+ exit: stopActor('signUpActor'),
151
+ },
152
+ },
153
+ on: {
154
+ SIGN_IN: 'signInActor',
155
+ 'done.invoke.signUpActor': [
156
+ {
157
+ cond: 'hasCompletedAttributeConfirmation',
158
+ target: '#authenticator.getCurrentUser',
159
+ },
160
+ {
161
+ cond: 'isConfirmUserAttributeStep',
162
+ target: '#authenticator.verifyUserAttributesActor',
163
+ },
164
+ {
165
+ actions: 'setActorDoneData',
166
+ target: '#authenticator.signInActor',
167
+ },
168
+ ],
169
+ },
170
+ },
171
+ forgotPasswordActor: {
172
+ initial: 'spawnActor',
173
+ states: {
174
+ spawnActor: {
175
+ always: {
176
+ actions: 'spawnForgotPasswordActor',
177
+ target: 'runActor',
178
+ },
179
+ },
180
+ runActor: {
181
+ entry: 'clearActorDoneData',
182
+ exit: stopActor('forgotPasswordActor'),
183
+ },
184
+ },
185
+ on: {
186
+ SIGN_IN: 'signInActor',
187
+ 'done.invoke.forgotPasswordActor': [
188
+ { target: '#authenticator.signInActor' },
189
+ ],
190
+ },
191
+ },
192
+ verifyUserAttributesActor: {
193
+ initial: 'spawnActor',
194
+ states: {
195
+ spawnActor: {
196
+ always: {
197
+ actions: 'spawnVerifyUserAttributesActor',
198
+ target: 'runActor',
199
+ },
200
+ },
201
+ runActor: {
202
+ entry: 'clearActorDoneData',
203
+ exit: stopActor('verifyUserAttributesActor'),
204
+ },
205
+ },
206
+ on: {
207
+ 'done.invoke.verifyUserAttributesActor': [
208
+ {
209
+ actions: 'setActorDoneData',
210
+ target: '#authenticator.getCurrentUser',
211
+ },
212
+ ],
213
+ },
214
+ },
215
+ authenticated: {
216
+ initial: 'idle',
217
+ states: {
218
+ idle: { on: { TOKEN_REFRESH: 'refreshUser' } },
219
+ refreshUser: {
220
+ invoke: {
221
+ src: '#authenticator.getCurrentUser',
222
+ onDone: { actions: 'setUser', target: 'idle' },
223
+ onError: { target: '#authenticator.signOut' },
224
+ },
225
+ },
226
+ },
227
+ on: { SIGN_OUT: 'signOut' },
228
+ },
229
+ signOut: {
230
+ initial: 'spawnActor',
231
+ states: {
232
+ spawnActor: {
233
+ always: {
234
+ actions: 'spawnSignOutActor',
235
+ target: 'runActor',
236
+ },
237
+ },
238
+ runActor: {
239
+ entry: 'clearActorDoneData',
240
+ exit: stopActor('signOutActor'),
241
+ },
242
+ },
243
+ on: {
244
+ 'done.invoke.signOutActor': {
245
+ actions: 'clearUser',
246
+ target: 'setup.getConfig',
247
+ },
248
+ },
249
+ },
250
+ },
251
+ on: {
252
+ SIGN_IN_WITH_REDIRECT: { target: '#authenticator.getCurrentUser' },
253
+ CHANGE: { actions: 'forwardToActor' },
254
+ BLUR: { actions: 'forwardToActor' },
255
+ SUBMIT: { actions: 'forwardToActor' },
256
+ FEDERATED_SIGN_IN: { actions: 'forwardToActor' },
257
+ RESEND: { actions: 'forwardToActor' },
258
+ SIGN_IN: { actions: 'forwardToActor' },
259
+ SKIP: { actions: 'forwardToActor' },
260
+ },
261
+ }, {
262
+ actions: {
263
+ ...ACTIONS,
264
+ forwardToActor: choose([
265
+ { cond: 'hasActor', actions: forwardTo(({ actorRef }) => actorRef) },
266
+ ]),
267
+ setActorDoneData: assign({
268
+ actorDoneData: (context, event) => ({
269
+ codeDeliveryDetails: event.data.codeDeliveryDetails,
270
+ missingAttributes: event.data.missingAttributes,
271
+ remoteError: event.data.remoteError,
272
+ username: event.data.username,
273
+ step: event.data.step,
274
+ totpSecretCode: event.data.totpSecretCode,
275
+ unverifiedUserAttributes: event.data.unverifiedUserAttributes,
276
+ }),
277
+ }),
278
+ applyAmplifyConfig: assign({
279
+ config(context, { data: cliConfig }) {
280
+ // Prefer explicitly configured settings over default CLI values\
281
+ const { loginMechanisms = cliConfig.loginMechanisms ?? [], signUpAttributes = cliConfig.signUpAttributes ?? [], socialProviders = cliConfig.socialProviders ?? [], initialState, formFields: _formFields, passwordSettings = cliConfig.passwordFormat ??
282
+ {}, } = context.config;
283
+ // By default, Cognito assumes `username`, so there isn't a different username attribute like `email`.
284
+ // We explicitly add it as a login mechanism to be consistent with Admin UI's language.
285
+ if (loginMechanisms.length === 0) {
286
+ loginMechanisms.push('username');
287
+ }
288
+ const formFields = convertFormFields(_formFields) ?? {};
289
+ return {
290
+ formFields,
291
+ initialState,
292
+ loginMechanisms,
293
+ passwordSettings,
294
+ signUpAttributes,
295
+ socialProviders,
296
+ };
297
+ },
298
+ }),
299
+ spawnSignInActor: assign({
300
+ actorRef: (context, _) => {
301
+ const { services } = context;
302
+ const actor = signInActor({ services }).withContext(getActorContext(context, 'SIGN_IN'));
303
+ return spawn(actor, { name: 'signInActor' });
304
+ },
305
+ }),
306
+ spawnSignUpActor: assign({
307
+ actorRef: (context, _) => {
308
+ const { services } = context;
309
+ const actor = signUpActor({ services }).withContext(getActorContext(context, 'SIGN_UP'));
310
+ return spawn(actor, { name: 'signUpActor' });
311
+ },
312
+ }),
313
+ spawnForgotPasswordActor: assign({
314
+ actorRef: (context, _) => {
315
+ const { services } = context;
316
+ const actor = forgotPasswordActor({ services }).withContext(getActorContext(context, 'FORGOT_PASSWORD'));
317
+ return spawn(actor, { name: 'forgotPasswordActor' });
318
+ },
319
+ }),
320
+ spawnVerifyUserAttributesActor: assign({
321
+ actorRef: (context) => {
322
+ const actor = verifyUserAttributesActor().withContext(getActorContext(context));
323
+ return spawn(actor, { name: 'verifyUserAttributesActor' });
324
+ },
325
+ }),
326
+ spawnSignOutActor: assign({
327
+ actorRef: (context) => {
328
+ const actor = signOutActor().withContext({ user: context?.user });
329
+ return spawn(actor, { name: 'signOutActor' });
330
+ },
331
+ }),
332
+ configure: assign((_, event) => {
333
+ const { services: customServices, ...config } = !isEmptyObject(overrideConfigServices)
334
+ ? overrideConfigServices
335
+ : event.data;
336
+ return {
337
+ services: { ...defaultServices, ...customServices },
338
+ config,
339
+ };
340
+ }),
341
+ setHasSetup: assign({ hasSetup: true }),
342
+ },
343
+ guards: {
344
+ ...GUARDS,
345
+ hasActor: ({ actorRef }) => !!actorRef,
346
+ isInitialStateSignUp: ({ config }) => config.initialState === 'signUp',
347
+ isInitialStateResetPassword: ({ config }) => config.initialState === 'forgotPassword',
348
+ shouldSetup: ({ hasSetup }) => !hasSetup,
349
+ },
350
+ services: {
351
+ getAmplifyConfig: ({ services }) => services.getAmplifyConfig(),
352
+ handleGetCurrentUser: ({ services }) => services.getCurrentUser(),
353
+ },
354
+ });
355
+ }
356
+ function convertFormFields(formFields) {
357
+ if (formFields) {
358
+ Object.keys(formFields).forEach((component) => {
359
+ Object.keys(formFields[component]).forEach((inputName) => {
360
+ let ff = formFields[component][inputName];
361
+ ff.required = ff.isRequired;
362
+ });
363
+ });
364
+ }
365
+ return formFields;
366
+ }
367
+
368
+ export { createAuthenticatorMachine };