@dloizides/auth-web 1.22.0 → 1.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -575,6 +575,12 @@ function useAuthStyles(theme) {
575
575
  marginTop: spacing.xs,
576
576
  color: colors.danger
577
577
  },
578
+ errorBody: {
579
+ fontSize: typography.body,
580
+ marginTop: spacing.xs,
581
+ marginBottom: spacing.md,
582
+ color: colors.danger
583
+ },
578
584
  successText: {
579
585
  fontSize: typography.body,
580
586
  lineHeight: typography.body * 1.4,
@@ -4672,6 +4678,11 @@ function createBffChangePasswordClient(options = {}) {
4672
4678
  }
4673
4679
  };
4674
4680
  }
4681
+ function useFocusOnMount(ref) {
4682
+ useEffect(() => {
4683
+ ref.current?.focus();
4684
+ }, [ref]);
4685
+ }
4675
4686
  function useResendVerification({ client, verifyUrlTemplate }) {
4676
4687
  const [email, setEmail] = useState("");
4677
4688
  const [missingEmail, setMissingEmail] = useState(false);
@@ -4691,6 +4702,11 @@ function useResendVerification({ client, verifyUrlTemplate }) {
4691
4702
  }, [client, email, verifyUrlTemplate]);
4692
4703
  return { email, setEmail, missingEmail, submitting, confirmed, submit };
4693
4704
  }
4705
+ function ResendConfirmation({ style, testID, text }) {
4706
+ const ref = useRef(null);
4707
+ useFocusOnMount(ref);
4708
+ return /* @__PURE__ */ jsx(View, { ref, accessible: true, accessibilityLiveRegion: "polite", focusable: true, testID, children: /* @__PURE__ */ jsx(Text, { style, children: text }) });
4709
+ }
4694
4710
  function VerifyEmailResendForm({
4695
4711
  client,
4696
4712
  labels,
@@ -4702,7 +4718,7 @@ function VerifyEmailResendForm({
4702
4718
  const resend = useResendVerification({ client, verifyUrlTemplate });
4703
4719
  const id = (base) => withTestIdPrefix(base, testIdPrefix);
4704
4720
  if (resend.confirmed) {
4705
- return /* @__PURE__ */ jsx(Text, { style: styles3.successText, testID: id(AuthTestIds.verifyEmailResendConfirmation), children: labels.resendConfirmation });
4721
+ return /* @__PURE__ */ jsx(ResendConfirmation, { style: styles3.successText, testID: id(AuthTestIds.verifyEmailResendConfirmation), text: labels.resendConfirmation });
4706
4722
  }
4707
4723
  const submit = () => {
4708
4724
  void resend.submit();
@@ -4731,7 +4747,7 @@ function VerifyEmailResendForm({
4731
4747
  }
4732
4748
  )
4733
4749
  ] }),
4734
- resend.missingEmail ? /* @__PURE__ */ jsx(Text, { style: styles3.errorText, children: labels.resendMissingEmail }) : null,
4750
+ resend.missingEmail ? /* @__PURE__ */ jsx(Text, { style: styles3.errorBody, children: labels.resendMissingEmail }) : null,
4735
4751
  /* @__PURE__ */ jsx(
4736
4752
  TouchableOpacity,
4737
4753
  {
@@ -4828,6 +4844,23 @@ function verifyEmailErrorText(code, labels) {
4828
4844
  }
4829
4845
  return labels.errorGeneric;
4830
4846
  }
4847
+ function ResendCta({ label, hint, style, textStyle, testID, onPress }) {
4848
+ const ref = useRef(null);
4849
+ useFocusOnMount(ref);
4850
+ return /* @__PURE__ */ jsx(
4851
+ TouchableOpacity,
4852
+ {
4853
+ ref,
4854
+ accessibilityHint: hint,
4855
+ accessibilityLabel: label,
4856
+ accessibilityRole: "button",
4857
+ style,
4858
+ testID,
4859
+ onPress,
4860
+ children: /* @__PURE__ */ jsx(Text, { style: textStyle, children: label })
4861
+ }
4862
+ );
4863
+ }
4831
4864
  function VerifyEmailScreen({
4832
4865
  client,
4833
4866
  token,
@@ -4873,7 +4906,7 @@ function VerifyEmailScreen({
4873
4906
  ] }) : null,
4874
4907
  phase === "failure" /* Failure */ ? /* @__PURE__ */ jsxs(View, { testID: id(AuthTestIds.verifyEmailError), children: [
4875
4908
  /* @__PURE__ */ jsx(Text, { accessibilityRole: "header", style: styles3.title, children: labels.errorTitle }),
4876
- /* @__PURE__ */ jsx(Text, { style: styles3.errorText, children: verifyEmailErrorText(errorCode, labels) }),
4909
+ /* @__PURE__ */ jsx(Text, { style: styles3.errorBody, children: verifyEmailErrorText(errorCode, labels) }),
4877
4910
  resendOpen ? /* @__PURE__ */ jsx(
4878
4911
  VerifyEmailResendForm,
4879
4912
  {
@@ -4885,15 +4918,14 @@ function VerifyEmailScreen({
4885
4918
  verifyUrlTemplate
4886
4919
  }
4887
4920
  ) : /* @__PURE__ */ jsx(
4888
- TouchableOpacity,
4921
+ ResendCta,
4889
4922
  {
4890
- accessibilityHint: labels.resendCtaHint,
4891
- accessibilityLabel: labels.resendCta,
4892
- accessibilityRole: "button",
4923
+ hint: labels.resendCtaHint,
4924
+ label: labels.resendCta,
4893
4925
  style: styles3.primaryButton,
4894
4926
  testID: id(AuthTestIds.verifyEmailResendCta),
4895
- onPress: openResend,
4896
- children: /* @__PURE__ */ jsx(Text, { style: styles3.primaryButtonText, children: labels.resendCta })
4927
+ textStyle: styles3.primaryButtonText,
4928
+ onPress: openResend
4897
4929
  }
4898
4930
  )
4899
4931
  ] }) : null
@@ -4911,6 +4943,9 @@ var SERVER_ERROR_CODES2 = [
4911
4943
  "KEYCLOAK_UPDATE_FAILED" /* KeycloakUpdateFailed */
4912
4944
  ];
4913
4945
  var GENERIC_FAILURE = { success: false, errorCode: "GENERIC" /* Generic */ };
4946
+ var INVALID_TOKEN = { success: false, errorCode: "TOKEN_INVALID" /* TokenInvalid */ };
4947
+ var HTTP_BAD_REQUEST3 = 400;
4948
+ var TOKEN_FIELD = "token";
4914
4949
  async function lazyFetchHttpClient3(request) {
4915
4950
  const fetchImpl = typeof fetch === "function" ? fetch.bind(globalThis) : void 0;
4916
4951
  if (fetchImpl === void 0) {
@@ -4924,14 +4959,23 @@ function isServerErrorCode(value) {
4924
4959
  function isRecord3(value) {
4925
4960
  return typeof value === "object" && value !== null;
4926
4961
  }
4927
- function decodeVerifyResponse(body) {
4962
+ function isTokenValidationRejection(status, body) {
4963
+ if (status !== HTTP_BAD_REQUEST3 || !isRecord3(body.errors)) {
4964
+ return false;
4965
+ }
4966
+ return Object.keys(body.errors).some((field2) => field2.toLowerCase() === TOKEN_FIELD);
4967
+ }
4968
+ function decodeVerifyResponse(status, body) {
4928
4969
  if (!isRecord3(body)) {
4929
4970
  return GENERIC_FAILURE;
4930
4971
  }
4931
4972
  if (body.success === true) {
4932
4973
  return { success: true };
4933
4974
  }
4934
- return isServerErrorCode(body.errorCode) ? { success: false, errorCode: body.errorCode } : GENERIC_FAILURE;
4975
+ if (isServerErrorCode(body.errorCode)) {
4976
+ return { success: false, errorCode: body.errorCode };
4977
+ }
4978
+ return isTokenValidationRejection(status, body) ? INVALID_TOKEN : GENERIC_FAILURE;
4935
4979
  }
4936
4980
  function createBffVerifyEmailClient(options = {}) {
4937
4981
  const http = options.http ?? lazyFetchHttpClient3;
@@ -4947,7 +4991,7 @@ function createBffVerifyEmailClient(options = {}) {
4947
4991
  verifyEmail: async (token) => {
4948
4992
  try {
4949
4993
  const response = await post(VERIFY_EMAIL_ENDPOINT, { token });
4950
- return decodeVerifyResponse(response.data);
4994
+ return decodeVerifyResponse(response.status, response.data);
4951
4995
  } catch {
4952
4996
  return GENERIC_FAILURE;
4953
4997
  }