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