@aws-amplify/ui 3.0.14 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,9 +1,80 @@
1
1
  import * as amazon_cognito_identity_js from 'amazon-cognito-identity-js';
2
2
  import { CognitoUser, CodeDeliveryDetails } from 'amazon-cognito-identity-js';
3
3
  import * as xstate from 'xstate';
4
- import { State, Interpreter, Sender } from 'xstate';
4
+ import { Interpreter, State, Sender } from 'xstate';
5
5
  import { PartialDeep } from 'type-fest';
6
6
 
7
+ /**
8
+ * Map of each input name to its value
9
+ */
10
+ declare type AuthFormData = Record<string, string>;
11
+ /**
12
+ * List of routes that support custom formFields
13
+ */
14
+ declare type formFieldComponents = 'signIn' | 'signUp' | 'forceNewPassword' | 'confirmResetPassword' | 'confirmSignIn' | 'confirmSignUp' | 'confirmVerifyUser' | 'resetPassword' | 'setupTOTP';
15
+ /**
16
+ * Used to customize form field attributes for each authenticator screen.
17
+ */
18
+ declare type FormFields = {
19
+ [key in formFieldComponents]?: formField;
20
+ };
21
+ /**
22
+ * Override option for each screen. Maps each input to override options.
23
+ */
24
+ interface formField {
25
+ [key: string]: formFieldTypes;
26
+ }
27
+ /**
28
+ * Override options for each field
29
+ */
30
+ interface formFieldTypes {
31
+ /** Will hide the label above the input if set to true */
32
+ labelHidden?: boolean;
33
+ /** Label text */
34
+ label?: string;
35
+ /** Placeholder text */
36
+ placeholder?: string;
37
+ /**
38
+ * @deprecated For internal use only, please use `isRequired` instead.
39
+ */
40
+ required?: boolean;
41
+ /** Whether this field is required for submission */
42
+ isRequired?: boolean;
43
+ /** Default dial code value */
44
+ dialCode?: string;
45
+ /** TOTP issuer to be used in the QR setup */
46
+ totpIssuer?: string;
47
+ /** TOTP username to be used in the QR */
48
+ totpUsername?: string;
49
+ /** List of dial codes you want to show in phone number field */
50
+ dialCodeList?: Array<string>;
51
+ /** Integer that denotes where this field should be positioned in. */
52
+ order?: number;
53
+ }
54
+
55
+ /** Enum of known challenge names */
56
+ declare enum AuthChallengeNames {
57
+ SMS_MFA = "SMS_MFA",
58
+ SOFTWARE_TOKEN_MFA = "SOFTWARE_TOKEN_MFA",
59
+ NEW_PASSWORD_REQUIRED = "NEW_PASSWORD_REQUIRED",
60
+ RESET_REQUIRED = "RESET_REQUIRED",
61
+ MFA_SETUP = "MFA_SETUP"
62
+ }
63
+ /** Known cognito user attributes */
64
+ interface CognitoAttributes {
65
+ email: string;
66
+ phone_number: string;
67
+ [key: string]: string;
68
+ }
69
+ /** Cognito User Interface */
70
+ interface CognitoUserAmplify extends CognitoUser {
71
+ username?: string;
72
+ attributes?: CognitoAttributes;
73
+ }
74
+
75
+ /**
76
+ * Maps each input to its validation error, if any
77
+ */
7
78
  declare type ValidationError = Record<string, string>;
8
79
  /**
9
80
  * Return type of validator. This is `null` if there are no error, and `ValidationError` otherwise.
@@ -16,6 +87,36 @@ declare type SignInResult = string;
16
87
  declare type Validator = (formData: AuthFormData, touchData?: AuthFormData) => ValidatorResult | Promise<ValidatorResult>;
17
88
  declare type SignInTypes = (user: string, code: string, mfaType: AuthChallengeNames.SMS_MFA | AuthChallengeNames.SOFTWARE_TOKEN_MFA) => SignInResult | Promise<SignInResult>;
18
89
 
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
+
19
120
  declare const defaultServices: {
20
121
  getAmplifyConfig(): Promise<{}>;
21
122
  getCurrentUser(): Promise<any>;
@@ -44,13 +145,28 @@ declare const defaultServices: {
44
145
  validatePreferredUsername(formData: any, touchData: any): Promise<ValidatorResult>;
45
146
  };
46
147
 
47
- declare type AuthFormData = Record<string, string>;
148
+ /**
149
+ * Data that actor returns when they are done and reach the final state
150
+ */
151
+ interface ActorDoneData {
152
+ /** Any auth form values that needs to be persisted between the actors */
153
+ authAttributes?: AuthFormData;
154
+ /** String that indicates where authMachine should next transition to */
155
+ intent?: string;
156
+ /** User returned by the actor it's done */
157
+ user?: CognitoUserAmplify;
158
+ }
159
+ /**
160
+ * Context interface for the top-level machine
161
+ */
48
162
  interface AuthContext {
163
+ /** Reference to the spawned actor */
49
164
  actorRef?: any;
50
165
  config?: {
51
166
  loginMechanisms?: LoginMechanism[];
52
167
  signUpAttributes?: SignUpAttribute[];
53
168
  socialProviders?: SocialProvider[];
169
+ formFields?: FormFields;
54
170
  initialState?: 'signIn' | 'signUp' | 'resetPassword';
55
171
  };
56
172
  services?: Partial<typeof defaultServices>;
@@ -59,99 +175,106 @@ interface AuthContext {
59
175
  password?: string;
60
176
  code?: string;
61
177
  mfaType?: AuthChallengeNames.SMS_MFA | AuthChallengeNames.SOFTWARE_TOKEN_MFA;
178
+ actorDoneData?: Omit<ActorDoneData, 'user'>;
62
179
  }
63
- interface ServicesContext {
64
- username?: string;
65
- password?: string;
66
- user?: string;
67
- code?: string;
68
- mfaType: AuthChallengeNames.SMS_MFA | AuthChallengeNames.SOFTWARE_TOKEN_MFA;
69
- }
180
+ /**
181
+ * Base context for all actors that have auth forms associated
182
+ */
70
183
  interface BaseFormContext {
184
+ /** Any user attributes set that needs to persist between states */
71
185
  authAttributes?: Record<string, any>;
186
+ /** Current challengeName issued by Cognnito */
72
187
  challengeName?: string;
188
+ /** Required attributes for form submission */
73
189
  requiredAttributes?: Array<string>;
190
+ /** Maps each input name to tis value */
74
191
  formValues?: AuthFormData;
192
+ /** Input (names) that has been blurred at least ones */
75
193
  touched?: AuthFormData;
194
+ /** String that indicates where authMachine should next transition to */
76
195
  intent?: string;
196
+ /** Error returned from remote service / API */
77
197
  remoteError?: string;
198
+ /** Current user inteface the actor is working with */
78
199
  user?: CognitoUserAmplify;
200
+ /** Maps each input to its validation error, if any */
79
201
  validationError?: ValidationError;
202
+ /** Denotes where a confirmation code has been sent to */
80
203
  codeDeliveryDetails?: CodeDeliveryDetails;
204
+ /** Default country code for all phone number fields. */
81
205
  country_code?: string;
82
206
  }
83
207
  interface SignInContext extends BaseFormContext {
84
208
  loginMechanisms: Required<AuthContext>['config']['loginMechanisms'];
85
209
  socialProviders: Required<AuthContext>['config']['socialProviders'];
210
+ formFields?: FormFields;
86
211
  attributeToVerify?: string;
87
212
  redirectIntent?: string;
88
213
  unverifiedAttributes?: Record<string, string>;
89
214
  }
90
- declare const signUpFieldsWithDefault: readonly ["birthdate", "email", "family_name", "given_name", "middle_name", "name", "nickname", "phone_number", "preferred_username", "profile", "website"];
91
- declare const signUpFieldsWithoutDefault: readonly ["address", "gender", "locale", "picture", "updated_at", "zoneinfo"];
92
- declare type SignUpFieldsWithDefaults = typeof signUpFieldsWithDefault[number];
93
- declare type SignUpFieldsWithoutDefaults = typeof signUpFieldsWithoutDefault[number];
94
- declare type SignUpAttribute = SignUpFieldsWithDefaults | SignUpFieldsWithoutDefaults;
95
215
  interface SignUpContext extends BaseFormContext {
96
216
  loginMechanisms: Required<AuthContext>['config']['loginMechanisms'];
97
217
  socialProviders: Required<AuthContext>['config']['socialProviders'];
218
+ formFields: FormFields;
98
219
  unverifiedAttributes?: Record<string, string>;
99
220
  }
100
221
  interface ResetPasswordContext extends BaseFormContext {
101
222
  username?: string;
102
223
  unverifiedAttributes?: Record<string, string>;
224
+ formFields?: FormFields;
103
225
  }
104
226
  interface SignOutContext {
105
227
  authAttributes?: Record<string, any>;
106
228
  challengeName?: string;
107
229
  unverifiedAttributes?: Record<string, string>;
108
230
  user?: CognitoUserAmplify;
231
+ formFields?: FormFields;
109
232
  }
233
+ /**
234
+ * Context for actors that have forms
235
+ */
110
236
  declare type ActorContextWithForms = SignInContext | SignUpContext | ResetPasswordContext;
111
- declare type SignInState = State<SignInContext, AuthEvent>;
112
- declare type SignUpState = State<SignUpContext, AuthEvent>;
113
- declare type SignOutState = State<SignOutContext, AuthEvent>;
114
- declare type ResetPasswordState = State<ResetPasswordContext, AuthEvent>;
115
237
  declare type AuthActorContext = ActorContextWithForms | SignOutContext;
116
- declare type AuthActorState = State<AuthActorContext, AuthEvent>;
117
- interface CognitoUserAmplify extends CognitoUser {
118
- username?: string;
119
- attributes?: CognitoAttributes;
120
- }
121
- interface CognitoAttributes {
122
- email: string;
123
- phone_number: string;
124
- [key: string]: string;
125
- }
238
+
239
+ /**
240
+ * Events that occur when actors are done
241
+ */
126
242
  declare type InvokeActorEventTypes = 'done.invoke.signInActor' | 'done.invoke.signUpActor' | 'done.invoke.signOutActor' | 'done.invoke.resetPasswordActor';
243
+ /**
244
+ * All known explicit events for xstate
245
+ */
127
246
  declare type AuthEventTypes = 'CHANGE' | 'BLUR' | 'FEDERATED_SIGN_IN' | 'RESEND' | 'RESET_PASSWORD' | 'SIGN_IN' | 'SIGN_OUT' | 'SIGN_UP' | 'SKIP' | 'SUBMIT' | 'INIT' | InvokeActorEventTypes;
128
- declare enum AuthChallengeNames {
129
- SMS_MFA = "SMS_MFA",
130
- SOFTWARE_TOKEN_MFA = "SOFTWARE_TOKEN_MFA",
131
- NEW_PASSWORD_REQUIRED = "NEW_PASSWORD_REQUIRED",
132
- RESET_REQUIRED = "RESET_REQUIRED",
133
- MFA_SETUP = "MFA_SETUP"
134
- }
135
- interface InputAttributes {
136
- label: string;
137
- type: string;
138
- placeholder: string;
139
- autocomplete?: string;
140
- }
141
- declare const LoginMechanismArray: readonly ["username", "email", "phone_number"];
142
- declare type LoginMechanism = typeof LoginMechanismArray[number];
143
- declare type SocialProvider = 'amazon' | 'apple' | 'facebook' | 'google';
144
- declare type AuthFieldsWithDefaults = LoginMechanism | SignUpFieldsWithDefaults | 'confirmation_code' | 'password';
145
- declare type AuthInputAttributes = Record<AuthFieldsWithDefaults, InputAttributes>;
247
+ /**
248
+ * Data payload for auth events
249
+ */
146
250
  declare type AuthEventData = Record<PropertyKey, any>;
251
+ /** Top-level auth machine event interface */
147
252
  interface AuthEvent {
148
253
  type: AuthEventTypes;
149
254
  data?: AuthEventData;
150
255
  }
151
- declare type AuthMachineState = State<AuthContext, AuthEvent>;
256
+
257
+ /**
258
+ * This files provides types that describe general shape of
259
+ * authenticator machine and its intepreter.
260
+ */
261
+
262
+ /**
263
+ * Intefrace for `authMachine` machine interpreter
264
+ */
152
265
  declare type AuthInterpreter = Interpreter<AuthContext, any, AuthEvent>;
266
+ /**
267
+ * Function type for `send` in `authMachine`
268
+ */
153
269
  declare type AuthMachineSend = AuthInterpreter['send'];
154
270
 
271
+ declare type SignInState = State<SignInContext, AuthEvent>;
272
+ declare type SignUpState = State<SignUpContext, AuthEvent>;
273
+ declare type SignOutState = State<SignOutContext, AuthEvent>;
274
+ declare type ResetPasswordState = State<ResetPasswordContext, AuthEvent>;
275
+ declare type AuthActorState = State<AuthActorContext, AuthEvent>;
276
+ declare type AuthMachineState = State<AuthContext, AuthEvent>;
277
+
155
278
  declare type NoInfer<T> = [T][T extends any ? 0 : never];
156
279
 
157
280
  declare const authInputAttributes: AuthInputAttributes;
@@ -176,8 +299,8 @@ declare const getAliasInfoFromContext: (context: AuthContext, alias?: LoginMecha
176
299
  * secondaryAliases.
177
300
  */
178
301
  declare const getConfiguredAliases: (context: AuthContext) => {
179
- primaryAlias: "username" | "email" | "phone_number";
180
- secondaryAliases: ("username" | "email" | "phone_number")[];
302
+ primaryAlias: "email" | "phone_number" | "username";
303
+ secondaryAliases: ("email" | "phone_number" | "username")[];
181
304
  };
182
305
  /**
183
306
  * Get the state of current actor. This is useful for checking which screen
@@ -260,6 +383,10 @@ declare const listenToAuthHub: (send: AuthMachineSend) => () => void;
260
383
  declare type ContactMethod = 'Email' | 'Phone Number';
261
384
  declare const censorAllButFirstAndLast: (value: string) => string;
262
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>;
263
390
 
264
391
  declare const countryDialCodes: string[];
265
392
 
@@ -452,9 +579,13 @@ interface OrdinalVariation<DesignTokenType = DesignToken<ColorValue>> {
452
579
  }
453
580
 
454
581
  declare type ScaleKeys = 10 | 20 | 40 | 60 | 80 | 90 | 100;
582
+ declare type OverlayKeys = 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90;
455
583
  declare type ColorScale<DesignTokenType = DesignToken<ColorValue>> = {
456
584
  [key in ScaleKeys]: DesignTokenType;
457
585
  };
586
+ declare type OverlayColors<DesignTokenType = DesignToken<ColorValue>> = {
587
+ [key in OverlayKeys]: DesignTokenType;
588
+ };
458
589
  declare type FontColors<DesignTokenType = DesignToken<ColorValue>> = {
459
590
  inverse: DesignTokenType;
460
591
  interactive: DesignTokenType;
@@ -494,6 +625,7 @@ declare type Colors = {
494
625
  primary: ColorScale;
495
626
  secondary: ColorScale;
496
627
  };
628
+ overlay: OverlayColors;
497
629
  [key: string]: ColorTypes | Record<string, ColorTypes>;
498
630
  };
499
631
  declare type WebColors = {
@@ -515,6 +647,7 @@ declare type WebColors = {
515
647
  primary: ColorScale<WebDesignToken<ColorValue>>;
516
648
  secondary: ColorScale<WebDesignToken<ColorValue>>;
517
649
  };
650
+ overlay: OverlayColors<WebDesignToken<ColorValue>>;
518
651
  [key: string]: WebColorTypes | Record<string, WebColorTypes>;
519
652
  };
520
653
 
@@ -627,7 +760,7 @@ declare type WebShadows = {
627
760
  [Property in keyof Shadows]: WebDesignToken<ShadowValue>;
628
761
  };
629
762
 
630
- declare type Space = {
763
+ declare type SpaceSizes = {
631
764
  xxxs: DesignToken<SpaceValue>;
632
765
  xxs: DesignToken<SpaceValue>;
633
766
  xs: DesignToken<SpaceValue>;
@@ -637,16 +770,11 @@ declare type Space = {
637
770
  xl: DesignToken<SpaceValue>;
638
771
  xxl: DesignToken<SpaceValue>;
639
772
  xxxl: DesignToken<SpaceValue>;
640
- relative: {
641
- xxxs: DesignToken<SpaceValue>;
642
- xxs: DesignToken<SpaceValue>;
643
- xs: DesignToken<SpaceValue>;
644
- small: DesignToken<SpaceValue>;
645
- medium: DesignToken<SpaceValue>;
646
- large: DesignToken<SpaceValue>;
647
- xl: DesignToken<SpaceValue>;
648
- xxl: DesignToken<SpaceValue>;
649
- xxxl: DesignToken<SpaceValue>;
773
+ };
774
+ declare type Space = SpaceSizes & {
775
+ zero: DesignToken<SpaceValue>;
776
+ relative: SpaceSizes & {
777
+ full: DesignToken<SpaceValue>;
650
778
  };
651
779
  };
652
780
  declare type WebSpace = {
@@ -847,4 +975,4 @@ declare function createTheme(theme?: Theme, baseTheme?: BaseTheme): WebTheme;
847
975
 
848
976
  declare const defaultTheme: WebTheme;
849
977
 
850
- export { ActorContextWithForms, AuthActorContext, AuthActorState, AuthChallengeNames, AuthContext, AuthEvent, AuthEventData, AuthEventTypes, AuthFieldsWithDefaults, AuthFormData, AuthInputAttributes, AuthInterpreter, AuthMachineSend, AuthMachineState, AuthenticatorMachineOptions, BaseTheme, BorderWidthValue, CognitoAttributes, CognitoUserAmplify, ColorModeOverride, ColorValue, ContactMethod, DefaultTexts, DesignToken, Dict, FederatedIdentityProviders, FontSizeValue, FontValue, FontWeightValue, InputAttributes, InvokeActorEventTypes, LineHeightValue, LoginMechanism, LoginMechanismArray, MediaQueryOverride, NoInfer, OpacityValue, OutlineOffsetValue, OutlineWidthValue, Override, Phrase, RadiusValue, ResetPasswordContext, ResetPasswordState, SelectorOverride, ServicesContext, 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, getSendEventAliases, getServiceContextFacade, getServiceFacade, hasTranslation, isDesignToken, listenToAuthHub, signUpFieldsWithDefault, signUpFieldsWithoutDefault, translate, translations };
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 };