Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "spec/user/user"

Index

Modules

Challenges

Challenges:

When a user logs in with their username & password, they may have to respond to a challenge in order to finish the auth loop. This is a collection of data types and helper functions related those ChallengeResponse interactions.

Types

Types:

Our internal key of possible challenges from Cognito. ForgotPassword and Default are constants we made up to control the client-side interface -- the former means we've begun a PassReset flow, the latter means there is no challenge at all. NewPasswordRequired and MFA-related challenges, however, are proper Cognito challenges. You can view the whole list of them at:

https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_InitiateAuth.html#API_InitiateAuth_ResponseSyntax

AppMfa

AppMfa: = "SOFTWARE_TOKEN_MFA"

BeginForgotPassword

BeginForgotPassword: = "BEGIN_FORGOT_PASSWORD"

Default

Default: = "DEFAULT"

ForgotPassword

ForgotPassword: = "FORGOT_PASSWORD"

MfaSetup

MfaSetup: = "MFA_SETUP"

NewPasswordRequired

NewPasswordRequired: = "NEW_PASSWORD_REQUIRED"

SelectMfaType

SelectMfaType: = "SELECT_MFA_TYPE"

SmsMfa

SmsMfa: = "SMS_MFA"

Data

Data:

General response shape for all Challenges. They will always have a ChallengeName, and the Session key is a special value which must be passed back and forth throughout the Challenge-Response flow.

ChallengeName

ChallengeName: Types

ChallengeParameters

ChallengeParameters: object

Type declaration

  • [key: string]: string

Session

Session: string

MfaTypes

MfaTypes: SmsMfa | AppMfa

isData

  • isData(val: any): boolean
  • Type guard; only returns true if maybe fully satisfies Challenges.Data. Validates that the name is a valid value from Challenges.Types, that the session is a string, and that Data.ChallengeParameters has only string keys & string values.

    Parameters

    • val: any

    Returns boolean

isMfaTypes

  • isMfaTypes(val: any): boolean
  • Type guard; only valid values for the MfaTypes type will return true.

    Parameters

    • val: any

    Returns boolean

isTypes

  • isTypes(val: any): boolean
  • Type guard; only valid enum values within the Types enum will return true.

    Parameters

    • val: any

    Returns boolean

newData

  • Factory function to produce an empty ChallengeData object. Session is an empty string, the name is Types.Default, and ChallengeParameters is an empty object.

    Returns Data

CognitoAttributes

CognitoAttributes:

Collection of helper types describing attributes on a Cognito user. UserAttributes technically comes out of Cognito as a ListType, but we transform it on the server into a MapType which fits the UserAttributes spec.

ItemType

ItemType:

Name

Name: NameType

Optional Value

Value: ValueType

MFAOptionType

MFAOptionType:

Optional AttributeName

AttributeName: NameType

Optional DeliveryMedium

DeliveryMedium: DeliveryMediumType

DeliveryMediumType

DeliveryMediumType: "SMS" | "EMAIL" | string

ListType

ListType: ItemType[]

MFAOptionListType

MFAOptionListType: MFAOptionType[]

MapType

MapType: object

Type declaration

NameType

NameType: string

UserMFASettingListType

UserMFASettingListType: string[]

ValueType

ValueType: string

Enumerations

PaymentProvider

PaymentProvider:

All possible custom:payment_providers for a DappBot user. As of Fall 2019, the only options are they're paying with Stripe or they have an admin account.

ADMIN

ADMIN: = "ADMIN"

STRIPE

STRIPE: = "STRIPE"

PaymentStatus

PaymentStatus:

All possible custom:payment_statuses for a DappBot user. If all is well, they're ACTIVE. Once a payment fails, they're LAPSED. If it stays failed, the user eventually goes into FAILED. Their status will only be CANCELLED once they explicitly zero out their subscripton.

ACTIVE

ACTIVE: = "ACTIVE"

CANCELLED

CANCELLED: = "CANCELLED"

FAILED

FAILED: = "FAILED"

LAPSED

LAPSED: = "LAPSED"

Interfaces

AuthData

AuthData:

Object returned after successful login to DappBot. Authorization is the exact token which should go into the Authorization header (no Bearer). RefreshToken is used to get new Authorization after it expires at ExpiresAt, which is a date encoded as an ISO string.

Authorization

Authorization: string

ExpiresAt

ExpiresAt: string

RefreshToken

RefreshToken: string

User

User: UserData

UserAttributes

UserAttributes:

UserAttributes map including all of the custom properties we added to the Cognito user. The limit attributes all control how many dapps the user is allowed to make, payment_provider says whether they are using Stripe, payment_status says whether their payments are all up to date.

custom:enterprise_limit

custom:enterprise_limit: string

custom:payment_provider

custom:payment_provider: PaymentProvider

custom:payment_status

custom:payment_status: PaymentStatus

custom:professional_limit

custom:professional_limit: string

custom:standard_limit

custom:standard_limit: string

UserData

UserData:

DappBot User Record as defined by Cognito. This interface basically follows the default Cognito user, but we have enforced additional constraints on UserAttributes, which is otherwise an arbitrary set of key-val string pairs.

Email

Email: string

Optional MFAOptions

MFAOptions: MFAOptionListType

Optional PreferredMfaSetting

PreferredMfaSetting: undefined | string

UserAttributes

UserAttributes: UserAttributes

Optional UserMFASettingList

UserMFASettingList: UserMFASettingListType

Username

Username: string

Functions

authStatus

  • Given valid AuthData, return an object stating whether the data is active (authorized), stale (needs refresh), or empty (needs full login).

    Parameters

    Returns object

    • isActive: boolean
    • isEmpty: boolean
    • isStale: boolean

isAuthData

  • isAuthData(val: any): boolean
  • Type guard; only returns true if maybe fully satisfies the AuthData interface. Leverages isUserData to check AuthData.User. Checks that ExpiresAt is a valid ISO string, just checks the other two props are strings.

    Parameters

    • val: any

    Returns boolean

isUserAttributes

  • isUserAttributes(val: any): boolean
  • Validates that the enum values within UserAttributes are actually from the appropriate enums, validates that the limit values can be converted to non-negative integers.

    Parameters

    • val: any

    Returns boolean

isUserData

  • isUserData(val: any): boolean
  • Type guard; only returns true if maybe satisfies the UserData interface. Recursively verifies that maybe.UserAttributes verifies the UserAttributes interface.

    Parameters

    • val: any

    Returns boolean

newAuthData

  • Factory which produces an empty AuthData object. Leverages emptyUserData() for User key, ExpiresAt is now as an ISO string, Authorization & RefreshToken are empty strings.

    Returns AuthData

newUserAttributes

  • Factory to produce a blank UserAttributes object. For validity, it is configured as an active admin account with one standard dapp. These factories are convenient for getting blank objects of the correct type, or a list of the interface's keys as a value.

    Returns UserAttributes

newUserData

  • Factory to produce an empty UserData object. All string values are empty except for the UserAttributes, which simulate an admin account that is only allowed to make one standard dapp. These factories are convenient for getting blank objects or a list of the interface's keys as a value.

    Returns UserData

validatePassword

  • validatePassword(newPass: string): boolean
  • Validator function which returns true if the provided string has a length from 8-64 chars, has upper & lowercase characters, no whitespace, and a symbol. Otherwise returns false.

    Parameters

    • newPass: string

    Returns boolean

Generated using TypeDoc