@aws-amplify/ui 3.2.0 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -4,6 +4,28 @@ import * as xstate from 'xstate';
4
4
  import { Interpreter, State, Sender } from 'xstate';
5
5
  import { PartialDeep } from 'type-fest';
6
6
 
7
+ /** Array of auth fields that we supply defaults with */
8
+ declare const signUpFieldsWithDefault: readonly ["birthdate", "email", "family_name", "given_name", "middle_name", "name", "nickname", "phone_number", "preferred_username", "profile", "website"];
9
+ /** Auth fields that we supply defaults with */
10
+ declare type SignUpFieldsWithDefaults = typeof signUpFieldsWithDefault[number];
11
+ /** Array of auth fields that we do not supply defaults with */
12
+ declare const signUpFieldsWithoutDefault: readonly ["address", "gender", "locale", "picture", "updated_at", "zoneinfo"];
13
+ /** Auth fields that we do not supply defaults with */
14
+ declare type SignUpFieldsWithoutDefaults = typeof signUpFieldsWithoutDefault[number];
15
+ /** All known auth fields */
16
+ declare type SignUpAttribute = SignUpFieldsWithDefaults | SignUpFieldsWithoutDefaults;
17
+ /** Fields that are common in all routes */
18
+ declare type CommonFields = 'username' | 'password' | 'confirm_password';
19
+ /** Array of known login mechanisms */
20
+ declare const LoginMechanismArray: readonly ["username", "email", "phone_number"];
21
+ /** Login mechanisms that can be used to sign in */
22
+ declare type LoginMechanism = typeof LoginMechanismArray[number];
23
+ /** List of social provider Authenticator supports */
24
+ declare type SocialProvider = 'amazon' | 'apple' | 'facebook' | 'google';
25
+ declare const authFieldsWithDefaults: readonly ["username", "email", "phone_number", "birthdate", "email", "family_name", "given_name", "middle_name", "name", "nickname", "phone_number", "preferred_username", "profile", "website", "confirmation_code", "password", "confirm_password"];
26
+ /** Input fields that we provide default fields with */
27
+ declare type AuthFieldsWithDefaults = typeof authFieldsWithDefaults[number];
28
+
7
29
  /**
8
30
  * Map of each input name to its value
9
31
  */
@@ -11,23 +33,23 @@ declare type AuthFormData = Record<string, string>;
11
33
  /**
12
34
  * List of routes that support custom formFields
13
35
  */
14
- declare type formFieldComponents = 'signIn' | 'signUp' | 'forceNewPassword' | 'confirmResetPassword' | 'confirmSignIn' | 'confirmSignUp' | 'confirmVerifyUser' | 'resetPassword' | 'setupTOTP';
36
+ declare type FormFieldComponents = 'signIn' | 'signUp' | 'forceNewPassword' | 'confirmResetPassword' | 'confirmSignIn' | 'confirmSignUp' | 'confirmVerifyUser' | 'resetPassword' | 'setupTOTP';
15
37
  /**
16
38
  * Used to customize form field attributes for each authenticator screen.
17
39
  */
18
- declare type FormFields = {
19
- [key in formFieldComponents]?: formField;
40
+ declare type AuthFormFields = {
41
+ [key in FormFieldComponents]?: FormFields;
20
42
  };
21
43
  /**
22
44
  * Override option for each screen. Maps each input to override options.
23
45
  */
24
- interface formField {
25
- [key: string]: formFieldTypes;
46
+ interface FormFields {
47
+ [field_name: string]: FormFieldOptions;
26
48
  }
27
49
  /**
28
50
  * Override options for each field
29
51
  */
30
- interface formFieldTypes {
52
+ interface FormFieldOptions {
31
53
  /** Will hide the label above the input if set to true */
32
54
  labelHidden?: boolean;
33
55
  /** Label text */
@@ -50,6 +72,19 @@ interface formFieldTypes {
50
72
  dialCodeList?: Array<string>;
51
73
  /** Integer that denotes where this field should be positioned in. */
52
74
  order?: number;
75
+ /** Desired HTML input type */
76
+ type?: string;
77
+ /** Desired autocomplete HTML attribute */
78
+ autocomplete?: string;
79
+ }
80
+ /** Default formField values for each supported auth field */
81
+ declare type DefaultFormFieldOptions = Record<AuthFieldsWithDefaults, FormFieldOptions>;
82
+ /** Ordered list of formFields */
83
+ declare type FormFieldsArray = Array<[string, FormFieldOptions]>;
84
+ declare type PasswordPolicyRules = 'REQUIRES_LOWERCASE' | 'REQUIRES_NUMBERS' | 'REQUIRES_SYMBOLS' | 'REQUIRES_UPPERCASE';
85
+ interface PasswordSettings {
86
+ passwordPolicyMinLength: number;
87
+ passwordPolicyCharacters: Array<PasswordPolicyRules>;
53
88
  }
54
89
 
55
90
  /** Enum of known challenge names */
@@ -60,6 +95,15 @@ declare enum AuthChallengeNames {
60
95
  RESET_REQUIRED = "RESET_REQUIRED",
61
96
  MFA_SETUP = "MFA_SETUP"
62
97
  }
98
+ /** Contact destinations that we can send user confirmation code to */
99
+ declare type ContactMethod = 'Email' | 'Phone Number';
100
+ /** Federated IDPs that Authenticator supports */
101
+ declare enum FederatedIdentityProviders {
102
+ Apple = "SignInWithApple",
103
+ Amazon = "LoginWithAmazon",
104
+ Facebook = "Facebook",
105
+ Google = "Google"
106
+ }
63
107
  /** Known cognito user attributes */
64
108
  interface CognitoAttributes {
65
109
  email: string;
@@ -75,7 +119,7 @@ interface CognitoUserAmplify extends CognitoUser {
75
119
  /**
76
120
  * Maps each input to its validation error, if any
77
121
  */
78
- declare type ValidationError = Record<string, string>;
122
+ declare type ValidationError = Record<string, string | string[]>;
79
123
  /**
80
124
  * Return type of validator. This is `null` if there are no error, and `ValidationError` otherwise.
81
125
  */
@@ -84,39 +128,9 @@ declare type SignInResult = string;
84
128
  /**
85
129
  * Validates the given formData. This can be synchronous or asynchronous.
86
130
  */
87
- declare type Validator = (formData: AuthFormData, touchData?: AuthFormData) => ValidatorResult | Promise<ValidatorResult>;
131
+ declare type Validator = (formData: AuthFormData, touchData?: AuthFormData, passwordSettings?: PasswordSettings) => ValidatorResult | Promise<ValidatorResult>;
88
132
  declare type SignInTypes = (user: string, code: string, mfaType: AuthChallengeNames.SMS_MFA | AuthChallengeNames.SOFTWARE_TOKEN_MFA) => SignInResult | Promise<SignInResult>;
89
133
 
90
- /** Array of auth fields that we supply defaults with */
91
- declare const signUpFieldsWithDefault: readonly ["birthdate", "email", "family_name", "given_name", "middle_name", "name", "nickname", "phone_number", "preferred_username", "profile", "website"];
92
- /** Auth fields that we supply defaults with */
93
- declare type SignUpFieldsWithDefaults = typeof signUpFieldsWithDefault[number];
94
- /** Array of auth fields that we do not supply defaults with */
95
- declare const signUpFieldsWithoutDefault: readonly ["address", "gender", "locale", "picture", "updated_at", "zoneinfo"];
96
- /** Auth fields that we do not supply defaults with */
97
- declare type SignUpFieldsWithoutDefaults = typeof signUpFieldsWithoutDefault[number];
98
- /** All known auth fields */
99
- declare type SignUpAttribute = SignUpFieldsWithDefaults | SignUpFieldsWithoutDefaults;
100
- /** Fields that are common in all routes */
101
- declare type CommonFields = 'username' | 'password' | 'confirm_password';
102
- /** Array of known login mechanisms */
103
- declare const LoginMechanismArray: readonly ["username", "email", "phone_number"];
104
- /** Login mechanisms that can be used to sign in */
105
- declare type LoginMechanism = typeof LoginMechanismArray[number];
106
- /** List of social provider Authenticator supports */
107
- declare type SocialProvider = 'amazon' | 'apple' | 'facebook' | 'google';
108
- /** Input fields that we provide default fields with */
109
- declare type AuthFieldsWithDefaults = LoginMechanism | SignUpFieldsWithDefaults | 'confirmation_code' | 'password';
110
- /** Maps default attributes values for an input */
111
- interface InputAttributeDefaults {
112
- label: string;
113
- type: string;
114
- placeholder: string;
115
- autocomplete?: string;
116
- }
117
- /** Maps default attribute values for each Auth Field */
118
- declare type AuthInputAttributes = Record<AuthFieldsWithDefaults, InputAttributeDefaults>;
119
-
120
134
  declare const defaultServices: {
121
135
  getAmplifyConfig(): Promise<{}>;
122
136
  getCurrentUser(): Promise<any>;
@@ -141,7 +155,8 @@ declare const defaultServices: {
141
155
  }): Promise<SignInResult>;
142
156
  handleForgotPassword(formData: any): Promise<any>;
143
157
  validateCustomSignUp(formData: any, touchData: any): Promise<ValidatorResult>;
144
- validateConfirmPassword<Validator>(formData: any, touchData: any): Promise<ValidatorResult>;
158
+ validateFormPassword<Validator>(formData: any, touchData: any, passwordSettings: PasswordSettings): Promise<ValidatorResult>;
159
+ validateConfirmPassword<Validator_1>(formData: any, touchData: any): Promise<ValidatorResult>;
145
160
  validatePreferredUsername(formData: any, touchData: any): Promise<ValidatorResult>;
146
161
  };
147
162
 
@@ -166,8 +181,9 @@ interface AuthContext {
166
181
  loginMechanisms?: LoginMechanism[];
167
182
  signUpAttributes?: SignUpAttribute[];
168
183
  socialProviders?: SocialProvider[];
169
- formFields?: FormFields;
184
+ formFields?: AuthFormFields;
170
185
  initialState?: 'signIn' | 'signUp' | 'resetPassword';
186
+ passwordSettings?: PasswordSettings;
171
187
  };
172
188
  services?: Partial<typeof defaultServices>;
173
189
  user?: CognitoUserAmplify;
@@ -199,6 +215,8 @@ interface BaseFormContext {
199
215
  user?: CognitoUserAmplify;
200
216
  /** Maps each input to its validation error, if any */
201
217
  validationError?: ValidationError;
218
+ /** Maps each password validation rule */
219
+ passwordSettings?: PasswordSettings;
202
220
  /** Denotes where a confirmation code has been sent to */
203
221
  codeDeliveryDetails?: CodeDeliveryDetails;
204
222
  /** Default country code for all phone number fields. */
@@ -207,7 +225,7 @@ interface BaseFormContext {
207
225
  interface SignInContext extends BaseFormContext {
208
226
  loginMechanisms: Required<AuthContext>['config']['loginMechanisms'];
209
227
  socialProviders: Required<AuthContext>['config']['socialProviders'];
210
- formFields?: FormFields;
228
+ formFields?: AuthFormFields;
211
229
  attributeToVerify?: string;
212
230
  redirectIntent?: string;
213
231
  unverifiedAttributes?: Record<string, string>;
@@ -215,20 +233,20 @@ interface SignInContext extends BaseFormContext {
215
233
  interface SignUpContext extends BaseFormContext {
216
234
  loginMechanisms: Required<AuthContext>['config']['loginMechanisms'];
217
235
  socialProviders: Required<AuthContext>['config']['socialProviders'];
218
- formFields: FormFields;
236
+ formFields: AuthFormFields;
219
237
  unverifiedAttributes?: Record<string, string>;
220
238
  }
221
239
  interface ResetPasswordContext extends BaseFormContext {
222
240
  username?: string;
223
241
  unverifiedAttributes?: Record<string, string>;
224
- formFields?: FormFields;
242
+ formFields?: AuthFormFields;
225
243
  }
226
244
  interface SignOutContext {
227
245
  authAttributes?: Record<string, any>;
228
246
  challengeName?: string;
229
247
  unverifiedAttributes?: Record<string, string>;
230
248
  user?: CognitoUserAmplify;
231
- formFields?: FormFields;
249
+ formFields?: AuthFormFields;
232
250
  }
233
251
  /**
234
252
  * Context for actors that have forms
@@ -277,31 +295,11 @@ declare type AuthMachineState = State<AuthContext, AuthEvent>;
277
295
 
278
296
  declare type NoInfer<T> = [T][T extends any ? 0 : never];
279
297
 
280
- declare const authInputAttributes: AuthInputAttributes;
281
- declare enum FederatedIdentityProviders {
282
- Apple = "SignInWithApple",
283
- Amazon = "LoginWithAmazon",
284
- Facebook = "Facebook",
285
- Google = "Google"
286
- }
287
298
  /**
288
- * Given xstate context from AuthMachine, this returns the input label, type,
289
- * and error attributes of the configured login_mechanisms. An optional "alias"
290
- * may be passed in to get info from context for that specific alias.
299
+ * This file contains helpers that lets you easily access current actor's state
300
+ * and context.
291
301
  */
292
- declare const getAliasInfoFromContext: (context: AuthContext, alias?: LoginMechanism) => {
293
- label: string;
294
- type: string;
295
- error: any;
296
- };
297
- /**
298
- * Given xstate context from AuthMachine, returns the primaryAlias and
299
- * secondaryAliases.
300
- */
301
- declare const getConfiguredAliases: (context: AuthContext) => {
302
- primaryAlias: "email" | "phone_number" | "username";
303
- secondaryAliases: ("email" | "phone_number" | "username")[];
304
- };
302
+
305
303
  /**
306
304
  * Get the state of current actor. This is useful for checking which screen
307
305
  * to render: e.g. `getActorState(state).matches('confirmSignUp.edit').
@@ -312,6 +310,17 @@ declare const getActorState: (state: AuthMachineState) => AuthActorState;
312
310
  * like remoteError.
313
311
  */
314
312
  declare const getActorContext: (state: AuthMachineState) => AuthActorContext;
313
+
314
+ declare const getPrimaryAlias: (state: AuthMachineState) => "email" | "phone_number" | "username";
315
+ /**
316
+ * Given xstate context from AuthMachine, returns the primaryAlias and
317
+ * secondaryAliases.
318
+ */
319
+ declare const getConfiguredAliases: (context: AuthContext) => {
320
+ primaryAlias: "email" | "phone_number" | "username";
321
+ secondaryAliases: ("email" | "phone_number" | "username")[];
322
+ };
323
+
315
324
  /**
316
325
  * Creates public facing auth helpers that abstracts out xstate implementation
317
326
  * detail. Each framework implementation can export these helpers so that
@@ -342,7 +351,7 @@ declare const getServiceContextFacade: (state: AuthMachineState) => {
342
351
  route: string;
343
352
  user: CognitoUserAmplify;
344
353
  validationErrors: {
345
- [x: string]: string;
354
+ [x: string]: string | string[];
346
355
  };
347
356
  codeDeliveryDetails: amazon_cognito_identity_js.CodeDeliveryDetails;
348
357
  };
@@ -356,7 +365,7 @@ declare const getServiceFacade: ({ send, state }: {
356
365
  route: string;
357
366
  user: CognitoUserAmplify;
358
367
  validationErrors: {
359
- [x: string]: string;
368
+ [x: string]: string | string[];
360
369
  };
361
370
  codeDeliveryDetails: amazon_cognito_identity_js.CodeDeliveryDetails;
362
371
  resendCode: (data?: AuthEventData) => void;
@@ -370,6 +379,27 @@ declare const getServiceFacade: ({ send, state }: {
370
379
  toSignUp: (data?: AuthEventData) => void;
371
380
  skipVerification: (data?: AuthEventData) => void;
372
381
  };
382
+
383
+ /**
384
+ * This file contains helpers related to forms and input attributes.
385
+ */
386
+
387
+ declare const defaultFormFieldOptions: DefaultFormFieldOptions;
388
+
389
+ declare const getFormDataFromEvent: (event: Event) => {
390
+ [k: string]: FormDataEntryValue;
391
+ };
392
+ declare const setFormOrder: (formOverrides: FormFields, fieldNames: Array<SignUpAttribute | CommonFields>) => Array<string | number>;
393
+ declare const isAuthFieldWithDefaults: (field: string) => field is "birthdate" | "email" | "family_name" | "given_name" | "middle_name" | "name" | "nickname" | "phone_number" | "preferred_username" | "profile" | "website" | "username" | "password" | "confirm_password" | "confirmation_code";
394
+ declare const getErrors: (errors: string | string[]) => string[];
395
+
396
+ /**
397
+ * This file contains general helpers that state machine or authenticator
398
+ * implementations can use.
399
+ */
400
+
401
+ declare const censorAllButFirstAndLast: (value: string) => string;
402
+ declare const censorPhoneNumber: (val: string) => string;
373
403
  /**
374
404
  * Listens to external auth Hub events and sends corresponding event to
375
405
  * the `authService` of interest
@@ -380,13 +410,27 @@ declare const getServiceFacade: ({ send, state }: {
380
410
  */
381
411
  declare const listenToAuthHub: (send: AuthMachineSend) => () => void;
382
412
 
383
- declare type ContactMethod = 'Email' | 'Phone Number';
384
- declare const censorAllButFirstAndLast: (value: string) => string;
385
- declare const censorPhoneNumber: (val: string) => string;
386
- declare const getFormDataFromEvent: (event: Event) => {
387
- [k: string]: FormDataEntryValue;
388
- };
389
- declare const setFormOrder: (formOverrides: formField, fieldNames: Array<SignUpAttribute | CommonFields>) => Array<string | number>;
413
+ /**
414
+ * This file contains helpers that generate default form fields, given the
415
+ * current Authenticator / Zero Config configuration.
416
+ */
417
+
418
+ /** Gets the default formFields for given route/route */
419
+ declare const getDefaultFormFields: (route: FormFieldComponents, state: AuthMachineState) => FormFields;
420
+ /** Gets default formFields, then merges custom formFields into it */
421
+ declare const getFormFields: (route: FormFieldComponents, state: AuthMachineState) => FormFields;
422
+ /** Calls `getFormFields` above, then sorts it into an indexed array */
423
+ declare const getSortedFormFields: (route: FormFieldComponents, state: AuthMachineState) => FormFieldsArray;
424
+
425
+ /** Collect all the defaultFormFields getters */
426
+ declare const defaultFormFieldsGetters: Record<FormFieldComponents, (state: AuthMachineState) => FormFields>;
427
+
428
+ /** Applies translations to label and placeholder */
429
+ declare const applyTranslation: (formFields: FormFields) => FormFields;
430
+ /** Sorts formFields according to their `order`. */
431
+ declare const sortFormFields: (formFields: FormFields) => FormFieldsArray;
432
+ /** Applies defaultFormFields value into customFormFields */
433
+ declare const applyDefaults: (defaultFormFields: FormFields, customFormFields?: FormFields) => FormFields;
390
434
 
391
435
  declare const countryDialCodes: string[];
392
436
 
@@ -975,4 +1019,4 @@ declare function createTheme(theme?: Theme, baseTheme?: BaseTheme): WebTheme;
975
1019
 
976
1020
  declare const defaultTheme: WebTheme;
977
1021
 
978
- export { ActorContextWithForms, ActorDoneData, AuthActorContext, AuthActorState, AuthChallengeNames, AuthContext, AuthEvent, AuthEventData, AuthEventTypes, AuthFieldsWithDefaults, AuthFormData, AuthInputAttributes, AuthInterpreter, AuthMachineSend, AuthMachineState, AuthenticatorMachineOptions, BaseTheme, BorderWidthValue, CognitoAttributes, CognitoUserAmplify, ColorModeOverride, ColorValue, CommonFields, ContactMethod, DefaultTexts, DesignToken, Dict, FederatedIdentityProviders, FontSizeValue, FontValue, FontWeightValue, FormFields, InputAttributeDefaults, InvokeActorEventTypes, LineHeightValue, LoginMechanism, LoginMechanismArray, MediaQueryOverride, NoInfer, OpacityValue, OutlineOffsetValue, OutlineWidthValue, Override, Phrase, RadiusValue, ResetPasswordContext, ResetPasswordState, SelectorOverride, ShadowValue, SignInContext, SignInResult, SignInState, SignInTypes, SignOutContext, SignOutState, SignUpAttribute, SignUpContext, SignUpFieldsWithDefaults, SignUpFieldsWithoutDefaults, SignUpState, SocialProvider, SpaceValue, Theme, TimeValue, TransformValue, ValidationError, Validator, ValidatorResult, WebDesignToken, WebTheme, authInputAttributes, censorAllButFirstAndLast, censorPhoneNumber, countryDialCodes, createAuthenticatorMachine, createTheme, defaultTheme, formField, formFieldComponents, formFieldTypes, getActorContext, getActorState, getAliasInfoFromContext, getConfiguredAliases, getFormDataFromEvent, getSendEventAliases, getServiceContextFacade, getServiceFacade, hasTranslation, isDesignToken, listenToAuthHub, setFormOrder, signUpFieldsWithDefault, signUpFieldsWithoutDefault, translate, translations };
1022
+ export { ActorContextWithForms, ActorDoneData, AuthActorContext, AuthActorState, AuthChallengeNames, AuthContext, AuthEvent, AuthEventData, AuthEventTypes, AuthFieldsWithDefaults, AuthFormData, AuthFormFields, AuthInterpreter, AuthMachineSend, AuthMachineState, AuthenticatorMachineOptions, BaseTheme, BorderWidthValue, CognitoAttributes, CognitoUserAmplify, ColorModeOverride, ColorValue, CommonFields, ContactMethod, DefaultFormFieldOptions, DefaultTexts, DesignToken, Dict, FederatedIdentityProviders, FontSizeValue, FontValue, FontWeightValue, FormFieldComponents, FormFieldOptions, FormFields, FormFieldsArray, InvokeActorEventTypes, LineHeightValue, LoginMechanism, LoginMechanismArray, MediaQueryOverride, NoInfer, OpacityValue, OutlineOffsetValue, OutlineWidthValue, Override, PasswordPolicyRules, PasswordSettings, Phrase, RadiusValue, ResetPasswordContext, ResetPasswordState, SelectorOverride, ShadowValue, SignInContext, SignInResult, SignInState, SignInTypes, SignOutContext, SignOutState, SignUpAttribute, SignUpContext, SignUpFieldsWithDefaults, SignUpFieldsWithoutDefaults, SignUpState, SocialProvider, SpaceValue, Theme, TimeValue, TransformValue, ValidationError, Validator, ValidatorResult, WebDesignToken, WebTheme, applyDefaults, applyTranslation, authFieldsWithDefaults, censorAllButFirstAndLast, censorPhoneNumber, countryDialCodes, createAuthenticatorMachine, createTheme, defaultFormFieldOptions, defaultFormFieldsGetters, defaultTheme, getActorContext, getActorState, getConfiguredAliases, getDefaultFormFields, getErrors, getFormDataFromEvent, getFormFields, getPrimaryAlias, getSendEventAliases, getServiceContextFacade, getServiceFacade, getSortedFormFields, hasTranslation, isAuthFieldWithDefaults, isDesignToken, listenToAuthHub, setFormOrder, signUpFieldsWithDefault, signUpFieldsWithoutDefault, sortFormFields, translate, translations };