@dloizides/auth-web 1.21.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/CHANGELOG.md +635 -626
- package/dist/index.d.mts +131 -1
- package/dist/index.d.ts +131 -1
- package/dist/index.js +419 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +407 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -353,6 +353,31 @@ var DEFAULT_REGISTER_LABELS = {
|
|
|
353
353
|
}
|
|
354
354
|
};
|
|
355
355
|
|
|
356
|
+
// src/components/labels/verifyEmailLabels.ts
|
|
357
|
+
var DEFAULT_VERIFY_EMAIL_LABELS = {
|
|
358
|
+
loadingTitle: "Verifying your email...",
|
|
359
|
+
loadingHint: "Please wait while we verify your address.",
|
|
360
|
+
successTitle: "Your email is verified",
|
|
361
|
+
successBody: "Thanks for confirming your email address.",
|
|
362
|
+
successContinue: "Continue",
|
|
363
|
+
successContinueHint: "Go to the app",
|
|
364
|
+
errorTitle: "We couldn't verify your email",
|
|
365
|
+
errorInvalid: "This verification link is invalid. Request a new one.",
|
|
366
|
+
errorExpired: "This verification link has expired. Request a new one.",
|
|
367
|
+
errorUsed: "This link has already been used.",
|
|
368
|
+
errorGeneric: "Verification failed. Please try again later.",
|
|
369
|
+
missingToken: "This verification link is missing a token.",
|
|
370
|
+
resendCta: "Send a new verification email",
|
|
371
|
+
resendCtaHint: "Show the resend verification email form",
|
|
372
|
+
resendEmailLabel: "Email",
|
|
373
|
+
resendEmailHint: "The address to send a new verification link to",
|
|
374
|
+
resendEmailPlaceholder: "you@example.com",
|
|
375
|
+
resendMissingEmail: "Enter your email address.",
|
|
376
|
+
resendSubmit: "Send link",
|
|
377
|
+
resendSubmitHint: "Sends a new verification email",
|
|
378
|
+
resendConfirmation: "If that address has an account, a new verification link is on its way."
|
|
379
|
+
};
|
|
380
|
+
|
|
356
381
|
// src/components/testIds.ts
|
|
357
382
|
var AuthTestIds = {
|
|
358
383
|
loginForm: "auth-login-form",
|
|
@@ -443,7 +468,17 @@ var AuthTestIds = {
|
|
|
443
468
|
demoCredentialsPassword: "auth-demo-credentials-password",
|
|
444
469
|
demoCredentialsUseButton: "auth-demo-credentials-use",
|
|
445
470
|
// The collapsed disclosure trigger (`disclosure` variant only).
|
|
446
|
-
demoCredentialsToggle: "auth-demo-credentials-toggle"
|
|
471
|
+
demoCredentialsToggle: "auth-demo-credentials-toggle",
|
|
472
|
+
verifyEmailScreen: "auth-verify-email",
|
|
473
|
+
verifyEmailLoading: "auth-verify-email-loading",
|
|
474
|
+
verifyEmailSuccess: "auth-verify-email-success",
|
|
475
|
+
verifyEmailContinue: "auth-verify-email-continue",
|
|
476
|
+
verifyEmailError: "auth-verify-email-error",
|
|
477
|
+
verifyEmailResendCta: "auth-verify-email-resend-cta",
|
|
478
|
+
verifyEmailResendForm: "auth-verify-email-resend-form",
|
|
479
|
+
verifyEmailResendEmail: "auth-verify-email-resend-email",
|
|
480
|
+
verifyEmailResendSubmit: "auth-verify-email-resend-submit",
|
|
481
|
+
verifyEmailResendConfirmation: "auth-verify-email-resend-confirmation"
|
|
447
482
|
};
|
|
448
483
|
function withTestIdPrefix(baseId, prefix) {
|
|
449
484
|
return prefix === void 0 || prefix === "" ? baseId : `${prefix}-${baseId}`;
|
|
@@ -540,6 +575,12 @@ function useAuthStyles(theme) {
|
|
|
540
575
|
marginTop: spacing.xs,
|
|
541
576
|
color: colors.danger
|
|
542
577
|
},
|
|
578
|
+
errorBody: {
|
|
579
|
+
fontSize: typography.body,
|
|
580
|
+
marginTop: spacing.xs,
|
|
581
|
+
marginBottom: spacing.md,
|
|
582
|
+
color: colors.danger
|
|
583
|
+
},
|
|
543
584
|
successText: {
|
|
544
585
|
fontSize: typography.body,
|
|
545
586
|
lineHeight: typography.body * 1.4,
|
|
@@ -1315,19 +1356,19 @@ function useResetMutation(client, callbacks) {
|
|
|
1315
1356
|
}
|
|
1316
1357
|
function runSubmit(args) {
|
|
1317
1358
|
args.setErrorKey(null);
|
|
1318
|
-
const
|
|
1359
|
+
const failure2 = preflight({
|
|
1319
1360
|
newPassword: args.newPassword,
|
|
1320
1361
|
confirm: args.confirmPassword,
|
|
1321
1362
|
token: args.token
|
|
1322
1363
|
});
|
|
1323
|
-
if (
|
|
1364
|
+
if (failure2 === null) {
|
|
1324
1365
|
args.mutate({ token: args.token, newPassword: args.newPassword });
|
|
1325
1366
|
return;
|
|
1326
1367
|
}
|
|
1327
|
-
if (
|
|
1368
|
+
if (failure2 === "tokenInvalid" /* TokenInvalid */) {
|
|
1328
1369
|
args.setHasInvalidToken(true);
|
|
1329
1370
|
}
|
|
1330
|
-
args.setErrorKey(
|
|
1371
|
+
args.setErrorKey(failure2);
|
|
1331
1372
|
}
|
|
1332
1373
|
function useFormState() {
|
|
1333
1374
|
const [newPassword, setNewPassword] = useState("");
|
|
@@ -4324,15 +4365,15 @@ function typedFailureOf(error) {
|
|
|
4324
4365
|
}
|
|
4325
4366
|
return { status: hasStatus ? status : null, errorCode: hasCode ? errorCode : null };
|
|
4326
4367
|
}
|
|
4327
|
-
function mapTypedFailure(
|
|
4328
|
-
const byCode =
|
|
4368
|
+
function mapTypedFailure(failure2) {
|
|
4369
|
+
const byCode = failure2.errorCode === null ? void 0 : BODY_ERROR_CODES[failure2.errorCode];
|
|
4329
4370
|
if (byCode !== void 0) {
|
|
4330
4371
|
return byCode;
|
|
4331
4372
|
}
|
|
4332
|
-
if (
|
|
4373
|
+
if (failure2.status === HTTP_TOO_MANY_REQUESTS) {
|
|
4333
4374
|
return "rateLimited" /* RateLimited */;
|
|
4334
4375
|
}
|
|
4335
|
-
const isServerError =
|
|
4376
|
+
const isServerError = failure2.status !== null && failure2.status >= HTTP_SERVER_ERROR_MIN;
|
|
4336
4377
|
return isServerError ? "failed" /* Failed */ : null;
|
|
4337
4378
|
}
|
|
4338
4379
|
function messageOf(error) {
|
|
@@ -4342,8 +4383,8 @@ function messageOf(error) {
|
|
|
4342
4383
|
return typeof error === "string" ? error : "";
|
|
4343
4384
|
}
|
|
4344
4385
|
function mapRegisterErrorCode(error) {
|
|
4345
|
-
const
|
|
4346
|
-
const typed =
|
|
4386
|
+
const failure2 = typedFailureOf(error);
|
|
4387
|
+
const typed = failure2 === null ? null : mapTypedFailure(failure2);
|
|
4347
4388
|
if (typed !== null) {
|
|
4348
4389
|
return typed;
|
|
4349
4390
|
}
|
|
@@ -4637,7 +4678,361 @@ function createBffChangePasswordClient(options = {}) {
|
|
|
4637
4678
|
}
|
|
4638
4679
|
};
|
|
4639
4680
|
}
|
|
4681
|
+
function useFocusOnMount(ref) {
|
|
4682
|
+
useEffect(() => {
|
|
4683
|
+
ref.current?.focus();
|
|
4684
|
+
}, [ref]);
|
|
4685
|
+
}
|
|
4686
|
+
function useResendVerification({ client, verifyUrlTemplate }) {
|
|
4687
|
+
const [email, setEmail] = useState("");
|
|
4688
|
+
const [missingEmail, setMissingEmail] = useState(false);
|
|
4689
|
+
const [submitting, setSubmitting] = useState(false);
|
|
4690
|
+
const [confirmed, setConfirmed] = useState(false);
|
|
4691
|
+
const submit = useCallback(async () => {
|
|
4692
|
+
const trimmed = email.trim();
|
|
4693
|
+
if (trimmed === "") {
|
|
4694
|
+
setMissingEmail(true);
|
|
4695
|
+
return;
|
|
4696
|
+
}
|
|
4697
|
+
setMissingEmail(false);
|
|
4698
|
+
setSubmitting(true);
|
|
4699
|
+
await client.resendVerification(trimmed, verifyUrlTemplate);
|
|
4700
|
+
setSubmitting(false);
|
|
4701
|
+
setConfirmed(true);
|
|
4702
|
+
}, [client, email, verifyUrlTemplate]);
|
|
4703
|
+
return { email, setEmail, missingEmail, submitting, confirmed, submit };
|
|
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
|
+
}
|
|
4710
|
+
function VerifyEmailResendForm({
|
|
4711
|
+
client,
|
|
4712
|
+
labels,
|
|
4713
|
+
styles: styles3,
|
|
4714
|
+
theme,
|
|
4715
|
+
verifyUrlTemplate,
|
|
4716
|
+
testIdPrefix
|
|
4717
|
+
}) {
|
|
4718
|
+
const resend = useResendVerification({ client, verifyUrlTemplate });
|
|
4719
|
+
const id = (base) => withTestIdPrefix(base, testIdPrefix);
|
|
4720
|
+
if (resend.confirmed) {
|
|
4721
|
+
return /* @__PURE__ */ jsx(ResendConfirmation, { style: styles3.successText, testID: id(AuthTestIds.verifyEmailResendConfirmation), text: labels.resendConfirmation });
|
|
4722
|
+
}
|
|
4723
|
+
const submit = () => {
|
|
4724
|
+
void resend.submit();
|
|
4725
|
+
};
|
|
4726
|
+
const buttonStyle = resend.submitting ? [styles3.primaryButton, styles3.primaryButtonDisabled] : styles3.primaryButton;
|
|
4727
|
+
return /* @__PURE__ */ jsxs(View, { testID: id(AuthTestIds.verifyEmailResendForm), children: [
|
|
4728
|
+
/* @__PURE__ */ jsxs(View, { style: styles3.fieldGroup, children: [
|
|
4729
|
+
/* @__PURE__ */ jsx(Text, { style: styles3.label, children: labels.resendEmailLabel }),
|
|
4730
|
+
/* @__PURE__ */ jsx(
|
|
4731
|
+
TextInput,
|
|
4732
|
+
{
|
|
4733
|
+
accessibilityHint: labels.resendEmailHint,
|
|
4734
|
+
accessibilityLabel: labels.resendEmailLabel,
|
|
4735
|
+
autoCapitalize: "none",
|
|
4736
|
+
autoComplete: "email",
|
|
4737
|
+
autoCorrect: false,
|
|
4738
|
+
autoFocus: true,
|
|
4739
|
+
editable: !resend.submitting,
|
|
4740
|
+
keyboardType: "email-address",
|
|
4741
|
+
placeholder: labels.resendEmailPlaceholder,
|
|
4742
|
+
placeholderTextColor: theme.colors.textSecondary,
|
|
4743
|
+
style: styles3.input,
|
|
4744
|
+
testID: id(AuthTestIds.verifyEmailResendEmail),
|
|
4745
|
+
value: resend.email,
|
|
4746
|
+
onChangeText: resend.setEmail
|
|
4747
|
+
}
|
|
4748
|
+
)
|
|
4749
|
+
] }),
|
|
4750
|
+
resend.missingEmail ? /* @__PURE__ */ jsx(Text, { style: styles3.errorBody, children: labels.resendMissingEmail }) : null,
|
|
4751
|
+
/* @__PURE__ */ jsx(
|
|
4752
|
+
TouchableOpacity,
|
|
4753
|
+
{
|
|
4754
|
+
accessibilityHint: labels.resendSubmitHint,
|
|
4755
|
+
accessibilityLabel: labels.resendSubmit,
|
|
4756
|
+
accessibilityRole: "button",
|
|
4757
|
+
disabled: resend.submitting,
|
|
4758
|
+
style: buttonStyle,
|
|
4759
|
+
testID: id(AuthTestIds.verifyEmailResendSubmit),
|
|
4760
|
+
onPress: submit,
|
|
4761
|
+
children: resend.submitting ? /* @__PURE__ */ jsx(ActivityIndicator, { color: theme.colors.onPrimary, size: "small" }) : /* @__PURE__ */ jsx(Text, { style: styles3.primaryButtonText, children: labels.resendSubmit })
|
|
4762
|
+
}
|
|
4763
|
+
)
|
|
4764
|
+
] });
|
|
4765
|
+
}
|
|
4766
|
+
|
|
4767
|
+
// src/verify/VerifyEmailErrorCode.ts
|
|
4768
|
+
var VerifyEmailErrorCode = /* @__PURE__ */ ((VerifyEmailErrorCode2) => {
|
|
4769
|
+
VerifyEmailErrorCode2["TokenInvalid"] = "TOKEN_INVALID";
|
|
4770
|
+
VerifyEmailErrorCode2["TokenExpired"] = "TOKEN_EXPIRED";
|
|
4771
|
+
VerifyEmailErrorCode2["TokenUsed"] = "TOKEN_USED";
|
|
4772
|
+
VerifyEmailErrorCode2["KeycloakUpdateFailed"] = "KEYCLOAK_UPDATE_FAILED";
|
|
4773
|
+
VerifyEmailErrorCode2["MissingToken"] = "MISSING_TOKEN";
|
|
4774
|
+
VerifyEmailErrorCode2["Generic"] = "GENERIC";
|
|
4775
|
+
return VerifyEmailErrorCode2;
|
|
4776
|
+
})(VerifyEmailErrorCode || {});
|
|
4777
|
+
|
|
4778
|
+
// src/verify/VerifyEmailPhase.ts
|
|
4779
|
+
var VerifyEmailPhase = /* @__PURE__ */ ((VerifyEmailPhase2) => {
|
|
4780
|
+
VerifyEmailPhase2["Loading"] = "loading";
|
|
4781
|
+
VerifyEmailPhase2["Success"] = "success";
|
|
4782
|
+
VerifyEmailPhase2["Failure"] = "failure";
|
|
4783
|
+
return VerifyEmailPhase2;
|
|
4784
|
+
})(VerifyEmailPhase || {});
|
|
4785
|
+
|
|
4786
|
+
// src/verify/useVerifyEmail.ts
|
|
4787
|
+
var LOADING = {
|
|
4788
|
+
phase: "loading" /* Loading */,
|
|
4789
|
+
errorCode: "GENERIC" /* Generic */
|
|
4790
|
+
};
|
|
4791
|
+
var SUCCESS = {
|
|
4792
|
+
phase: "success" /* Success */,
|
|
4793
|
+
errorCode: "GENERIC" /* Generic */
|
|
4794
|
+
};
|
|
4795
|
+
var REJECTED = { success: false, errorCode: "GENERIC" /* Generic */ };
|
|
4796
|
+
function failure(errorCode) {
|
|
4797
|
+
return { phase: "failure" /* Failure */, errorCode };
|
|
4798
|
+
}
|
|
4799
|
+
function useVerifyEmail({ client, token, onVerified, onFailed }) {
|
|
4800
|
+
const [state, setState] = useState(LOADING);
|
|
4801
|
+
const latest = useRef({ client, onVerified, onFailed });
|
|
4802
|
+
latest.current = { client, onVerified, onFailed };
|
|
4803
|
+
useEffect(() => {
|
|
4804
|
+
if (token === "") {
|
|
4805
|
+
setState(failure("MISSING_TOKEN" /* MissingToken */));
|
|
4806
|
+
latest.current.onFailed?.("MISSING_TOKEN" /* MissingToken */);
|
|
4807
|
+
return void 0;
|
|
4808
|
+
}
|
|
4809
|
+
let active = true;
|
|
4810
|
+
setState(LOADING);
|
|
4811
|
+
const settle = (result) => {
|
|
4812
|
+
if (!active) {
|
|
4813
|
+
return;
|
|
4814
|
+
}
|
|
4815
|
+
if (result.success) {
|
|
4816
|
+
setState(SUCCESS);
|
|
4817
|
+
latest.current.onVerified?.();
|
|
4818
|
+
return;
|
|
4819
|
+
}
|
|
4820
|
+
setState(failure(result.errorCode));
|
|
4821
|
+
latest.current.onFailed?.(result.errorCode);
|
|
4822
|
+
};
|
|
4823
|
+
void latest.current.client.verifyEmail(token).catch(() => REJECTED).then(settle);
|
|
4824
|
+
return () => {
|
|
4825
|
+
active = false;
|
|
4826
|
+
};
|
|
4827
|
+
}, [token]);
|
|
4828
|
+
return state;
|
|
4829
|
+
}
|
|
4830
|
+
|
|
4831
|
+
// src/verify/verifyEmailErrorText.ts
|
|
4832
|
+
function verifyEmailErrorText(code, labels) {
|
|
4833
|
+
if (code === "TOKEN_INVALID" /* TokenInvalid */) {
|
|
4834
|
+
return labels.errorInvalid;
|
|
4835
|
+
}
|
|
4836
|
+
if (code === "TOKEN_EXPIRED" /* TokenExpired */) {
|
|
4837
|
+
return labels.errorExpired;
|
|
4838
|
+
}
|
|
4839
|
+
if (code === "TOKEN_USED" /* TokenUsed */) {
|
|
4840
|
+
return labels.errorUsed;
|
|
4841
|
+
}
|
|
4842
|
+
if (code === "MISSING_TOKEN" /* MissingToken */) {
|
|
4843
|
+
return labels.missingToken;
|
|
4844
|
+
}
|
|
4845
|
+
return labels.errorGeneric;
|
|
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
|
+
}
|
|
4864
|
+
function VerifyEmailScreen({
|
|
4865
|
+
client,
|
|
4866
|
+
token,
|
|
4867
|
+
onContinue,
|
|
4868
|
+
theme: themeProp,
|
|
4869
|
+
labels: labelsProp,
|
|
4870
|
+
verifyUrlTemplate,
|
|
4871
|
+
onVerified,
|
|
4872
|
+
onFailed,
|
|
4873
|
+
testIdPrefix
|
|
4874
|
+
}) {
|
|
4875
|
+
const theme = useAuthTheme(themeProp);
|
|
4876
|
+
const styles3 = useAuthStyles(theme);
|
|
4877
|
+
const labels = useMemo(
|
|
4878
|
+
() => ({ ...DEFAULT_VERIFY_EMAIL_LABELS, ...labelsProp }),
|
|
4879
|
+
[labelsProp]
|
|
4880
|
+
);
|
|
4881
|
+
const { phase, errorCode } = useVerifyEmail({ client, token, onVerified, onFailed });
|
|
4882
|
+
const [resendOpen, setResendOpen] = useState(false);
|
|
4883
|
+
const openResend = useCallback(() => setResendOpen(true), []);
|
|
4884
|
+
const id = (base) => withTestIdPrefix(base, testIdPrefix);
|
|
4885
|
+
return /* @__PURE__ */ jsx(View, { style: styles3.screen, testID: id(AuthTestIds.verifyEmailScreen), children: /* @__PURE__ */ jsxs(View, { style: styles3.card, children: [
|
|
4886
|
+
phase === "loading" /* Loading */ ? /* @__PURE__ */ jsxs(View, { testID: id(AuthTestIds.verifyEmailLoading), children: [
|
|
4887
|
+
/* @__PURE__ */ jsx(ActivityIndicator, { color: theme.colors.primary, size: "large" }),
|
|
4888
|
+
/* @__PURE__ */ jsx(Text, { accessibilityRole: "header", style: styles3.title, children: labels.loadingTitle }),
|
|
4889
|
+
/* @__PURE__ */ jsx(Text, { style: styles3.subtitle, children: labels.loadingHint })
|
|
4890
|
+
] }) : null,
|
|
4891
|
+
phase === "success" /* Success */ ? /* @__PURE__ */ jsxs(View, { testID: id(AuthTestIds.verifyEmailSuccess), children: [
|
|
4892
|
+
/* @__PURE__ */ jsx(Text, { accessibilityRole: "header", style: styles3.title, children: labels.successTitle }),
|
|
4893
|
+
/* @__PURE__ */ jsx(Text, { style: styles3.subtitle, children: labels.successBody }),
|
|
4894
|
+
/* @__PURE__ */ jsx(
|
|
4895
|
+
TouchableOpacity,
|
|
4896
|
+
{
|
|
4897
|
+
accessibilityHint: labels.successContinueHint,
|
|
4898
|
+
accessibilityLabel: labels.successContinue,
|
|
4899
|
+
accessibilityRole: "button",
|
|
4900
|
+
style: styles3.primaryButton,
|
|
4901
|
+
testID: id(AuthTestIds.verifyEmailContinue),
|
|
4902
|
+
onPress: onContinue,
|
|
4903
|
+
children: /* @__PURE__ */ jsx(Text, { style: styles3.primaryButtonText, children: labels.successContinue })
|
|
4904
|
+
}
|
|
4905
|
+
)
|
|
4906
|
+
] }) : null,
|
|
4907
|
+
phase === "failure" /* Failure */ ? /* @__PURE__ */ jsxs(View, { testID: id(AuthTestIds.verifyEmailError), children: [
|
|
4908
|
+
/* @__PURE__ */ jsx(Text, { accessibilityRole: "header", style: styles3.title, children: labels.errorTitle }),
|
|
4909
|
+
/* @__PURE__ */ jsx(Text, { style: styles3.errorBody, children: verifyEmailErrorText(errorCode, labels) }),
|
|
4910
|
+
resendOpen ? /* @__PURE__ */ jsx(
|
|
4911
|
+
VerifyEmailResendForm,
|
|
4912
|
+
{
|
|
4913
|
+
client,
|
|
4914
|
+
labels,
|
|
4915
|
+
styles: styles3,
|
|
4916
|
+
testIdPrefix,
|
|
4917
|
+
theme,
|
|
4918
|
+
verifyUrlTemplate
|
|
4919
|
+
}
|
|
4920
|
+
) : /* @__PURE__ */ jsx(
|
|
4921
|
+
ResendCta,
|
|
4922
|
+
{
|
|
4923
|
+
hint: labels.resendCtaHint,
|
|
4924
|
+
label: labels.resendCta,
|
|
4925
|
+
style: styles3.primaryButton,
|
|
4926
|
+
testID: id(AuthTestIds.verifyEmailResendCta),
|
|
4927
|
+
textStyle: styles3.primaryButtonText,
|
|
4928
|
+
onPress: openResend
|
|
4929
|
+
}
|
|
4930
|
+
)
|
|
4931
|
+
] }) : null
|
|
4932
|
+
] }) });
|
|
4933
|
+
}
|
|
4934
|
+
var VERIFY_EMAIL_ENDPOINT = "/bff/verify-email";
|
|
4935
|
+
var RESEND_VERIFICATION_ENDPOINT = "/bff/resend-verification";
|
|
4936
|
+
var CSRF_HEADER3 = "X-BFF-Csrf";
|
|
4937
|
+
var CSRF_HEADER_VALUE3 = "1";
|
|
4938
|
+
var JSON_CONTENT_TYPE3 = "application/json";
|
|
4939
|
+
var SERVER_ERROR_CODES2 = [
|
|
4940
|
+
"TOKEN_INVALID" /* TokenInvalid */,
|
|
4941
|
+
"TOKEN_EXPIRED" /* TokenExpired */,
|
|
4942
|
+
"TOKEN_USED" /* TokenUsed */,
|
|
4943
|
+
"KEYCLOAK_UPDATE_FAILED" /* KeycloakUpdateFailed */
|
|
4944
|
+
];
|
|
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";
|
|
4949
|
+
async function lazyFetchHttpClient3(request) {
|
|
4950
|
+
const fetchImpl = typeof fetch === "function" ? fetch.bind(globalThis) : void 0;
|
|
4951
|
+
if (fetchImpl === void 0) {
|
|
4952
|
+
throw new Error("createBffVerifyEmailClient: fetch is not available in this environment");
|
|
4953
|
+
}
|
|
4954
|
+
return createFetchHttpClient(fetchImpl)(request);
|
|
4955
|
+
}
|
|
4956
|
+
function isServerErrorCode(value) {
|
|
4957
|
+
return typeof value === "string" && SERVER_ERROR_CODES2.includes(value);
|
|
4958
|
+
}
|
|
4959
|
+
function isRecord3(value) {
|
|
4960
|
+
return typeof value === "object" && value !== null;
|
|
4961
|
+
}
|
|
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) {
|
|
4969
|
+
if (!isRecord3(body)) {
|
|
4970
|
+
return GENERIC_FAILURE;
|
|
4971
|
+
}
|
|
4972
|
+
if (body.success === true) {
|
|
4973
|
+
return { success: true };
|
|
4974
|
+
}
|
|
4975
|
+
if (isServerErrorCode(body.errorCode)) {
|
|
4976
|
+
return { success: false, errorCode: body.errorCode };
|
|
4977
|
+
}
|
|
4978
|
+
return isTokenValidationRejection(status, body) ? INVALID_TOKEN : GENERIC_FAILURE;
|
|
4979
|
+
}
|
|
4980
|
+
function createBffVerifyEmailClient(options = {}) {
|
|
4981
|
+
const http = options.http ?? lazyFetchHttpClient3;
|
|
4982
|
+
const baseUrl = options.baseUrl ?? "";
|
|
4983
|
+
const post = (path, body) => http({
|
|
4984
|
+
url: `${baseUrl}${path}`,
|
|
4985
|
+
method: "POST",
|
|
4986
|
+
headers: { "Content-Type": JSON_CONTENT_TYPE3, [CSRF_HEADER3]: CSRF_HEADER_VALUE3 },
|
|
4987
|
+
body: JSON.stringify(body),
|
|
4988
|
+
credentials: "include"
|
|
4989
|
+
});
|
|
4990
|
+
return {
|
|
4991
|
+
verifyEmail: async (token) => {
|
|
4992
|
+
try {
|
|
4993
|
+
const response = await post(VERIFY_EMAIL_ENDPOINT, { token });
|
|
4994
|
+
return decodeVerifyResponse(response.status, response.data);
|
|
4995
|
+
} catch {
|
|
4996
|
+
return GENERIC_FAILURE;
|
|
4997
|
+
}
|
|
4998
|
+
},
|
|
4999
|
+
resendVerification: async (email, verifyUrlTemplate) => {
|
|
5000
|
+
const body = verifyUrlTemplate === void 0 ? { email } : { email, verifyUrlTemplate };
|
|
5001
|
+
try {
|
|
5002
|
+
const response = await post(RESEND_VERIFICATION_ENDPOINT, body);
|
|
5003
|
+
return response.ok;
|
|
5004
|
+
} catch {
|
|
5005
|
+
return false;
|
|
5006
|
+
}
|
|
5007
|
+
}
|
|
5008
|
+
};
|
|
5009
|
+
}
|
|
5010
|
+
|
|
5011
|
+
// src/verify/verifyEmailUrl.ts
|
|
5012
|
+
var VERIFY_TOKEN_PLACEHOLDER = "{token}";
|
|
5013
|
+
var DEFAULT_VERIFY_PATH = "/verify-email";
|
|
5014
|
+
function readWindowOrigin() {
|
|
5015
|
+
if (typeof window === "undefined" || typeof window.location !== "object") {
|
|
5016
|
+
return null;
|
|
5017
|
+
}
|
|
5018
|
+
return typeof window.location.origin === "string" ? window.location.origin : null;
|
|
5019
|
+
}
|
|
5020
|
+
function nonEmpty(value) {
|
|
5021
|
+
return value !== void 0 && value !== "" ? value : null;
|
|
5022
|
+
}
|
|
5023
|
+
function buildVerifyUrlTemplate(options = {}) {
|
|
5024
|
+
const origin = nonEmpty(options.origin) ?? readWindowOrigin() ?? options.fallbackOrigin ?? "";
|
|
5025
|
+
const path = options.path ?? DEFAULT_VERIFY_PATH;
|
|
5026
|
+
return `${origin}${path}?token=${VERIFY_TOKEN_PLACEHOLDER}`;
|
|
5027
|
+
}
|
|
5028
|
+
function readVerifyToken(raw) {
|
|
5029
|
+
if (typeof raw === "string") {
|
|
5030
|
+
return raw;
|
|
5031
|
+
}
|
|
5032
|
+
const first = raw?.[0];
|
|
5033
|
+
return typeof first === "string" ? first : "";
|
|
5034
|
+
}
|
|
4640
5035
|
|
|
4641
|
-
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, 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, RegisterErrorCode, RegisterForm, RegisterTestIds, ResetPasswordError, ResetPasswordForm, cachePreferredMethod, clearCachedPreferredMethod, collectUserRoles, createBffAuthClient, createBffChangePasswordClient, createPreferencesClient, defaultAuthTheme, deriveUsernameFromEmail, isAllowedPinDigits, isPasswordValid, isRegisterPasswordStrong, isValidForgotPasswordEmail, performBffLogout, readCachedPreferredMethod, readPasskeyError, readPasskeyRegistered, 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, useResetPasswordForm, validatePasswordPolicy, withTestIdPrefix };
|
|
5036
|
+
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, 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, RESEND_VERIFICATION_ENDPOINT, RegisterErrorCode, RegisterForm, RegisterTestIds, ResetPasswordError, ResetPasswordForm, VERIFY_EMAIL_ENDPOINT, VERIFY_TOKEN_PLACEHOLDER, VerifyEmailErrorCode, VerifyEmailPhase, VerifyEmailScreen, buildVerifyUrlTemplate, cachePreferredMethod, clearCachedPreferredMethod, collectUserRoles, createBffAuthClient, createBffChangePasswordClient, createBffVerifyEmailClient, createPreferencesClient, defaultAuthTheme, deriveUsernameFromEmail, isAllowedPinDigits, isPasswordValid, 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 };
|
|
4642
5037
|
//# sourceMappingURL=index.mjs.map
|
|
4643
5038
|
//# sourceMappingURL=index.mjs.map
|