@wix/members 1.0.540 → 1.0.542
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/account-details-context-provider/package.json +3 -0
- package/account-home-context-provider/package.json +3 -0
- package/address-context-provider/package.json +3 -0
- package/addresses-context-provider/package.json +3 -0
- package/build/cjs/context-account-details.d.ts +246 -0
- package/build/cjs/context-account-details.js +9508 -0
- package/build/cjs/context-account-details.js.map +1 -0
- package/build/cjs/context-account-home.d.ts +54 -0
- package/build/cjs/context-account-home.js +719 -0
- package/build/cjs/context-account-home.js.map +1 -0
- package/build/cjs/context-address.d.ts +52 -0
- package/build/cjs/context-address.js +587 -0
- package/build/cjs/context-address.js.map +1 -0
- package/build/cjs/context-addresses.d.ts +104 -0
- package/build/cjs/context-addresses.js +9054 -0
- package/build/cjs/context-addresses.js.map +1 -0
- package/build/cjs/context-authentication.d.ts +633 -0
- package/build/cjs/context-authentication.js +4253 -0
- package/build/cjs/context-authentication.js.map +1 -0
- package/build/es/context-account-details.d.mts +246 -0
- package/build/es/context-account-details.mjs +9462 -0
- package/build/es/context-account-details.mjs.map +1 -0
- package/build/es/context-account-home.d.mts +54 -0
- package/build/es/context-account-home.mjs +690 -0
- package/build/es/context-account-home.mjs.map +1 -0
- package/build/es/context-address.d.mts +52 -0
- package/build/es/context-address.mjs +557 -0
- package/build/es/context-address.mjs.map +1 -0
- package/build/es/context-addresses.d.mts +104 -0
- package/build/es/context-addresses.mjs +9012 -0
- package/build/es/context-addresses.mjs.map +1 -0
- package/build/es/context-authentication.d.mts +633 -0
- package/build/es/context-authentication.mjs +4221 -0
- package/build/es/context-authentication.mjs.map +1 -0
- package/build/internal/cjs/context-account-details.d.ts +246 -0
- package/build/internal/cjs/context-account-home.d.ts +54 -0
- package/build/internal/cjs/context-address.d.ts +52 -0
- package/build/internal/cjs/context-addresses.d.ts +104 -0
- package/build/internal/cjs/context-authentication.d.ts +633 -0
- package/build/internal/es/context-account-details.d.mts +246 -0
- package/build/internal/es/context-account-home.d.mts +54 -0
- package/build/internal/es/context-address.d.mts +52 -0
- package/build/internal/es/context-addresses.d.mts +104 -0
- package/build/internal/es/context-authentication.d.mts +633 -0
- package/context/account-details/package.json +3 -0
- package/context/account-home/package.json +3 -0
- package/context/address/package.json +3 -0
- package/context/addresses/package.json +3 -0
- package/context/authentication/package.json +3 -0
- package/context-runtime/context-account-details/runtime.d.ts +246 -0
- package/context-runtime/context-account-details/runtime.js +14 -0
- package/context-runtime/context-account-home/runtime.d.ts +54 -0
- package/context-runtime/context-account-home/runtime.js +2 -0
- package/context-runtime/context-address/runtime.d.ts +52 -0
- package/context-runtime/context-address/runtime.js +2 -0
- package/context-runtime/context-addresses/runtime.d.ts +104 -0
- package/context-runtime/context-addresses/runtime.js +14 -0
- package/context-runtime/context-authentication/runtime.d.ts +633 -0
- package/context-runtime/context-authentication/runtime.js +6 -0
- package/package.json +86 -13
|
@@ -0,0 +1,633 @@
|
|
|
1
|
+
import React, { FC, PropsWithChildren } from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/texts.d.ts
|
|
4
|
+
declare const TEXTS: {
|
|
5
|
+
readonly adminApprovalTitle: "Your signup request was sent and is pending approval";
|
|
6
|
+
readonly adminApprovalSubtitle: "You’ll be notified of your approval via the email you used to sign up:\n{email}";
|
|
7
|
+
readonly adminApprovalDescription: "Once approved, you’ll be able to log in as a site member.";
|
|
8
|
+
readonly adminApprovalButton: "Got It";
|
|
9
|
+
readonly accessRestrictedTitle: "Access to this page is restricted";
|
|
10
|
+
readonly accessRestrictedSubtitle: "You don’t have permission to view this page. Contact the site owner for more info.";
|
|
11
|
+
readonly accessRestrictedHomeButton: "Back to Site Home";
|
|
12
|
+
readonly accessRestrictedSwitchAccount: "Log in with a different email";
|
|
13
|
+
readonly expiredTokenTitle: "This link has expired";
|
|
14
|
+
readonly expiredTokenSubtitle: "To get a new reset link, go through the reset password process again.";
|
|
15
|
+
readonly expiredTokenResetButton: "Reset Password";
|
|
16
|
+
readonly expiredTokenHomeLink: "Go to Site Home";
|
|
17
|
+
readonly loginTitle: "Log In";
|
|
18
|
+
readonly loginSubtitle: "Log in to your member account and get access to exclusive content.";
|
|
19
|
+
readonly loginSwitchPrompt: "Don’t have an account?";
|
|
20
|
+
readonly loginSwitchLink: "Sign up";
|
|
21
|
+
readonly loginForgotPassword: "Forgot Password";
|
|
22
|
+
readonly loginSubmitButton: "Log In";
|
|
23
|
+
readonly loginSubmittingButton: "Logging in...";
|
|
24
|
+
readonly authDivider: "or";
|
|
25
|
+
readonly authGoogleButton: "Continue with Google";
|
|
26
|
+
readonly authFacebookButton: "Continue with Facebook";
|
|
27
|
+
readonly authSsoButton: "Continue with SSO";
|
|
28
|
+
readonly authEmailLabel: "Email";
|
|
29
|
+
readonly authPasswordLabel: "Password";
|
|
30
|
+
readonly errorPlaceholder: "If an error occurs, a message will be shown here.";
|
|
31
|
+
readonly signupTitle: "Sign Up";
|
|
32
|
+
readonly signupSubtitle: "Create an account.";
|
|
33
|
+
readonly signupSwitchPrompt: "Already have an account?";
|
|
34
|
+
readonly signupSwitchLink: "Log In";
|
|
35
|
+
readonly signupSubmitButton: "Sign Up";
|
|
36
|
+
readonly completeProfileTitle: "Finish your registration to continue";
|
|
37
|
+
readonly completeProfileButton: "Complete Registration";
|
|
38
|
+
readonly signupPolicyNote: "Your profile will be set to public automatically when you sign up. You can change this later in your profile settings.";
|
|
39
|
+
readonly signupPublicProfile: "Sign up to this site with a public profile.";
|
|
40
|
+
readonly signupShowMore: "Show more";
|
|
41
|
+
readonly signupShowLess: "Show less";
|
|
42
|
+
readonly resetPasswordTitle: "Reset password";
|
|
43
|
+
readonly resetPasswordSubtitle: "Enter your login email and we'll send you a link to reset your password.";
|
|
44
|
+
readonly resetPasswordEmailLabel: "Login email";
|
|
45
|
+
readonly resetPasswordSubmitButton: "Send Link";
|
|
46
|
+
readonly resetPasswordLinkTitle: "Reset password link was sent";
|
|
47
|
+
readonly resetPasswordLinkSubtitle: "To finish resetting your password, use the link we sent to";
|
|
48
|
+
readonly resetPasswordGotItButton: "Got it";
|
|
49
|
+
readonly resetPasswordSpamNote: "Didn't get the email? Check your spam.";
|
|
50
|
+
readonly errorInvalidEmail: "Invalid email address.";
|
|
51
|
+
readonly errorGeneral: "We're having an issue on our end, refresh and try again.";
|
|
52
|
+
readonly errorResetPasswordUserNotFound: "An account with that email doesn't exist.";
|
|
53
|
+
readonly errorResetPasswordInvalidEmail: "That email is invalid, check your email and try again.";
|
|
54
|
+
readonly errorTooManyEmails: "We sent you too many emails. Wait a bit before clicking resend again.";
|
|
55
|
+
readonly errorTooManyRequests: "You've made too many attempts. Wait a bit before trying again.";
|
|
56
|
+
readonly emailConfirmationTitle: "Confirm your email";
|
|
57
|
+
readonly emailConfirmationSubtitle: "To finish signing up, confirm your email by entering the 6-digit code sent to";
|
|
58
|
+
readonly emailConfirmationCodeLabel: "Enter 6-digit code";
|
|
59
|
+
readonly emailConfirmationSubmitButton: "Confirm Email";
|
|
60
|
+
readonly emailConfirmationSpamNote: "Didn't get the email? Check your spam.";
|
|
61
|
+
readonly emailConfirmationResendButton: "Resend Code";
|
|
62
|
+
readonly emailConfirmationResendTimer: "Code was sent. You can resend in 0:{30}";
|
|
63
|
+
readonly createPasswordTitle: "Create new password";
|
|
64
|
+
readonly createPasswordNewLabel: "Enter new password";
|
|
65
|
+
readonly createPasswordConfirmLabel: "Confirm new password";
|
|
66
|
+
readonly createPasswordSubmitButton: "Create password";
|
|
67
|
+
readonly createPasswordSuccessTitle: "You're all set";
|
|
68
|
+
readonly createPasswordSuccessText: "Your password was changed.";
|
|
69
|
+
readonly createPasswordLoginButton: "Log In";
|
|
70
|
+
readonly createPasswordHomeButton: "Go to Site Home";
|
|
71
|
+
readonly errorPasswordsDoNotMatch: "Passwords do not match. Try again.";
|
|
72
|
+
readonly errorWrongCredentials: "Wrong email or password";
|
|
73
|
+
readonly errorEmailExists: "An account with this email already exists. Try logging in with your password or the Google or Facebook account you used to sign up.";
|
|
74
|
+
readonly errorCaptcha: "Captcha is required to verify that you're a human.";
|
|
75
|
+
readonly captchaNotTicked: "Select the “I’m not a robot” checkbox to continue.";
|
|
76
|
+
readonly errorAccessDenied: "Unable to log in with that email. Try a different account.";
|
|
77
|
+
readonly errorPasswordResetRequired: "Your password has been reset. To log in, click Forgot Password above & create a new password.";
|
|
78
|
+
readonly errorInvalidCode: "That code isn't correct, try again.";
|
|
79
|
+
readonly errorPasswordTooShort: "Enter a password with at least 6 characters.";
|
|
80
|
+
readonly fieldEmailRequired: "Enter an email address.";
|
|
81
|
+
readonly fieldEmailInvalid: "Enter an email address, like example@email.com";
|
|
82
|
+
readonly fieldPasswordRequired: "Enter a password.";
|
|
83
|
+
readonly fieldRequired: "This field is required.";
|
|
84
|
+
readonly passwordShow: "Show password";
|
|
85
|
+
readonly passwordHide: "Hide password";
|
|
86
|
+
readonly fieldCodeRequired: "Enter the 6-digit code to verify.";
|
|
87
|
+
readonly errorPopupBlocked: "Allow pop-ups for this site, then try again.";
|
|
88
|
+
readonly errorNoPendingStep: "This code has expired. Sign up or log in again.";
|
|
89
|
+
};
|
|
90
|
+
type TextName = keyof typeof TEXTS;
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/platform-services.d.ts
|
|
93
|
+
interface PageConfig {
|
|
94
|
+
title: string;
|
|
95
|
+
path: string;
|
|
96
|
+
popup: boolean;
|
|
97
|
+
appPageId?: string;
|
|
98
|
+
appDefinitionId?: string;
|
|
99
|
+
}
|
|
100
|
+
interface PagesService {
|
|
101
|
+
readonly pages: Record<string, PageConfig>;
|
|
102
|
+
}
|
|
103
|
+
type LoginMethodType = 'PASSWORD' | 'GOOGLE' | 'FACEBOOK' | 'APPLE' | 'SSO';
|
|
104
|
+
interface LoginMethod {
|
|
105
|
+
/** The login connection's ID, for loginWithIdp. */
|
|
106
|
+
connectionId: string;
|
|
107
|
+
/** The login method's name, e.g. Google. */
|
|
108
|
+
name: string;
|
|
109
|
+
/** PASSWORD, GOOGLE, FACEBOOK, APPLE or SSO. */
|
|
110
|
+
type: LoginMethodType;
|
|
111
|
+
}
|
|
112
|
+
type CaptchaStatus = 'REQUIRED' | 'NOT_REQUIRED';
|
|
113
|
+
type CaptchaOption = 'NEVER' | 'SUSPECTED_BOTS_ONLY' | 'ALWAYS';
|
|
114
|
+
interface SignupCustomField {
|
|
115
|
+
/** The field's key: the field name to set its value under. */
|
|
116
|
+
key: string;
|
|
117
|
+
/** The field's label. */
|
|
118
|
+
label: string;
|
|
119
|
+
/** REQUIRED or OPTIONAL. */
|
|
120
|
+
requirement: 'REQUIRED' | 'OPTIONAL';
|
|
121
|
+
}
|
|
122
|
+
/** The site's member login and signup settings. */
|
|
123
|
+
interface LoginSettings {
|
|
124
|
+
/** The ways members can log in on this site, e.g. email and password, Google or SSO. */
|
|
125
|
+
availableLoginMethods: LoginMethod[];
|
|
126
|
+
/** REQUIRED when login asks for a captcha, else NOT_REQUIRED. */
|
|
127
|
+
loginCaptchaStatus: CaptchaStatus;
|
|
128
|
+
/** REQUIRED when signup asks for a captcha, else NOT_REQUIRED. */
|
|
129
|
+
signupCaptchaStatus: CaptchaStatus;
|
|
130
|
+
/**
|
|
131
|
+
* When login asks for a captcha: NEVER, SUSPECTED_BOTS_ONLY or ALWAYS. loginCaptchaStatus is
|
|
132
|
+
* REQUIRED unless it's NEVER.
|
|
133
|
+
*/
|
|
134
|
+
loginCaptchaOption: CaptchaOption;
|
|
135
|
+
/**
|
|
136
|
+
* When signup asks for a captcha: NEVER, SUSPECTED_BOTS_ONLY or ALWAYS. signupCaptchaStatus is
|
|
137
|
+
* REQUIRED unless it's NEVER.
|
|
138
|
+
*/
|
|
139
|
+
signupCaptchaOption: CaptchaOption;
|
|
140
|
+
/** ENABLED when the site allows social login, else DISABLED. */
|
|
141
|
+
socialLoginStatus: 'ENABLED' | 'DISABLED';
|
|
142
|
+
/**
|
|
143
|
+
* ALLOWED when members can have a public profile: the site lets anyone have one and has a page
|
|
144
|
+
* that shows profiles, e.g. Forum or Groups. Else NOT_ALLOWED.
|
|
145
|
+
*/
|
|
146
|
+
publicMembersStatus: 'ALLOWED' | 'NOT_ALLOWED';
|
|
147
|
+
/** Whether new members confirm their email with a code: NONE, AFTER_SIGNUP or DURING_SIGNUP. */
|
|
148
|
+
signupEmailVerificationMode: 'NONE' | 'AFTER_SIGNUP' | 'DURING_SIGNUP';
|
|
149
|
+
/** The extra fields the site's signup form asks for. */
|
|
150
|
+
signupCustomFields: SignupCustomField[];
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* The site's login settings under their old names, as the site-members service returns them.
|
|
154
|
+
* Use LoginSettings.
|
|
155
|
+
*/
|
|
156
|
+
interface SignInSettings extends Omit<LoginSettings, 'availableLoginMethods' | 'socialLoginStatus'> {
|
|
157
|
+
/** LoginSettings.availableLoginMethods. */
|
|
158
|
+
availableSignInMethods: LoginMethod[];
|
|
159
|
+
/** LoginSettings.socialLoginStatus. */
|
|
160
|
+
socialSignInStatus: LoginSettings['socialLoginStatus'];
|
|
161
|
+
}
|
|
162
|
+
type ProfilePrivacyStatus = 'PUBLIC' | 'PRIVATE';
|
|
163
|
+
/** Keyed by a signup custom field's `key`, e.g. `firstName`. */
|
|
164
|
+
type SignupFieldValues = Record<string, unknown>;
|
|
165
|
+
/** Where the member stands after an authentication call. Every status but SUCCESS is a parked step. */
|
|
166
|
+
type AuthenticationResult = {
|
|
167
|
+
status: 'SUCCESS';
|
|
168
|
+
} | {
|
|
169
|
+
status: 'EMAIL_VERIFICATION_REQUIRED';
|
|
170
|
+
email: string;
|
|
171
|
+
} | {
|
|
172
|
+
status: 'OWNER_APPROVAL_REQUIRED';
|
|
173
|
+
email: string;
|
|
174
|
+
} | {
|
|
175
|
+
status: 'PROFILE_COMPLETION_REQUIRED';
|
|
176
|
+
email: string;
|
|
177
|
+
prefilledFieldValues: SignupFieldValues;
|
|
178
|
+
};
|
|
179
|
+
type PendingAuthentication = Exclude<AuthenticationResult, {
|
|
180
|
+
status: 'SUCCESS';
|
|
181
|
+
}>;
|
|
182
|
+
interface CaptchaLocalesOption {
|
|
183
|
+
/**
|
|
184
|
+
* The translated texts of the captcha dialog the service opens when the server demands a
|
|
185
|
+
* captcha; a missing one stays English. A service without it ignores it.
|
|
186
|
+
*/
|
|
187
|
+
captchaLocales?: {
|
|
188
|
+
title?: string;
|
|
189
|
+
subtitle?: string;
|
|
190
|
+
closeButtonAriaLabel?: string;
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
interface SiteMembersService {
|
|
194
|
+
/** The host's own login dialog. This app never calls it: authentication goes through `login`. */
|
|
195
|
+
promptLogin?: (options?: {
|
|
196
|
+
mode?: 'login' | 'signup';
|
|
197
|
+
modal?: boolean;
|
|
198
|
+
}) => Promise<unknown>;
|
|
199
|
+
login?: (email: string, password: string, options?: {
|
|
200
|
+
captchaToken?: string;
|
|
201
|
+
invisibleCaptchaToken?: string;
|
|
202
|
+
} & CaptchaLocalesOption) => Promise<AuthenticationResult>;
|
|
203
|
+
signup?: (email: string, password: string, options?: {
|
|
204
|
+
signupFieldValues?: SignupFieldValues;
|
|
205
|
+
privacyStatus?: ProfilePrivacyStatus;
|
|
206
|
+
captchaToken?: string;
|
|
207
|
+
invisibleCaptchaToken?: string;
|
|
208
|
+
} & CaptchaLocalesOption) => Promise<AuthenticationResult>;
|
|
209
|
+
/** Sends the emailed code, after EMAIL_VERIFICATION_REQUIRED. */
|
|
210
|
+
verifyEmail?: (code: string) => Promise<AuthenticationResult>;
|
|
211
|
+
/** Emails a new code, after EMAIL_VERIFICATION_REQUIRED. */
|
|
212
|
+
resendVerificationCodeEmail?: () => Promise<void>;
|
|
213
|
+
/** `connectionId` is from SignInSettings.availableSignInMethods. */
|
|
214
|
+
loginWithIdp?: (connectionId: string, options?: {
|
|
215
|
+
privacyStatus?: ProfilePrivacyStatus;
|
|
216
|
+
}) => Promise<AuthenticationResult>;
|
|
217
|
+
/** Sends the required signup fields, after PROFILE_COMPLETION_REQUIRED. */
|
|
218
|
+
completeProfile?: (signupFieldValues: SignupFieldValues, privacyStatus?: ProfilePrivacyStatus) => Promise<AuthenticationResult>;
|
|
219
|
+
/** The step the current flow is parked on, for a popup that continues it. Null when none. */
|
|
220
|
+
getPendingAuthentication?: () => PendingAuthentication | null;
|
|
221
|
+
sendResetPasswordEmail?: (email: string) => Promise<void>;
|
|
222
|
+
/** Sets the new password; `recoveryToken` comes from the reset-password email link. */
|
|
223
|
+
changePassword?: (newPassword: string, recoveryToken: string) => Promise<void>;
|
|
224
|
+
/** Opens the Login popup. */
|
|
225
|
+
goToLogin?: () => Promise<void>;
|
|
226
|
+
/** Opens the Sign Up popup. */
|
|
227
|
+
goToSignup?: () => Promise<void>;
|
|
228
|
+
/** Opens the Forgot / Reset Password popup. */
|
|
229
|
+
goToResetPassword?: () => Promise<void>;
|
|
230
|
+
/** Opens the Email Confirmation popup, with the parked step's email as its context. */
|
|
231
|
+
goToEmailConfirmation?: () => Promise<void>;
|
|
232
|
+
/** Opens the Admin Approval popup, with the parked step's email as its context. */
|
|
233
|
+
goToAdminApproval?: () => Promise<void>;
|
|
234
|
+
/** Navigates to the app's Access Restricted page. */
|
|
235
|
+
goToAccessRestricted?: () => Promise<void>;
|
|
236
|
+
/** Navigates to the app's Expired Token page. */
|
|
237
|
+
goToExpiredToken?: () => Promise<void>;
|
|
238
|
+
/** Navigates to the app's Create Password page, with no query params. */
|
|
239
|
+
goToCreatePassword?: () => Promise<void>;
|
|
240
|
+
/** Navigates to the site's home page. */
|
|
241
|
+
goToSiteHome?: () => Promise<void>;
|
|
242
|
+
/** Closes the popup that is open. */
|
|
243
|
+
closePopup?: () => Promise<void>;
|
|
244
|
+
/** The host's logout, passed through: it clears the session and reloads the page. */
|
|
245
|
+
logout?: () => Promise<void>;
|
|
246
|
+
/** The site's sign-in methods, captcha, social login, community and signup settings. */
|
|
247
|
+
getSignInSettings?: () => Promise<SignInSettings>;
|
|
248
|
+
isInitiallyLoggedIn?: boolean;
|
|
249
|
+
/** The current member, or null for a visitor. Only after hydration: the server render has none. */
|
|
250
|
+
getMemberDetails?: () => Promise<MemberDetails | null>;
|
|
251
|
+
/** Called with the member who just logged in. */
|
|
252
|
+
addMemberLoginListener?: (callback: (member?: MemberDetails) => void) => unknown;
|
|
253
|
+
removeMemberLoginListener?: (callbackId: unknown) => void;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* The part of the site-members service's MemberDetails the context reads: the logged-in member's
|
|
257
|
+
* own details, which their session already gets. `status` is e.g. ACTIVE, PENDING, APPLICANT or
|
|
258
|
+
* BLOCKED; `role` e.g. MEMBER, OWNER or CONTRIBUTOR. The service has no groups (Thunderbolt leaves
|
|
259
|
+
* them undefined).
|
|
260
|
+
*/
|
|
261
|
+
interface MemberDetails {
|
|
262
|
+
id?: string;
|
|
263
|
+
status?: string;
|
|
264
|
+
role?: string;
|
|
265
|
+
}
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region src/extensions/context-provider/screens.d.ts
|
|
268
|
+
type ScreenFunctionName = 'openAccessRestricted' | 'openCreatePassword' | 'openExpiredToken' | 'openAdminApproval' | 'openEmailConfirmation';
|
|
269
|
+
//#endregion
|
|
270
|
+
//#region src/extensions/context-provider/slices/index.d.ts
|
|
271
|
+
declare const contextSlices: readonly [{
|
|
272
|
+
name: string;
|
|
273
|
+
defaults: LoginSettingsSliceValue;
|
|
274
|
+
load: (services: ContextServices, readFailed: (() => void) | undefined) => Promise<LoginSettingsSliceValue>;
|
|
275
|
+
}];
|
|
276
|
+
declare const liveContextSlices: readonly [{
|
|
277
|
+
name: string;
|
|
278
|
+
defaults: {
|
|
279
|
+
memberState: {
|
|
280
|
+
id: string;
|
|
281
|
+
status: string;
|
|
282
|
+
role: string;
|
|
283
|
+
loginStatus: "LOGGED_OUT";
|
|
284
|
+
};
|
|
285
|
+
isLoggedIn: false;
|
|
286
|
+
};
|
|
287
|
+
useValue: ({
|
|
288
|
+
siteMembers
|
|
289
|
+
}: ContextServices) => {
|
|
290
|
+
memberState: {
|
|
291
|
+
id: string;
|
|
292
|
+
status: string;
|
|
293
|
+
role: string;
|
|
294
|
+
loginStatus: LoginStatus;
|
|
295
|
+
};
|
|
296
|
+
isLoggedIn: boolean;
|
|
297
|
+
};
|
|
298
|
+
}, {
|
|
299
|
+
name: string;
|
|
300
|
+
defaults: {
|
|
301
|
+
resendEmailCode: () => void;
|
|
302
|
+
resendState: ResendState;
|
|
303
|
+
resendSecondsLeft: number;
|
|
304
|
+
loginFormState: ActionState;
|
|
305
|
+
signupFormState: ActionState;
|
|
306
|
+
resendVerificationCodeEmail: () => Promise<never>;
|
|
307
|
+
resendVerificationCodeState: ResendVerificationCodeState;
|
|
308
|
+
emailConfirmationFormState: {
|
|
309
|
+
emailToConfirm: string;
|
|
310
|
+
status: ActionStatus;
|
|
311
|
+
errorCode: string | null;
|
|
312
|
+
errorReason: ErrorReason | null;
|
|
313
|
+
errorMessage: string | null;
|
|
314
|
+
};
|
|
315
|
+
loginWithIdp: () => Promise<never>;
|
|
316
|
+
loginWithProvider: () => void;
|
|
317
|
+
completeProfile: () => Promise<never>;
|
|
318
|
+
completeProfileState: {
|
|
319
|
+
profileCompletionRequired: false;
|
|
320
|
+
prefilledFieldValues: {};
|
|
321
|
+
status: ActionStatus;
|
|
322
|
+
errorCode: string | null;
|
|
323
|
+
errorReason: ErrorReason | null;
|
|
324
|
+
errorMessage: string | null;
|
|
325
|
+
};
|
|
326
|
+
pendingApprovalState: {
|
|
327
|
+
pendingApprovalEmail: string;
|
|
328
|
+
};
|
|
329
|
+
logout: () => Promise<never>;
|
|
330
|
+
setFieldValue: () => void;
|
|
331
|
+
setFieldFromInput: () => void;
|
|
332
|
+
setPasswordValue: () => void;
|
|
333
|
+
submitLogin: () => Promise<void>;
|
|
334
|
+
submitSignup: () => Promise<void>;
|
|
335
|
+
submitEmailCode: () => Promise<void>;
|
|
336
|
+
clearFormErrors: () => void;
|
|
337
|
+
};
|
|
338
|
+
useValue: ({
|
|
339
|
+
siteMembers
|
|
340
|
+
}: ContextServices, {
|
|
341
|
+
forms,
|
|
342
|
+
loginSettings
|
|
343
|
+
}: LiveContextShared) => {
|
|
344
|
+
resendEmailCode: () => undefined;
|
|
345
|
+
resendState: ResendState;
|
|
346
|
+
resendSecondsLeft: number;
|
|
347
|
+
loginFormState: ActionState;
|
|
348
|
+
signupFormState: ActionState;
|
|
349
|
+
resendVerificationCodeEmail: () => Promise<void>;
|
|
350
|
+
resendVerificationCodeState: ResendVerificationCodeState;
|
|
351
|
+
emailConfirmationFormState: EmailConfirmationState;
|
|
352
|
+
loginWithIdp: (connectionId: string, options?: LoginWithIdpOptions) => Promise<void>;
|
|
353
|
+
loginWithProvider: (provider: string) => void;
|
|
354
|
+
completeProfile: (signupFieldValues?: SignupFieldValues, privacyStatus?: ProfilePrivacyStatus) => Promise<void>;
|
|
355
|
+
completeProfileState: CompleteProfileState;
|
|
356
|
+
pendingApprovalState: PendingApprovalState;
|
|
357
|
+
logout: () => Promise<void>;
|
|
358
|
+
setFieldValue: (fieldName: string, value: string) => void;
|
|
359
|
+
setFieldFromInput: (fieldName: string, input?: unknown) => void;
|
|
360
|
+
setPasswordValue: (fieldName: string, value: string) => void;
|
|
361
|
+
submitLogin: () => Promise<void | undefined>;
|
|
362
|
+
submitSignup: (formValues?: SignupFieldValues) => Promise<void | undefined>;
|
|
363
|
+
submitEmailCode: () => Promise<void | undefined>;
|
|
364
|
+
clearFormErrors: () => void;
|
|
365
|
+
};
|
|
366
|
+
}, {
|
|
367
|
+
name: string;
|
|
368
|
+
defaults: {
|
|
369
|
+
resetPasswordState: ActionState;
|
|
370
|
+
changePasswordState: ActionState;
|
|
371
|
+
submitResetPasswordEmail: () => Promise<void>;
|
|
372
|
+
submitChangePassword: () => Promise<void>;
|
|
373
|
+
};
|
|
374
|
+
useValue: ({
|
|
375
|
+
siteMembers
|
|
376
|
+
}: ContextServices, {
|
|
377
|
+
forms
|
|
378
|
+
}: LiveContextShared) => {
|
|
379
|
+
resetPasswordState: ActionState;
|
|
380
|
+
changePasswordState: ActionState;
|
|
381
|
+
submitResetPasswordEmail: () => Promise<void | undefined>;
|
|
382
|
+
submitChangePassword: () => Promise<void | undefined>;
|
|
383
|
+
};
|
|
384
|
+
}, {
|
|
385
|
+
name: string;
|
|
386
|
+
defaults: {
|
|
387
|
+
goToLogin: () => Promise<never>;
|
|
388
|
+
goToSignup: () => Promise<never>;
|
|
389
|
+
goToResetPassword: () => Promise<never>;
|
|
390
|
+
goToSiteHome: () => Promise<never>;
|
|
391
|
+
closePopup: () => Promise<never>;
|
|
392
|
+
openLogin: () => void;
|
|
393
|
+
navigateHome: () => void;
|
|
394
|
+
openLoginPopup: () => void;
|
|
395
|
+
openSignupPopup: () => void;
|
|
396
|
+
openCompleteProfilePopup: () => void;
|
|
397
|
+
openResetPassword: () => void;
|
|
398
|
+
};
|
|
399
|
+
useValue: ({
|
|
400
|
+
siteMembers
|
|
401
|
+
}: ContextServices) => {
|
|
402
|
+
goToLogin: () => Promise<void>;
|
|
403
|
+
goToSignup: () => Promise<void>;
|
|
404
|
+
goToResetPassword: () => Promise<void>;
|
|
405
|
+
goToSiteHome: () => Promise<void>;
|
|
406
|
+
closePopup: () => Promise<void>;
|
|
407
|
+
openLogin: () => undefined;
|
|
408
|
+
navigateHome: () => undefined;
|
|
409
|
+
openLoginPopup: () => undefined;
|
|
410
|
+
openSignupPopup: () => undefined;
|
|
411
|
+
openCompleteProfilePopup: () => void;
|
|
412
|
+
openResetPassword: () => undefined;
|
|
413
|
+
};
|
|
414
|
+
}, {
|
|
415
|
+
name: string;
|
|
416
|
+
defaults: Record<ScreenFunctionName, () => void>;
|
|
417
|
+
useValue: ({
|
|
418
|
+
siteMembers
|
|
419
|
+
}: ContextServices) => Record<ScreenFunctionName, () => void>;
|
|
420
|
+
}, {
|
|
421
|
+
name: string;
|
|
422
|
+
defaults: {
|
|
423
|
+
closeEmailConfirmation: () => void;
|
|
424
|
+
};
|
|
425
|
+
useValue: ({
|
|
426
|
+
siteMembers
|
|
427
|
+
}: ContextServices) => {
|
|
428
|
+
closeEmailConfirmation: () => void;
|
|
429
|
+
};
|
|
430
|
+
}, {
|
|
431
|
+
name: string;
|
|
432
|
+
defaults: {
|
|
433
|
+
formFields: FormFields;
|
|
434
|
+
};
|
|
435
|
+
useValue: (_services: ContextServices, {
|
|
436
|
+
forms
|
|
437
|
+
}: LiveContextShared) => {
|
|
438
|
+
formFields: FormFields;
|
|
439
|
+
};
|
|
440
|
+
}];
|
|
441
|
+
//#endregion
|
|
442
|
+
//#region src/extensions/context-provider/form-bindings.d.ts
|
|
443
|
+
/**
|
|
444
|
+
* What a form built from editor elements binds to, one per provider and shared by its slices: its
|
|
445
|
+
* fields set their values with setFieldValue, its submit button calls a parameter-less submit
|
|
446
|
+
* function that reads them, and clearFormErrors clears every state a form's error shows in.
|
|
447
|
+
*/
|
|
448
|
+
interface FormBindings {
|
|
449
|
+
setFieldValue: (fieldName: string, value: string) => void;
|
|
450
|
+
/** setFieldValue with the text of what a bound input passes its change handler. */
|
|
451
|
+
setFieldFromInput: (fieldName: string, input?: unknown) => void;
|
|
452
|
+
/** A field's value; empty when the form never set it. */
|
|
453
|
+
field: (fieldName: string) => string;
|
|
454
|
+
/** Whether the form set the field, e.g. a Confirm Password field. */
|
|
455
|
+
hasField: (fieldName: string) => boolean;
|
|
456
|
+
/** Every field the form set. */
|
|
457
|
+
fieldValues: () => Record<string, string>;
|
|
458
|
+
/** Adds what clears a slice's states that hold an error; returns its removal. */
|
|
459
|
+
addErrorClearer: (clear: () => void) => () => void;
|
|
460
|
+
clearFormErrors: () => void;
|
|
461
|
+
/** Calls `listener` with every field after each change; returns its removal. */
|
|
462
|
+
subscribe: (listener: (values: Record<string, string>) => void) => () => void;
|
|
463
|
+
}
|
|
464
|
+
//#endregion
|
|
465
|
+
//#region src/extensions/context-provider/types.d.ts
|
|
466
|
+
interface ContextServices {
|
|
467
|
+
siteMembers?: SiteMembersService;
|
|
468
|
+
pages?: PagesService;
|
|
469
|
+
}
|
|
470
|
+
/** Data loaded once per page, when the first context mounts; it suspends until every load resolves. */
|
|
471
|
+
interface ContextSlice<T extends object> {
|
|
472
|
+
name: string;
|
|
473
|
+
defaults: T;
|
|
474
|
+
/** Calls `readFailed` when a read fails and part of the value is the defaults. */
|
|
475
|
+
load: (services: ContextServices, readFailed?: () => void) => Promise<T>;
|
|
476
|
+
}
|
|
477
|
+
/** What every live slice of one provider shares. */
|
|
478
|
+
interface LiveContextShared {
|
|
479
|
+
/** The fields a form built from editor elements set, and its errors' clearing. */
|
|
480
|
+
forms: FormBindings;
|
|
481
|
+
/** The site's login settings, as loaded when the context mounted. */
|
|
482
|
+
loginSettings: LoginSettings;
|
|
483
|
+
}
|
|
484
|
+
interface LiveContextSlice<T extends object> {
|
|
485
|
+
name: string;
|
|
486
|
+
defaults: T;
|
|
487
|
+
useValue: (services: ContextServices, shared: LiveContextShared) => T;
|
|
488
|
+
}
|
|
489
|
+
type ActionStatus =
|
|
490
|
+
/**
|
|
491
|
+
* No request yet, the form's error was cleared, or the visitor closed a social login's provider
|
|
492
|
+
* window: when the page gets the focus back while SUBMITTING, the state returns to IDLE, and a
|
|
493
|
+
* late result can still set SUCCESS or ERROR.
|
|
494
|
+
*/
|
|
495
|
+
'IDLE' /** The request is running. */ | 'SUBMITTING'
|
|
496
|
+
/**
|
|
497
|
+
* The last request went through. For a login, signup, email code, social login or profile
|
|
498
|
+
* completion, that includes one that now waits for an email code, the site owner's approval or
|
|
499
|
+
* profile details, so check isLoggedIn to know whether the visitor is logged in.
|
|
500
|
+
*/
|
|
501
|
+
| 'SUCCESS' /** The last request failed: see errorReason, errorCode and errorMessage. */ | 'ERROR';
|
|
502
|
+
/**
|
|
503
|
+
* Why a call failed, in a few stable values a site owner can check, e.g. to show an element of
|
|
504
|
+
* their own. Most come from the site-members service's error; the context gives the others.
|
|
505
|
+
*/
|
|
506
|
+
type ErrorReason = /** Wrong email or password, or no such member. */'INVALID_CREDENTIALS' /** The server wants a solved captcha first. */ | 'CAPTCHA_REQUIRED' /** A member with this email already exists. */ | 'EMAIL_ALREADY_EXISTS' /** The email confirmation code is wrong or expired. */ | 'INVALID_VERIFICATION_CODE' /** A field failed the server's validation. */ | 'INVALID_INPUT' /** The member is blocked, or the site doesn't let them in this way. */ | 'ACCESS_DENIED' /** The member must set a new password first. */ | 'PASSWORD_RESET_REQUIRED' /** No signup or login is waiting for this step (e.g. an email code), or it expired. */ | 'NO_PENDING_STEP' /** Social login can't run here, e.g. the browser blocked the provider's window. */ | 'NOT_SUPPORTED' /** The site isn't set up for this call. */ | 'MISSING_HOST_INJECTION' /** The social login isn't enabled on the site. */ | 'CONNECTION_NOT_ENABLED' /** Reset Password: no member has this email. */ | 'USER_NOT_FOUND' /** Reset Password: the server refused the email address. */ | 'INVALID_EMAIL' /** Too many emails were sent to this address; wait before asking again. */ | 'TOO_MANY_EMAILS' /** Too many attempts; wait before trying again. */ | 'TOO_MANY_REQUESTS' /** Change Password: the reset link is missing, used, expired or broken; the Expired Token page opens. */ | 'EXPIRED_LINK' /** Change Password: the new password and its retype differ. */ | 'PASSWORDS_DO_NOT_MATCH' /** The call can't run on this page (no site-members service, or it lacks the call). */ | 'UNAVAILABLE' /** Anything else. */ | 'UNKNOWN';
|
|
507
|
+
interface ActionState {
|
|
508
|
+
/** Where the last request stands: IDLE, SUBMITTING while it runs, then SUCCESS or ERROR. */
|
|
509
|
+
status: ActionStatus;
|
|
510
|
+
/**
|
|
511
|
+
* The error's code: the server's, e.g. `-19976`, the service's reason when the server gave none,
|
|
512
|
+
* or the context's own, e.g. `PASSWORDS_DO_NOT_MATCH`; `UNKNOWN` when the error has no code.
|
|
513
|
+
* null unless ERROR.
|
|
514
|
+
*/
|
|
515
|
+
errorCode: string | null;
|
|
516
|
+
/** Why it failed, see ErrorReason; null unless ERROR. */
|
|
517
|
+
errorReason: ErrorReason | null;
|
|
518
|
+
/**
|
|
519
|
+
* The text the site's login, signup, email confirmation and password screens show for the
|
|
520
|
+
* error, in the site's language (English until that language's texts load, or when a text has
|
|
521
|
+
* no translation); null unless ERROR.
|
|
522
|
+
*/
|
|
523
|
+
errorMessage: string | null;
|
|
524
|
+
}
|
|
525
|
+
type LoginStatus = 'LOGGED_IN' | 'LOGGED_OUT';
|
|
526
|
+
/**
|
|
527
|
+
* What the declared form fields hold ('' until set). No other field is here, so passwords and
|
|
528
|
+
* captcha tokens never are; the submits still send them. An object type, not a Record, so each
|
|
529
|
+
* field carries its own description on the docs page.
|
|
530
|
+
*/
|
|
531
|
+
type FormFields = {
|
|
532
|
+
/** The `email` field. */email: string; /** The `code` field: the email confirmation code. */
|
|
533
|
+
code: string; /** The `firstName` signup field. */
|
|
534
|
+
firstName: string; /** The `lastName` signup field. */
|
|
535
|
+
lastName: string;
|
|
536
|
+
};
|
|
537
|
+
interface LoginSettingsSliceValue {
|
|
538
|
+
/**
|
|
539
|
+
* The site's member login and signup settings: login methods, captcha, social login, community
|
|
540
|
+
* and signup options. Read-only: loaded when the context mounts. When they can't be loaded, the
|
|
541
|
+
* defaults: no login methods, no captcha, social login off, no public community, no email
|
|
542
|
+
* verification and no custom fields.
|
|
543
|
+
*/
|
|
544
|
+
loginSettings: LoginSettings;
|
|
545
|
+
/**
|
|
546
|
+
* Whether Login and Signup show the SSO button: the site has an available login method of type
|
|
547
|
+
* SSO. False with the defaults, i.e. when the settings can't be loaded.
|
|
548
|
+
*/
|
|
549
|
+
isSsoEnabled: boolean;
|
|
550
|
+
/**
|
|
551
|
+
* loginSettings under its old name, with `availableSignInMethods` and `socialSignInStatus` for
|
|
552
|
+
* availableLoginMethods and socialLoginStatus.
|
|
553
|
+
* @deprecated Use loginSettings.
|
|
554
|
+
*/
|
|
555
|
+
signInSettings: SignInSettings;
|
|
556
|
+
/**
|
|
557
|
+
* isSsoEnabled under its old name.
|
|
558
|
+
* @deprecated Use isSsoEnabled.
|
|
559
|
+
*/
|
|
560
|
+
ssoEnabled: boolean;
|
|
561
|
+
}
|
|
562
|
+
interface EmailConfirmationState extends ActionState {
|
|
563
|
+
/**
|
|
564
|
+
* The address the code was sent to; '' until a signup or login waits for a code or the popup
|
|
565
|
+
* was opened with an email.
|
|
566
|
+
*/
|
|
567
|
+
emailToConfirm: string;
|
|
568
|
+
}
|
|
569
|
+
interface CompleteProfileState extends ActionState {
|
|
570
|
+
/**
|
|
571
|
+
* A social signup is waiting for the signup form's other fields: the Signup screen asks for
|
|
572
|
+
* them instead of a new signup.
|
|
573
|
+
*/
|
|
574
|
+
profileCompletionRequired: boolean;
|
|
575
|
+
/** The signup field values the social provider gave, e.g. `firstName`. */
|
|
576
|
+
prefilledFieldValues: SignupFieldValues;
|
|
577
|
+
}
|
|
578
|
+
interface PendingApprovalState {
|
|
579
|
+
/**
|
|
580
|
+
* The email waiting for the site owner's approval; '' until a signup or login waits for it or
|
|
581
|
+
* the popup was opened with an email.
|
|
582
|
+
*/
|
|
583
|
+
pendingApprovalEmail: string;
|
|
584
|
+
}
|
|
585
|
+
interface LoginWithIdpOptions {
|
|
586
|
+
privacyStatus?: ProfilePrivacyStatus;
|
|
587
|
+
/** The screen it's called from, whose state reports the call. Default `login`. */
|
|
588
|
+
from?: 'login' | 'signup';
|
|
589
|
+
}
|
|
590
|
+
/** The old flat resend items' state: `timer` while the wait runs. */
|
|
591
|
+
type ResendState = 'regular' | 'timer';
|
|
592
|
+
interface ResendVerificationCodeState extends ActionState {
|
|
593
|
+
/**
|
|
594
|
+
* Seconds until resendVerificationCodeEmail sends again: 30 as a resend starts, counting down
|
|
595
|
+
* every second to 0. A failed resend ends the wait at once.
|
|
596
|
+
*/
|
|
597
|
+
secondsUntilResend: number;
|
|
598
|
+
}
|
|
599
|
+
type UnionToIntersection<U> = (U extends unknown ? (arg: U) => void : never) extends ((arg: infer I) => void) ? I : never;
|
|
600
|
+
type SliceValue<S> = S extends ContextSlice<infer T> ? T : S extends LiveContextSlice<infer T> ? T : never;
|
|
601
|
+
type LoadedContextValue = UnionToIntersection<SliceValue<(typeof contextSlices)[number]>>;
|
|
602
|
+
type LiveContextValue = UnionToIntersection<SliceValue<(typeof liveContextSlices)[number]>>;
|
|
603
|
+
type TextsValue = {
|
|
604
|
+
/**
|
|
605
|
+
* The app's default English copy of its member screens (login, signup, password, Pending
|
|
606
|
+
* Approval, Access Restricted, Expired Token), by text name, to show in text elements and
|
|
607
|
+
* components of your own; the editor offers the Pending Approval, Access Restricted and Expired
|
|
608
|
+
* Token texts. Always English, whatever the site's language. `{email}` in a text is
|
|
609
|
+
* pendingApprovalState.pendingApprovalEmail. The app's own screens carry this copy themselves and
|
|
610
|
+
* don't read it here. Empty outside an Authentication provider.
|
|
611
|
+
* @example
|
|
612
|
+
* ```tsx
|
|
613
|
+
* const { texts } = useContextProvider();
|
|
614
|
+
* return <h2>{texts.accessRestrictedTitle}</h2>; // "Access to this page is restricted"
|
|
615
|
+
* ```
|
|
616
|
+
*/
|
|
617
|
+
texts: Record<TextName, string>;
|
|
618
|
+
};
|
|
619
|
+
/** The site's login settings, the member's state, the screens' texts, and the actions that log in, sign up and navigate between screens. */
|
|
620
|
+
type AuthenticationContextValue = LoadedContextValue & LiveContextValue & TextsValue;
|
|
621
|
+
//#endregion
|
|
622
|
+
//#region src/extensions/context-provider/context-provider.d.ts
|
|
623
|
+
declare const AuthenticationContext: React.Context<AuthenticationContextValue | null>;
|
|
624
|
+
/** Reads the authentication context supplied by a surrounding Authentication provider. */
|
|
625
|
+
declare function useContextProvider(): AuthenticationContextValue;
|
|
626
|
+
/** Like {@link useContextProvider}, but returns `null` outside an Authentication provider. */
|
|
627
|
+
declare function useContextProviderSafe(): AuthenticationContextValue | null;
|
|
628
|
+
/** Props accepted by {@link AuthenticationProvider}. */
|
|
629
|
+
type AuthenticationProviderProps = PropsWithChildren;
|
|
630
|
+
/** Loads the site's login settings and supplies them, with the member's state, the screens' texts and the login, signup and navigation actions, to descendant components. */
|
|
631
|
+
declare const AuthenticationProvider: FC<AuthenticationProviderProps>;
|
|
632
|
+
//#endregion
|
|
633
|
+
export { AuthenticationContext, type AuthenticationContextValue, AuthenticationProviderProps, AuthenticationProvider as default, useContextProvider, useContextProviderSafe };
|