@dloizides/auth-web 1.23.0 → 1.24.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.
package/dist/index.mjs CHANGED
@@ -397,6 +397,45 @@ var DEFAULT_VERIFY_EMAIL_LABELS = {
397
397
  signIn: DEFAULT_VERIFY_SIGN_IN_LABELS
398
398
  };
399
399
 
400
+ // src/components/labels/accountDeletionLabels.ts
401
+ var DEFAULT_ACCOUNT_DELETION_LABELS = {
402
+ title: "Delete your account",
403
+ subtitle: "We email you a link to confirm. Nothing is deleted until you open it.",
404
+ reason: {
405
+ label: "Reason (optional)",
406
+ placeholder: "Why are you leaving?",
407
+ hint: "Optional reason for deleting your account",
408
+ inputLabel: "Reason for deleting your account"
409
+ },
410
+ submit: "Request account deletion",
411
+ submitHint: "Emails you a link to confirm the deletion",
412
+ submitting: "Sending the request",
413
+ stepUpTitle: "Confirm your password",
414
+ stepUpSubtitle: "You signed in a while ago. Enter your password to continue.",
415
+ password: {
416
+ label: "Password",
417
+ placeholder: "Your password",
418
+ hint: "Your current password",
419
+ inputLabel: "Password"
420
+ },
421
+ stepUpSubmit: "Confirm and continue",
422
+ stepUpSubmitHint: "Checks your password, then sends the deletion request",
423
+ checkEmailTitle: "Check your email",
424
+ checkEmailBody: "Open the link we sent you to confirm. Your account stays active until then.",
425
+ emailNotSentTitle: "We could not send the email",
426
+ emailNotSentBody: "Your request is recorded, but the confirmation email did not go out. Contact support to finish it.",
427
+ scheduledDate: "Scheduled deletion date: {date}",
428
+ alreadyRequestedTitle: "Deletion already requested",
429
+ alreadyRequestedBody: "Look for the confirmation link in your email. You do not need to ask again.",
430
+ errorPasswordRequired: "Enter your password.",
431
+ errorWrongPassword: "That password is not correct.",
432
+ errorSignInRequired: "Your session ended. Sign in and try again.",
433
+ errorRateLimited: "Too many attempts. Wait a moment and try again.",
434
+ errorRateLimitedSeconds: "Too many attempts. Try again in {seconds} seconds.",
435
+ errorRetryLater: "We could not reach the account service. Try again later.",
436
+ errorFailed: "Something went wrong. Try again."
437
+ };
438
+
400
439
  // src/components/testIds.ts
401
440
  var AuthTestIds = {
402
441
  loginForm: "auth-login-form",
@@ -679,7 +718,7 @@ function useLoginSubmit({
679
718
  missingFieldsLabel,
680
719
  invalidCredentialsLabel
681
720
  }) {
682
- const [errorText, setErrorText] = useState(null);
721
+ const [errorText2, setErrorText] = useState(null);
683
722
  const inFlight = useRef(false);
684
723
  const runLogin = useCallback(async () => {
685
724
  if (inFlight.current) {
@@ -705,7 +744,7 @@ function useLoginSubmit({
705
744
  const handleSubmit = useCallback(() => {
706
745
  void runLogin();
707
746
  }, [runLogin]);
708
- return { errorText, handleSubmit };
747
+ return { errorText: errorText2, handleSubmit };
709
748
  }
710
749
  function isKeyRepeat(event) {
711
750
  const native = event?.nativeEvent;
@@ -865,7 +904,7 @@ function LoginForm({
865
904
  prefillNonce,
866
905
  prefillIntent
867
906
  });
868
- const { errorText, handleSubmit } = useLoginSubmit({
907
+ const { errorText: errorText2, handleSubmit } = useLoginSubmit({
869
908
  username,
870
909
  password,
871
910
  login,
@@ -921,12 +960,12 @@ function LoginForm({
921
960
  }
922
961
  )
923
962
  ] }),
924
- errorText !== null ? /* @__PURE__ */ jsx(
963
+ errorText2 !== null ? /* @__PURE__ */ jsx(
925
964
  Text,
926
965
  {
927
966
  style: styles3.errorText,
928
967
  testID: withTestIdPrefix(AuthTestIds.loginError, testIdPrefix),
929
- children: errorText
968
+ children: errorText2
930
969
  }
931
970
  ) : null,
932
971
  onForgotPassword !== void 0 ? /* @__PURE__ */ jsx(
@@ -1018,7 +1057,7 @@ function ForgotPasswordForm({
1018
1057
  );
1019
1058
  const [email, setEmail] = useState("");
1020
1059
  const [submitted, setSubmitted] = useState(false);
1021
- const [errorText, setErrorText] = useState(null);
1060
+ const [errorText2, setErrorText] = useState(null);
1022
1061
  const mutationOptions = useMemo(
1023
1062
  () => ({
1024
1063
  client,
@@ -1080,12 +1119,12 @@ function ForgotPasswordForm({
1080
1119
  }
1081
1120
  )
1082
1121
  ] }),
1083
- errorText !== null ? /* @__PURE__ */ jsx(
1122
+ errorText2 !== null ? /* @__PURE__ */ jsx(
1084
1123
  Text,
1085
1124
  {
1086
1125
  style: styles3.errorText,
1087
1126
  testID: withTestIdPrefix(AuthTestIds.forgotPasswordError, testIdPrefix),
1088
- children: errorText
1127
+ children: errorText2
1089
1128
  }
1090
1129
  ) : null,
1091
1130
  /* @__PURE__ */ jsx(
@@ -1573,7 +1612,7 @@ function OtpRequestStep({
1573
1612
  labels,
1574
1613
  testIdPrefix,
1575
1614
  isSubmitting,
1576
- errorText,
1615
+ errorText: errorText2,
1577
1616
  onSubmit
1578
1617
  }) {
1579
1618
  const [email, setEmail] = useState("");
@@ -1601,7 +1640,7 @@ function OtpRequestStep({
1601
1640
  }
1602
1641
  )
1603
1642
  ] }),
1604
- errorText !== null ? /* @__PURE__ */ jsx(Text, { style: styles3.errorText, testID: withTestIdPrefix(AuthTestIds.otpError, testIdPrefix), children: errorText }) : null,
1643
+ errorText2 !== null ? /* @__PURE__ */ jsx(Text, { style: styles3.errorText, testID: withTestIdPrefix(AuthTestIds.otpError, testIdPrefix), children: errorText2 }) : null,
1605
1644
  /* @__PURE__ */ jsx(
1606
1645
  TouchableOpacity,
1607
1646
  {
@@ -1624,7 +1663,7 @@ function OtpVerifyStep({
1624
1663
  testIdPrefix,
1625
1664
  identifier,
1626
1665
  isSubmitting,
1627
- errorText,
1666
+ errorText: errorText2,
1628
1667
  onSubmit,
1629
1668
  onResend,
1630
1669
  onChangeEmail
@@ -1655,7 +1694,7 @@ function OtpVerifyStep({
1655
1694
  }
1656
1695
  )
1657
1696
  ] }),
1658
- errorText !== null ? /* @__PURE__ */ jsx(Text, { style: styles3.errorText, testID: withTestIdPrefix(AuthTestIds.otpError, testIdPrefix), children: errorText }) : null,
1697
+ errorText2 !== null ? /* @__PURE__ */ jsx(Text, { style: styles3.errorText, testID: withTestIdPrefix(AuthTestIds.otpError, testIdPrefix), children: errorText2 }) : null,
1659
1698
  /* @__PURE__ */ jsx(
1660
1699
  TouchableOpacity,
1661
1700
  {
@@ -1878,11 +1917,11 @@ function OtpForm({
1878
1917
  setLocalError(null);
1879
1918
  otp.reset();
1880
1919
  }, [otp]);
1881
- const errorText = localError ?? transportErrorFor(otp.step, otp.error, labels);
1920
+ const errorText2 = localError ?? transportErrorFor(otp.step, otp.error, labels);
1882
1921
  const content = otp.step === "requestCode" /* RequestCode */ ? /* @__PURE__ */ jsx(
1883
1922
  OtpRequestStep,
1884
1923
  {
1885
- errorText,
1924
+ errorText: errorText2,
1886
1925
  isSubmitting: otp.isSubmitting,
1887
1926
  labels,
1888
1927
  styles: styles3,
@@ -1893,7 +1932,7 @@ function OtpForm({
1893
1932
  ) : /* @__PURE__ */ jsx(
1894
1933
  OtpVerifyStep,
1895
1934
  {
1896
- errorText,
1935
+ errorText: errorText2,
1897
1936
  identifier: otp.identifier,
1898
1937
  isSubmitting: otp.isSubmitting,
1899
1938
  labels,
@@ -2005,7 +2044,7 @@ function PinForm({
2005
2044
  const [localError, setLocalError] = useState(null);
2006
2045
  const [pinValue, setPinValue] = useState("");
2007
2046
  const handleSubmit = useSubmitHandler(pin, labels, setLocalError, onSuccess);
2008
- const errorText = localError ?? transportErrorFor2(pin.error, labels);
2047
+ const errorText2 = localError ?? transportErrorFor2(pin.error, labels);
2009
2048
  const buttonStyle = pin.isSubmitting ? [styles3.primaryButton, styles3.primaryButtonDisabled] : styles3.primaryButton;
2010
2049
  const content = /* @__PURE__ */ jsxs(Fragment, { children: [
2011
2050
  /* @__PURE__ */ jsx(Text, { style: styles3.title, children: labels.title }),
@@ -2031,12 +2070,12 @@ function PinForm({
2031
2070
  }
2032
2071
  )
2033
2072
  ] }),
2034
- errorText !== null ? /* @__PURE__ */ jsx(
2073
+ errorText2 !== null ? /* @__PURE__ */ jsx(
2035
2074
  Text,
2036
2075
  {
2037
2076
  style: styles3.errorText,
2038
2077
  testID: withTestIdPrefix(AuthTestIds.pinError, testIdPrefix),
2039
- children: errorText
2078
+ children: errorText2
2040
2079
  }
2041
2080
  ) : null,
2042
2081
  /* @__PURE__ */ jsx(
@@ -2262,7 +2301,7 @@ function useDevicePinUnlock({
2262
2301
  const [pin, setPinState] = useState("");
2263
2302
  const [submitting, setSubmitting] = useState(false);
2264
2303
  const [errorKey, setErrorKey] = useState(null);
2265
- const [retryAfterSeconds, setRetryAfterSeconds] = useState(null);
2304
+ const [retryAfterSeconds2, setRetryAfterSeconds] = useState(null);
2266
2305
  const setPin = useCallback((next) => {
2267
2306
  setPinState(next);
2268
2307
  setErrorKey(null);
@@ -2302,7 +2341,7 @@ function useDevicePinUnlock({
2302
2341
  setSubmitting(false);
2303
2342
  });
2304
2343
  }, [client, pin, digits, onSignedIn]);
2305
- return { pin, submitting, errorKey, retryAfterSeconds, setPin, submit };
2344
+ return { pin, submitting, errorKey, retryAfterSeconds: retryAfterSeconds2, setPin, submit };
2306
2345
  }
2307
2346
  function resolveErrorText(errorKey, digits, retryAfter, labels) {
2308
2347
  if (errorKey === null) {
@@ -2338,14 +2377,14 @@ function DevicePinUnlockScreen({
2338
2377
  () => ({ ...DEFAULT_DEVICE_PIN_UNLOCK_LABELS, ...labelsProp }),
2339
2378
  [labelsProp]
2340
2379
  );
2341
- const { pin, submitting, errorKey, retryAfterSeconds, setPin, submit } = useDevicePinUnlock({
2380
+ const { pin, submitting, errorKey, retryAfterSeconds: retryAfterSeconds2, setPin, submit } = useDevicePinUnlock({
2342
2381
  client,
2343
2382
  digits,
2344
2383
  onSignedIn
2345
2384
  });
2346
2385
  const hasName = rememberedUsername !== "";
2347
2386
  const title = hasName ? interpolate(labels.title, { name: rememberedUsername }) : labels.titleNoName;
2348
- const error = resolveErrorText(errorKey, digits, retryAfterSeconds, labels);
2387
+ const error = resolveErrorText(errorKey, digits, retryAfterSeconds2, labels);
2349
2388
  const buttonStyle = submitting ? [styles3.primaryButton, styles3.primaryButtonDisabled] : styles3.primaryButton;
2350
2389
  return /* @__PURE__ */ jsx(View, { style: styles3.screen, children: /* @__PURE__ */ jsxs(
2351
2390
  View,
@@ -4305,13 +4344,13 @@ var RegisterErrorCode = /* @__PURE__ */ ((RegisterErrorCode2) => {
4305
4344
  })(RegisterErrorCode || {});
4306
4345
 
4307
4346
  // src/hooks/routeRegisterOutcome.ts
4308
- function routeRegisterOutcome(outcome, handlers) {
4309
- if (outcome.ok) {
4310
- handlers.onSuccess(outcome.result);
4347
+ function routeRegisterOutcome(outcome2, handlers) {
4348
+ if (outcome2.ok) {
4349
+ handlers.onSuccess(outcome2.result);
4311
4350
  return;
4312
4351
  }
4313
- if (outcome.error !== "inFlight" /* InFlight */) {
4314
- handlers.onError?.(outcome.error);
4352
+ if (outcome2.error !== "inFlight" /* InFlight */) {
4353
+ handlers.onError?.(outcome2.error);
4315
4354
  }
4316
4355
  }
4317
4356
 
@@ -5441,6 +5480,432 @@ function SharedRegisterForm({
5441
5480
  return /* @__PURE__ */ jsx(RegisterFormCore, { ...formProps, sharedRegistration: true, onSuccess: handleResult });
5442
5481
  }
5443
5482
 
5444
- export { AccountSettingsScreen, AuthScreen, AuthTestIds, AuthThemeProvider, BffAuthStatus, CHANGE_PASSWORD_ENDPOINT, ChangePasswordCard, ChangePasswordErrorKey, DEFAULT_ACCOUNT_SETTINGS_LABELS, DEFAULT_AUTH_CARD_MAX_WIDTH, DEFAULT_DEMO_CREDENTIALS_HINT_LABELS, DEFAULT_DEVICE_PIN_ENROLL_LABELS, DEFAULT_DEVICE_PIN_SETTINGS_LABELS, DEFAULT_DEVICE_PIN_UNLOCK_LABELS, DEFAULT_FORGOT_PASSWORD_FIELDS_LABELS, DEFAULT_FORGOT_PASSWORD_LABELS, DEFAULT_LOGIN_LABELS, DEFAULT_OTP_LABELS, DEFAULT_PASSKEY_LOGIN_LABELS, DEFAULT_PASSKEY_SETTINGS_LABELS, DEFAULT_PIN_LABELS, DEFAULT_PREFERRED_METHOD_HINT_LABELS, DEFAULT_PREFERRED_METHOD_SETTINGS_LABELS, DEFAULT_REGISTER_LABELS, DEFAULT_RESET_PASSWORD_LABELS, DEFAULT_VERIFY_EMAIL_LABELS, DEFAULT_VERIFY_NEW_PASSWORD_LABELS, DEFAULT_VERIFY_SIGN_IN_LABELS, DEVICE_PIN_ALLOWED_DIGITS, DEVICE_PIN_DEFAULT_DIGITS, DemoCredentialsHint, DemoCredentialsHintVariant, DevicePinEnrollErrorKey, DevicePinEnrollForm, DevicePinErrorKey, DevicePinInput, DevicePinLengthPicker, DevicePinOffer, DevicePinSettingsCard, DevicePinUnlockScreen, ForgotPasswordFields, ForgotPasswordForm, LoginForm, OtpForm, OtpLoginStep, PASSWORD_MAX_LENGTH, PASSWORD_MIN_LENGTH, PasskeyCeremonyMode, PasskeyCeremonyStatus, PasskeyLoginButton, PasskeySettingsCard, PasswordPolicyError, PinForm, PreferredMethodHint, PreferredMethodSettingsCard, PrefillIntent, REGISTER_ENDPOINT, RESEND_VERIFICATION_ENDPOINT, RegisterErrorCode, RegisterForm, RegisterTestIds, ResetPasswordError, ResetPasswordForm, SharedRegisterForm, VERIFY_AND_LOGIN_ENDPOINT, VERIFY_EMAIL_ENDPOINT, VERIFY_TOKEN_PLACEHOLDER, VerifyEmailErrorCode, VerifyEmailPhase, VerifyEmailScreen, buildVerifyUrlTemplate, cachePreferredMethod, clearCachedPreferredMethod, collectUserRoles, createBffAuthClient, createBffChangePasswordClient, createBffVerifyEmailClient, createPreferencesClient, createSharedRegistrationClient, defaultAuthTheme, deriveUsernameFromEmail, isAllowedPinDigits, isPasswordValid, isRegisterAccepted, isRegisterPasswordStrong, isValidForgotPasswordEmail, performBffLogout, readCachedPreferredMethod, readPasskeyError, readPasskeyRegistered, readVerifyToken, resolveAccessibleRoutes, resolveAccountList, resolveDemoAccounts, resolveDemoCredentials, resolvePostLoginRoute, splitFullName, startPasskeyLogin, startPasskeyRegistration, syncPreferredMethodFromServer, useAuthTheme, useBffAuth, useBffForgotPassword, useBffLoginConfig, useBffResetPassword, useChangePassword, useDemoCredentials, useDevicePinDisable, useDevicePinEnroll, useDevicePinUnlock, useForgotPasswordSubmit, useOtpLogin, usePasskeyCeremony, usePinLogin, usePreferredMethodSetting, useRegisterForm, useResendVerification, useResetPasswordForm, useVerifyEmail, validatePasswordPolicy, verifyEmailErrorText, withTestIdPrefix };
5483
+ // src/account/AccountDeletionStatus.ts
5484
+ var AccountDeletionStatus = /* @__PURE__ */ ((AccountDeletionStatus2) => {
5485
+ AccountDeletionStatus2["Accepted"] = "accepted";
5486
+ AccountDeletionStatus2["StepUpRequired"] = "stepUpRequired";
5487
+ AccountDeletionStatus2["AlreadyRequested"] = "alreadyRequested";
5488
+ AccountDeletionStatus2["SignInRequired"] = "signInRequired";
5489
+ AccountDeletionStatus2["RateLimited"] = "rateLimited";
5490
+ AccountDeletionStatus2["RetryLater"] = "retryLater";
5491
+ AccountDeletionStatus2["Failed"] = "failed";
5492
+ return AccountDeletionStatus2;
5493
+ })(AccountDeletionStatus || {});
5494
+
5495
+ // src/account/StepUpStatus.ts
5496
+ var StepUpStatus = /* @__PURE__ */ ((StepUpStatus2) => {
5497
+ StepUpStatus2["Confirmed"] = "confirmed";
5498
+ StepUpStatus2["WrongPassword"] = "wrongPassword";
5499
+ StepUpStatus2["RateLimited"] = "rateLimited";
5500
+ StepUpStatus2["Failed"] = "failed";
5501
+ return StepUpStatus2;
5502
+ })(StepUpStatus || {});
5503
+
5504
+ // src/account/accountDeletionClient.ts
5505
+ var ACCOUNT_DELETE_REQUEST_ENDPOINT = "/bff/account/delete-request";
5506
+ var STEP_UP_PASSWORD_ENDPOINT = "/bff/step-up/password";
5507
+ var RECENT_AUTHENTICATION_REQUIRED = "RECENT_AUTHENTICATION_REQUIRED";
5508
+ var HTTP_ACCEPTED2 = 202;
5509
+ var HTTP_UNAUTHORIZED3 = 401;
5510
+ var HTTP_FORBIDDEN = 403;
5511
+ var HTTP_CONFLICT = 409;
5512
+ var HTTP_TOO_MANY_REQUESTS3 = 429;
5513
+ var HTTP_BAD_GATEWAY = 502;
5514
+ var DELTA_SECONDS = /^\d+$/;
5515
+ function retryAfterSeconds(response) {
5516
+ const raw = response.header?.("Retry-After")?.trim();
5517
+ return raw !== void 0 && DELTA_SECONDS.test(raw) ? Number(raw) : null;
5518
+ }
5519
+ function decodeReceipt(data) {
5520
+ const body = isRecord3(data) ? data : {};
5521
+ return {
5522
+ requestId: typeof body.requestId === "string" ? body.requestId : "",
5523
+ scheduledDeletionDate: typeof body.scheduledDeletionDate === "string" ? body.scheduledDeletionDate : "",
5524
+ confirmationEmailSent: body.confirmationEmailSent === true
5525
+ };
5526
+ }
5527
+ function isStaleLogin(data) {
5528
+ return isRecord3(data) && data.code === RECENT_AUTHENTICATION_REQUIRED;
5529
+ }
5530
+ function decodeDeletion(response) {
5531
+ switch (response.status) {
5532
+ case HTTP_ACCEPTED2:
5533
+ return { status: "accepted" /* Accepted */, receipt: decodeReceipt(response.data) };
5534
+ case HTTP_FORBIDDEN:
5535
+ return { status: isStaleLogin(response.data) ? "stepUpRequired" /* StepUpRequired */ : "failed" /* Failed */ };
5536
+ case HTTP_CONFLICT:
5537
+ return { status: "alreadyRequested" /* AlreadyRequested */ };
5538
+ case HTTP_UNAUTHORIZED3:
5539
+ return { status: "signInRequired" /* SignInRequired */ };
5540
+ case HTTP_TOO_MANY_REQUESTS3:
5541
+ return { status: "rateLimited" /* RateLimited */, retryAfterSeconds: retryAfterSeconds(response) };
5542
+ case HTTP_BAD_GATEWAY:
5543
+ return { status: "retryLater" /* RetryLater */ };
5544
+ default:
5545
+ return { status: "failed" /* Failed */ };
5546
+ }
5547
+ }
5548
+ function decodeStepUp(response) {
5549
+ if (response.ok) {
5550
+ return { status: "confirmed" /* Confirmed */ };
5551
+ }
5552
+ if (response.status === HTTP_UNAUTHORIZED3) {
5553
+ return { status: "wrongPassword" /* WrongPassword */ };
5554
+ }
5555
+ if (response.status === HTTP_TOO_MANY_REQUESTS3) {
5556
+ return { status: "rateLimited" /* RateLimited */, retryAfterSeconds: retryAfterSeconds(response) };
5557
+ }
5558
+ return { status: "failed" /* Failed */ };
5559
+ }
5560
+ function createBffAccountDeletionClient(options = {}) {
5561
+ const http = options.http ?? lazyFetchHttpClient3;
5562
+ const baseUrl = options.baseUrl ?? "";
5563
+ const post = (path, body) => http({
5564
+ url: `${baseUrl}${path}`,
5565
+ method: "POST",
5566
+ headers: { "Content-Type": "application/json", "X-BFF-Csrf": "1" },
5567
+ body: JSON.stringify(body),
5568
+ credentials: "include"
5569
+ });
5570
+ return {
5571
+ requestDeletion: async (reason) => {
5572
+ try {
5573
+ return decodeDeletion(await post(ACCOUNT_DELETE_REQUEST_ENDPOINT, reason === void 0 ? {} : { reason }));
5574
+ } catch {
5575
+ return { status: "failed" /* Failed */ };
5576
+ }
5577
+ },
5578
+ stepUpPassword: async (password) => {
5579
+ try {
5580
+ return decodeStepUp(await post(STEP_UP_PASSWORD_ENDPOINT, { password }));
5581
+ } catch {
5582
+ return { status: "failed" /* Failed */ };
5583
+ }
5584
+ }
5585
+ };
5586
+ }
5587
+
5588
+ // src/account/AccountDeletionErrorKey.ts
5589
+ var AccountDeletionErrorKey = /* @__PURE__ */ ((AccountDeletionErrorKey2) => {
5590
+ AccountDeletionErrorKey2["PasswordRequired"] = "passwordRequired";
5591
+ AccountDeletionErrorKey2["WrongPassword"] = "wrongPassword";
5592
+ AccountDeletionErrorKey2["SignInRequired"] = "signInRequired";
5593
+ AccountDeletionErrorKey2["RateLimited"] = "rateLimited";
5594
+ AccountDeletionErrorKey2["RetryLater"] = "retryLater";
5595
+ AccountDeletionErrorKey2["Failed"] = "failed";
5596
+ return AccountDeletionErrorKey2;
5597
+ })(AccountDeletionErrorKey || {});
5598
+
5599
+ // src/account/AccountDeletionPhase.ts
5600
+ var AccountDeletionPhase = /* @__PURE__ */ ((AccountDeletionPhase2) => {
5601
+ AccountDeletionPhase2["Confirm"] = "confirm";
5602
+ AccountDeletionPhase2["StepUp"] = "stepUp";
5603
+ AccountDeletionPhase2["Accepted"] = "accepted";
5604
+ AccountDeletionPhase2["AlreadyRequested"] = "alreadyRequested";
5605
+ return AccountDeletionPhase2;
5606
+ })(AccountDeletionPhase || {});
5607
+
5608
+ // src/account/accountDeletionFlow.ts
5609
+ function outcome(phase, errorKey = null, retryAfterSeconds2 = null) {
5610
+ return { phase, errorKey, receipt: null, retryAfterSeconds: retryAfterSeconds2 };
5611
+ }
5612
+ function fromDeletion(result, steppedUp) {
5613
+ switch (result.status) {
5614
+ case "accepted" /* Accepted */:
5615
+ return { ...outcome("accepted" /* Accepted */), receipt: result.receipt };
5616
+ case "stepUpRequired" /* StepUpRequired */:
5617
+ return outcome("stepUp" /* StepUp */, steppedUp ? "failed" /* Failed */ : null);
5618
+ case "alreadyRequested" /* AlreadyRequested */:
5619
+ return outcome("alreadyRequested" /* AlreadyRequested */);
5620
+ case "signInRequired" /* SignInRequired */:
5621
+ return outcome("confirm" /* Confirm */, "signInRequired" /* SignInRequired */);
5622
+ case "rateLimited" /* RateLimited */:
5623
+ return outcome("confirm" /* Confirm */, "rateLimited" /* RateLimited */, result.retryAfterSeconds);
5624
+ case "retryLater" /* RetryLater */:
5625
+ return outcome("confirm" /* Confirm */, "retryLater" /* RetryLater */);
5626
+ default:
5627
+ return outcome("confirm" /* Confirm */, "failed" /* Failed */);
5628
+ }
5629
+ }
5630
+ function fromStepUpFailure(result) {
5631
+ if (result.status === "wrongPassword" /* WrongPassword */) {
5632
+ return outcome("stepUp" /* StepUp */, "wrongPassword" /* WrongPassword */);
5633
+ }
5634
+ if (result.status === "rateLimited" /* RateLimited */) {
5635
+ return outcome("stepUp" /* StepUp */, "rateLimited" /* RateLimited */, result.retryAfterSeconds);
5636
+ }
5637
+ return outcome("stepUp" /* StepUp */, "failed" /* Failed */);
5638
+ }
5639
+ async function runDeletionAttempt(client, { phase, reason, password }) {
5640
+ const trimmed = reason.trim();
5641
+ const sentReason = trimmed === "" ? void 0 : trimmed;
5642
+ if (phase !== "stepUp" /* StepUp */) {
5643
+ return fromDeletion(await client.requestDeletion(sentReason), false);
5644
+ }
5645
+ const stepUp = await client.stepUpPassword(password);
5646
+ if (stepUp.status !== "confirmed" /* Confirmed */) {
5647
+ return fromStepUpFailure(stepUp);
5648
+ }
5649
+ return fromDeletion(await client.requestDeletion(sentReason), true);
5650
+ }
5651
+ var MS_PER_SECOND = 1e3;
5652
+ function useRetryAfterBlock(onExpired) {
5653
+ const [retryAfterSeconds2, setRetryAfterSeconds] = useState(null);
5654
+ const timer = useRef(null);
5655
+ const stopTimer = useCallback(() => {
5656
+ if (timer.current !== null) {
5657
+ clearTimeout(timer.current);
5658
+ }
5659
+ timer.current = null;
5660
+ }, []);
5661
+ useEffect(() => stopTimer, [stopTimer]);
5662
+ const block = useCallback(
5663
+ (seconds) => {
5664
+ stopTimer();
5665
+ setRetryAfterSeconds(seconds);
5666
+ timer.current = setTimeout(() => {
5667
+ timer.current = null;
5668
+ setRetryAfterSeconds(null);
5669
+ onExpired();
5670
+ }, seconds * MS_PER_SECOND);
5671
+ },
5672
+ [onExpired, stopTimer]
5673
+ );
5674
+ return { retryAfterSeconds: retryAfterSeconds2, block };
5675
+ }
5676
+
5677
+ // src/account/useAccountDeletion.ts
5678
+ function useAccountDeletion(args) {
5679
+ const { client, onAccepted, onSignInRequired } = args;
5680
+ const [reason, setReason] = useState("");
5681
+ const [password, setPasswordValue] = useState("");
5682
+ const [phase, setPhase] = useState("confirm" /* Confirm */);
5683
+ const [submitting, setSubmitting] = useState(false);
5684
+ const [errorKey, setErrorKey] = useState(null);
5685
+ const [receipt, setReceipt] = useState(null);
5686
+ const inFlight = useRef(false);
5687
+ const clearRateLimit = useCallback(() => {
5688
+ setErrorKey((current) => current === "rateLimited" /* RateLimited */ ? null : current);
5689
+ }, []);
5690
+ const { retryAfterSeconds: retryAfterSeconds2, block } = useRetryAfterBlock(clearRateLimit);
5691
+ const blocked = retryAfterSeconds2 !== null;
5692
+ const setPassword = useCallback((value) => {
5693
+ setPasswordValue(value);
5694
+ setErrorKey((current) => current === "rateLimited" /* RateLimited */ ? current : null);
5695
+ }, []);
5696
+ const applyOutcome = useCallback((outcome2) => {
5697
+ setPhase(outcome2.phase);
5698
+ setErrorKey(outcome2.errorKey);
5699
+ setPasswordValue("");
5700
+ if (outcome2.retryAfterSeconds !== null) {
5701
+ block(outcome2.retryAfterSeconds);
5702
+ }
5703
+ if (outcome2.errorKey === "signInRequired" /* SignInRequired */) {
5704
+ onSignInRequired?.();
5705
+ }
5706
+ if (outcome2.receipt === null) {
5707
+ return;
5708
+ }
5709
+ setReceipt(outcome2.receipt);
5710
+ onAccepted?.(outcome2.receipt);
5711
+ }, [block, onAccepted, onSignInRequired]);
5712
+ const submit = useCallback(() => {
5713
+ if (inFlight.current || blocked) {
5714
+ return;
5715
+ }
5716
+ if (phase === "stepUp" /* StepUp */ && password === "") {
5717
+ setErrorKey("passwordRequired" /* PasswordRequired */);
5718
+ return;
5719
+ }
5720
+ inFlight.current = true;
5721
+ setSubmitting(true);
5722
+ setErrorKey(null);
5723
+ runDeletionAttempt(client, { phase, reason, password }).then(applyOutcome).catch(() => {
5724
+ setPasswordValue("");
5725
+ setErrorKey("failed" /* Failed */);
5726
+ }).finally(() => {
5727
+ inFlight.current = false;
5728
+ setSubmitting(false);
5729
+ });
5730
+ }, [applyOutcome, blocked, client, password, phase, reason]);
5731
+ return { phase, reason, password, setReason, setPassword, submitting, blocked, retryAfterSeconds: retryAfterSeconds2, errorKey, receipt, submit };
5732
+ }
5733
+ var REASON_MAX_LENGTH = 1e3;
5734
+ function AccountDeletionField({
5735
+ copy,
5736
+ placeholderColor,
5737
+ secure,
5738
+ disabled,
5739
+ value,
5740
+ styles: styles3,
5741
+ testID,
5742
+ onChangeText,
5743
+ onSubmitEditing
5744
+ }) {
5745
+ const inputRef = useRef(null);
5746
+ useFocusOnMount(inputRef);
5747
+ return /* @__PURE__ */ jsxs(View, { style: styles3.fieldGroup, children: [
5748
+ /* @__PURE__ */ jsx(Text, { style: styles3.label, children: copy.label }),
5749
+ /* @__PURE__ */ jsx(
5750
+ TextInput,
5751
+ {
5752
+ ref: inputRef,
5753
+ accessibilityHint: copy.hint,
5754
+ accessibilityLabel: copy.inputLabel,
5755
+ autoComplete: secure ? "current-password" : "off",
5756
+ editable: !disabled,
5757
+ maxLength: secure ? void 0 : REASON_MAX_LENGTH,
5758
+ placeholder: copy.placeholder,
5759
+ placeholderTextColor: placeholderColor,
5760
+ returnKeyType: "go",
5761
+ secureTextEntry: secure,
5762
+ style: styles3.input,
5763
+ testID,
5764
+ value,
5765
+ onChangeText,
5766
+ onSubmitEditing
5767
+ }
5768
+ )
5769
+ ] });
5770
+ }
5771
+ function AccountDeletionNotice({
5772
+ title,
5773
+ body,
5774
+ detail,
5775
+ styles: styles3,
5776
+ testID,
5777
+ footer
5778
+ }) {
5779
+ const headingRef = useRef(null);
5780
+ useFocusOnMount(headingRef);
5781
+ return /* @__PURE__ */ jsx(View, { style: styles3.screen, children: /* @__PURE__ */ jsxs(View, { accessibilityLiveRegion: "polite", style: styles3.card, testID, children: [
5782
+ /* @__PURE__ */ jsx(View, { ref: headingRef, accessible: true, focusable: true, children: /* @__PURE__ */ jsx(Text, { accessibilityRole: "header", style: styles3.title, children: title }) }),
5783
+ /* @__PURE__ */ jsx(Text, { style: styles3.subtitle, children: body }),
5784
+ detail === null ? null : /* @__PURE__ */ jsx(Text, { style: styles3.helperText, children: detail }),
5785
+ footer
5786
+ ] }) });
5787
+ }
5788
+
5789
+ // src/components/accountDeletionTestIds.ts
5790
+ var AccountDeletionTestIds = {
5791
+ form: "account-deletion-form",
5792
+ reasonInput: "account-deletion-reason-input",
5793
+ stepUpInput: "account-deletion-password-input",
5794
+ submitButton: "account-deletion-submit-button",
5795
+ error: "account-deletion-error",
5796
+ checkEmail: "account-deletion-check-email",
5797
+ emailNotSent: "account-deletion-email-not-sent",
5798
+ alreadyRequested: "account-deletion-already-requested"
5799
+ };
5800
+ function errorText(errorKey, seconds, labels) {
5801
+ switch (errorKey) {
5802
+ case null:
5803
+ return null;
5804
+ case "passwordRequired" /* PasswordRequired */:
5805
+ return labels.errorPasswordRequired;
5806
+ case "wrongPassword" /* WrongPassword */:
5807
+ return labels.errorWrongPassword;
5808
+ case "signInRequired" /* SignInRequired */:
5809
+ return labels.errorSignInRequired;
5810
+ case "rateLimited" /* RateLimited */:
5811
+ return seconds === null ? labels.errorRateLimited : interpolate(labels.errorRateLimitedSeconds, { seconds });
5812
+ case "retryLater" /* RetryLater */:
5813
+ return labels.errorRetryLater;
5814
+ default:
5815
+ return labels.errorFailed;
5816
+ }
5817
+ }
5818
+ function scheduledDetail(receipt, labels) {
5819
+ const date = new Date(receipt?.scheduledDeletionDate ?? "");
5820
+ return Number.isNaN(date.getTime()) ? null : interpolate(labels.scheduledDate, { date: date.toLocaleDateString() });
5821
+ }
5822
+ function noticeCopy(phase, receipt, labels) {
5823
+ if (phase === "alreadyRequested" /* AlreadyRequested */) {
5824
+ return {
5825
+ title: labels.alreadyRequestedTitle,
5826
+ body: labels.alreadyRequestedBody,
5827
+ detail: null,
5828
+ testId: AccountDeletionTestIds.alreadyRequested
5829
+ };
5830
+ }
5831
+ if (phase !== "accepted" /* Accepted */) {
5832
+ return null;
5833
+ }
5834
+ const detail = scheduledDetail(receipt, labels);
5835
+ if (receipt?.confirmationEmailSent === true) {
5836
+ return { title: labels.checkEmailTitle, body: labels.checkEmailBody, detail, testId: AccountDeletionTestIds.checkEmail };
5837
+ }
5838
+ return { title: labels.emailNotSentTitle, body: labels.emailNotSentBody, detail, testId: AccountDeletionTestIds.emailNotSent };
5839
+ }
5840
+ function AccountDeletionForm({
5841
+ client,
5842
+ labels: labelsProp,
5843
+ theme: themeProp,
5844
+ testIdPrefix,
5845
+ footer,
5846
+ onAccepted,
5847
+ onSignInRequired
5848
+ }) {
5849
+ const theme = useAuthTheme(themeProp);
5850
+ const styles3 = useAuthStyles(theme);
5851
+ const labels = useMemo(() => ({ ...DEFAULT_ACCOUNT_DELETION_LABELS, ...labelsProp }), [labelsProp]);
5852
+ const form = useAccountDeletion({ client, onAccepted, onSignInRequired });
5853
+ const handleSubmitEditing = useSubmitOnEnter(form.submit);
5854
+ const testId = (id) => withTestIdPrefix(id, testIdPrefix);
5855
+ const notice = noticeCopy(form.phase, form.receipt, labels);
5856
+ if (notice !== null) {
5857
+ return /* @__PURE__ */ jsx(
5858
+ AccountDeletionNotice,
5859
+ {
5860
+ body: notice.body,
5861
+ detail: notice.detail,
5862
+ footer,
5863
+ styles: styles3,
5864
+ testID: testId(notice.testId),
5865
+ title: notice.title
5866
+ }
5867
+ );
5868
+ }
5869
+ const steppingUp = form.phase === "stepUp" /* StepUp */;
5870
+ const message = errorText(form.errorKey, form.retryAfterSeconds, labels);
5871
+ const submitLabel = steppingUp ? labels.stepUpSubmit : labels.submit;
5872
+ return /* @__PURE__ */ jsx(View, { style: styles3.screen, children: /* @__PURE__ */ jsxs(View, { style: styles3.card, testID: testId(AccountDeletionTestIds.form), children: [
5873
+ /* @__PURE__ */ jsx(Text, { style: styles3.title, children: steppingUp ? labels.stepUpTitle : labels.title }),
5874
+ /* @__PURE__ */ jsx(Text, { style: styles3.subtitle, children: steppingUp ? labels.stepUpSubtitle : labels.subtitle }),
5875
+ /* @__PURE__ */ jsx(
5876
+ AccountDeletionField,
5877
+ {
5878
+ copy: steppingUp ? labels.password : labels.reason,
5879
+ disabled: form.submitting,
5880
+ placeholderColor: theme.colors.textSecondary,
5881
+ secure: steppingUp,
5882
+ styles: styles3,
5883
+ testID: testId(steppingUp ? AccountDeletionTestIds.stepUpInput : AccountDeletionTestIds.reasonInput),
5884
+ value: steppingUp ? form.password : form.reason,
5885
+ onChangeText: steppingUp ? form.setPassword : form.setReason,
5886
+ onSubmitEditing: handleSubmitEditing
5887
+ },
5888
+ form.phase
5889
+ ),
5890
+ message === null ? null : /* @__PURE__ */ jsx(Text, { accessibilityLiveRegion: "polite", style: styles3.errorText, testID: testId(AccountDeletionTestIds.error), children: message }),
5891
+ /* @__PURE__ */ jsx(View, { style: styles3.fieldGroup, children: /* @__PURE__ */ jsx(
5892
+ Button,
5893
+ {
5894
+ fullWidth: true,
5895
+ accessibilityHint: steppingUp ? labels.stepUpSubmitHint : labels.submitHint,
5896
+ accessibilityLabel: form.submitting ? labels.submitting : submitLabel,
5897
+ disabled: form.blocked,
5898
+ label: submitLabel,
5899
+ loading: form.submitting,
5900
+ testID: testId(AccountDeletionTestIds.submitButton),
5901
+ variant: "danger",
5902
+ onPress: form.submit
5903
+ }
5904
+ ) }),
5905
+ footer
5906
+ ] }) });
5907
+ }
5908
+
5909
+ export { ACCOUNT_DELETE_REQUEST_ENDPOINT, AccountDeletionErrorKey, AccountDeletionForm, AccountDeletionPhase, AccountDeletionStatus, AccountDeletionTestIds, AccountSettingsScreen, AuthScreen, AuthTestIds, AuthThemeProvider, BffAuthStatus, CHANGE_PASSWORD_ENDPOINT, ChangePasswordCard, ChangePasswordErrorKey, DEFAULT_ACCOUNT_DELETION_LABELS, DEFAULT_ACCOUNT_SETTINGS_LABELS, DEFAULT_AUTH_CARD_MAX_WIDTH, DEFAULT_DEMO_CREDENTIALS_HINT_LABELS, DEFAULT_DEVICE_PIN_ENROLL_LABELS, DEFAULT_DEVICE_PIN_SETTINGS_LABELS, DEFAULT_DEVICE_PIN_UNLOCK_LABELS, DEFAULT_FORGOT_PASSWORD_FIELDS_LABELS, DEFAULT_FORGOT_PASSWORD_LABELS, DEFAULT_LOGIN_LABELS, DEFAULT_OTP_LABELS, DEFAULT_PASSKEY_LOGIN_LABELS, DEFAULT_PASSKEY_SETTINGS_LABELS, DEFAULT_PIN_LABELS, DEFAULT_PREFERRED_METHOD_HINT_LABELS, DEFAULT_PREFERRED_METHOD_SETTINGS_LABELS, DEFAULT_REGISTER_LABELS, DEFAULT_RESET_PASSWORD_LABELS, DEFAULT_VERIFY_EMAIL_LABELS, DEFAULT_VERIFY_NEW_PASSWORD_LABELS, DEFAULT_VERIFY_SIGN_IN_LABELS, DEVICE_PIN_ALLOWED_DIGITS, DEVICE_PIN_DEFAULT_DIGITS, DemoCredentialsHint, DemoCredentialsHintVariant, DevicePinEnrollErrorKey, DevicePinEnrollForm, DevicePinErrorKey, DevicePinInput, DevicePinLengthPicker, DevicePinOffer, DevicePinSettingsCard, DevicePinUnlockScreen, ForgotPasswordFields, ForgotPasswordForm, LoginForm, OtpForm, OtpLoginStep, PASSWORD_MAX_LENGTH, PASSWORD_MIN_LENGTH, PasskeyCeremonyMode, PasskeyCeremonyStatus, PasskeyLoginButton, PasskeySettingsCard, PasswordPolicyError, PinForm, PreferredMethodHint, PreferredMethodSettingsCard, PrefillIntent, REGISTER_ENDPOINT, RESEND_VERIFICATION_ENDPOINT, RegisterErrorCode, RegisterForm, RegisterTestIds, ResetPasswordError, ResetPasswordForm, STEP_UP_PASSWORD_ENDPOINT, SharedRegisterForm, StepUpStatus, VERIFY_AND_LOGIN_ENDPOINT, VERIFY_EMAIL_ENDPOINT, VERIFY_TOKEN_PLACEHOLDER, VerifyEmailErrorCode, VerifyEmailPhase, VerifyEmailScreen, buildVerifyUrlTemplate, cachePreferredMethod, clearCachedPreferredMethod, collectUserRoles, createBffAccountDeletionClient, createBffAuthClient, createBffChangePasswordClient, createBffVerifyEmailClient, createPreferencesClient, createSharedRegistrationClient, defaultAuthTheme, deriveUsernameFromEmail, isAllowedPinDigits, isPasswordValid, isRegisterAccepted, isRegisterPasswordStrong, isValidForgotPasswordEmail, performBffLogout, readCachedPreferredMethod, readPasskeyError, readPasskeyRegistered, readVerifyToken, resolveAccessibleRoutes, resolveAccountList, resolveDemoAccounts, resolveDemoCredentials, resolvePostLoginRoute, splitFullName, startPasskeyLogin, startPasskeyRegistration, syncPreferredMethodFromServer, useAccountDeletion, useAuthTheme, useBffAuth, useBffForgotPassword, useBffLoginConfig, useBffResetPassword, useChangePassword, useDemoCredentials, useDevicePinDisable, useDevicePinEnroll, useDevicePinUnlock, useForgotPasswordSubmit, useOtpLogin, usePasskeyCeremony, usePinLogin, usePreferredMethodSetting, useRegisterForm, useResendVerification, useResetPasswordForm, useVerifyEmail, validatePasswordPolicy, verifyEmailErrorText, withTestIdPrefix };
5445
5910
  //# sourceMappingURL=index.mjs.map
5446
5911
  //# sourceMappingURL=index.mjs.map