@aws-amplify/ui 3.2.1 → 3.3.2

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
  */
@@ -15,14 +37,14 @@ declare type FormFieldComponents = 'signIn' | 'signUp' | 'forceNewPassword' | 'c
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]: FormFieldOptions;
46
+ interface FormFields {
47
+ [field_name: string]: FormFieldOptions;
26
48
  }
27
49
  /**
28
50
  * Override options for each field
@@ -50,6 +72,19 @@ interface FormFieldOptions {
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 */
@@ -84,7 +119,7 @@ interface CognitoUserAmplify extends CognitoUser {
84
119
  /**
85
120
  * Maps each input to its validation error, if any
86
121
  */
87
- declare type ValidationError = Record<string, string>;
122
+ declare type ValidationError = Record<string, string | string[]>;
88
123
  /**
89
124
  * Return type of validator. This is `null` if there are no error, and `ValidationError` otherwise.
90
125
  */
@@ -93,39 +128,9 @@ declare type SignInResult = string;
93
128
  /**
94
129
  * Validates the given formData. This can be synchronous or asynchronous.
95
130
  */
96
- declare type Validator = (formData: AuthFormData, touchData?: AuthFormData) => ValidatorResult | Promise<ValidatorResult>;
131
+ declare type Validator = (formData: AuthFormData, touchData?: AuthFormData, passwordSettings?: PasswordSettings) => ValidatorResult | Promise<ValidatorResult>;
97
132
  declare type SignInTypes = (user: string, code: string, mfaType: AuthChallengeNames.SMS_MFA | AuthChallengeNames.SOFTWARE_TOKEN_MFA) => SignInResult | Promise<SignInResult>;
98
133
 
99
- /** Array of auth fields that we supply defaults with */
100
- declare const signUpFieldsWithDefault: readonly ["birthdate", "email", "family_name", "given_name", "middle_name", "name", "nickname", "phone_number", "preferred_username", "profile", "website"];
101
- /** Auth fields that we supply defaults with */
102
- declare type SignUpFieldsWithDefaults = typeof signUpFieldsWithDefault[number];
103
- /** Array of auth fields that we do not supply defaults with */
104
- declare const signUpFieldsWithoutDefault: readonly ["address", "gender", "locale", "picture", "updated_at", "zoneinfo"];
105
- /** Auth fields that we do not supply defaults with */
106
- declare type SignUpFieldsWithoutDefaults = typeof signUpFieldsWithoutDefault[number];
107
- /** All known auth fields */
108
- declare type SignUpAttribute = SignUpFieldsWithDefaults | SignUpFieldsWithoutDefaults;
109
- /** Fields that are common in all routes */
110
- declare type CommonFields = 'username' | 'password' | 'confirm_password';
111
- /** Array of known login mechanisms */
112
- declare const LoginMechanismArray: readonly ["username", "email", "phone_number"];
113
- /** Login mechanisms that can be used to sign in */
114
- declare type LoginMechanism = typeof LoginMechanismArray[number];
115
- /** List of social provider Authenticator supports */
116
- declare type SocialProvider = 'amazon' | 'apple' | 'facebook' | 'google';
117
- /** Input fields that we provide default fields with */
118
- declare type AuthFieldsWithDefaults = LoginMechanism | SignUpFieldsWithDefaults | 'confirmation_code' | 'password';
119
- /** Maps default attributes values for an input */
120
- interface InputAttributeDefaults {
121
- label: string;
122
- type: string;
123
- placeholder: string;
124
- autocomplete?: string;
125
- }
126
- /** Maps default attribute values for each Auth Field */
127
- declare type AuthInputAttributes = Record<AuthFieldsWithDefaults, InputAttributeDefaults>;
128
-
129
134
  declare const defaultServices: {
130
135
  getAmplifyConfig(): Promise<{}>;
131
136
  getCurrentUser(): Promise<any>;
@@ -150,7 +155,8 @@ declare const defaultServices: {
150
155
  }): Promise<SignInResult>;
151
156
  handleForgotPassword(formData: any): Promise<any>;
152
157
  validateCustomSignUp(formData: any, touchData: any): Promise<ValidatorResult>;
153
- 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>;
154
160
  validatePreferredUsername(formData: any, touchData: any): Promise<ValidatorResult>;
155
161
  };
156
162
 
@@ -175,8 +181,9 @@ interface AuthContext {
175
181
  loginMechanisms?: LoginMechanism[];
176
182
  signUpAttributes?: SignUpAttribute[];
177
183
  socialProviders?: SocialProvider[];
178
- formFields?: FormFields;
184
+ formFields?: AuthFormFields;
179
185
  initialState?: 'signIn' | 'signUp' | 'resetPassword';
186
+ passwordSettings?: PasswordSettings;
180
187
  };
181
188
  services?: Partial<typeof defaultServices>;
182
189
  user?: CognitoUserAmplify;
@@ -208,6 +215,8 @@ interface BaseFormContext {
208
215
  user?: CognitoUserAmplify;
209
216
  /** Maps each input to its validation error, if any */
210
217
  validationError?: ValidationError;
218
+ /** Maps each password validation rule */
219
+ passwordSettings?: PasswordSettings;
211
220
  /** Denotes where a confirmation code has been sent to */
212
221
  codeDeliveryDetails?: CodeDeliveryDetails;
213
222
  /** Default country code for all phone number fields. */
@@ -216,7 +225,7 @@ interface BaseFormContext {
216
225
  interface SignInContext extends BaseFormContext {
217
226
  loginMechanisms: Required<AuthContext>['config']['loginMechanisms'];
218
227
  socialProviders: Required<AuthContext>['config']['socialProviders'];
219
- formFields?: FormFields;
228
+ formFields?: AuthFormFields;
220
229
  attributeToVerify?: string;
221
230
  redirectIntent?: string;
222
231
  unverifiedAttributes?: Record<string, string>;
@@ -224,20 +233,20 @@ interface SignInContext extends BaseFormContext {
224
233
  interface SignUpContext extends BaseFormContext {
225
234
  loginMechanisms: Required<AuthContext>['config']['loginMechanisms'];
226
235
  socialProviders: Required<AuthContext>['config']['socialProviders'];
227
- formFields: FormFields;
236
+ formFields: AuthFormFields;
228
237
  unverifiedAttributes?: Record<string, string>;
229
238
  }
230
239
  interface ResetPasswordContext extends BaseFormContext {
231
240
  username?: string;
232
241
  unverifiedAttributes?: Record<string, string>;
233
- formFields?: FormFields;
242
+ formFields?: AuthFormFields;
234
243
  }
235
244
  interface SignOutContext {
236
245
  authAttributes?: Record<string, any>;
237
246
  challengeName?: string;
238
247
  unverifiedAttributes?: Record<string, string>;
239
248
  user?: CognitoUserAmplify;
240
- formFields?: FormFields;
249
+ formFields?: AuthFormFields;
241
250
  }
242
251
  /**
243
252
  * Context for actors that have forms
@@ -302,16 +311,7 @@ declare const getActorState: (state: AuthMachineState) => AuthActorState;
302
311
  */
303
312
  declare const getActorContext: (state: AuthMachineState) => AuthActorContext;
304
313
 
305
- /**
306
- * Given xstate context from AuthMachine, this returns the input label, type,
307
- * and error attributes of the configured login_mechanisms. An optional "alias"
308
- * may be passed in to get info from context for that specific alias.
309
- */
310
- declare const getAliasInfoFromContext: (context: AuthContext, alias?: LoginMechanism) => {
311
- label: string;
312
- type: string;
313
- error: any;
314
- };
314
+ declare const getPrimaryAlias: (state: AuthMachineState) => "email" | "phone_number" | "username";
315
315
  /**
316
316
  * Given xstate context from AuthMachine, returns the primaryAlias and
317
317
  * secondaryAliases.
@@ -351,7 +351,7 @@ declare const getServiceContextFacade: (state: AuthMachineState) => {
351
351
  route: string;
352
352
  user: CognitoUserAmplify;
353
353
  validationErrors: {
354
- [x: string]: string;
354
+ [x: string]: string | string[];
355
355
  };
356
356
  codeDeliveryDetails: amazon_cognito_identity_js.CodeDeliveryDetails;
357
357
  };
@@ -365,7 +365,7 @@ declare const getServiceFacade: ({ send, state }: {
365
365
  route: string;
366
366
  user: CognitoUserAmplify;
367
367
  validationErrors: {
368
- [x: string]: string;
368
+ [x: string]: string | string[];
369
369
  };
370
370
  codeDeliveryDetails: amazon_cognito_identity_js.CodeDeliveryDetails;
371
371
  resendCode: (data?: AuthEventData) => void;
@@ -384,11 +384,14 @@ declare const getServiceFacade: ({ send, state }: {
384
384
  * This file contains helpers related to forms and input attributes.
385
385
  */
386
386
 
387
- declare const authInputAttributes: AuthInputAttributes;
387
+ declare const defaultFormFieldOptions: DefaultFormFieldOptions;
388
+
388
389
  declare const getFormDataFromEvent: (event: Event) => {
389
390
  [k: string]: FormDataEntryValue;
390
391
  };
391
- declare const setFormOrder: (formOverrides: FormField, fieldNames: Array<SignUpAttribute | CommonFields>) => Array<string | number>;
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[];
392
395
 
393
396
  /**
394
397
  * This file contains general helpers that state machine or authenticator
@@ -407,6 +410,28 @@ declare const censorPhoneNumber: (val: string) => string;
407
410
  */
408
411
  declare const listenToAuthHub: (send: AuthMachineSend) => () => void;
409
412
 
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;
434
+
410
435
  declare const countryDialCodes: string[];
411
436
 
412
437
  /**
@@ -508,7 +533,29 @@ declare type AuthenticatorMachineOptions = AuthContext['config'] & {
508
533
  declare function createAuthenticatorMachine(): xstate.StateMachine<AuthContext, any, AuthEvent, {
509
534
  value: any;
510
535
  context: AuthContext;
511
- }, xstate.ActionObject<AuthContext, AuthEvent>>;
536
+ }, xstate.BaseActionObject, Record<string, {
537
+ data: any;
538
+ }>, xstate.TypegenDisabled & {
539
+ missingImplementations: {
540
+ actions: never;
541
+ delays: never;
542
+ guards: never;
543
+ services: never;
544
+ };
545
+ } & {
546
+ eventsCausingActions: Record<string, string>;
547
+ eventsCausingDelays: Record<string, string>;
548
+ eventsCausingGuards: Record<string, string>;
549
+ eventsCausingServices: Record<string, string>;
550
+ } & {
551
+ indexedActions: xstate.IndexByType<xstate.BaseActionObject>;
552
+ indexedEvents: Record<string, AuthEvent> & {
553
+ __XSTATE_ALLOW_ANY_INVOKE_DATA_HACK__: {
554
+ data: any;
555
+ };
556
+ };
557
+ invokeSrcNameMap: Record<string, "__XSTATE_ALLOW_ANY_INVOKE_DATA_HACK__">;
558
+ }>;
512
559
 
513
560
  /**
514
561
  * Helper function to test if something is a design token or not.
@@ -994,4 +1041,4 @@ declare function createTheme(theme?: Theme, baseTheme?: BaseTheme): WebTheme;
994
1041
 
995
1042
  declare const defaultTheme: WebTheme;
996
1043
 
997
- 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, FormField, FormFieldComponents, FormFieldOptions, 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, getActorContext, getActorState, getAliasInfoFromContext, getConfiguredAliases, getFormDataFromEvent, getSendEventAliases, getServiceContextFacade, getServiceFacade, hasTranslation, isDesignToken, listenToAuthHub, setFormOrder, signUpFieldsWithDefault, signUpFieldsWithoutDefault, translate, translations };
1044
+ 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 };