The base package that provides access to the Dynamic Client, which can be extended with extension packages.

Functions

createClient

createClient(params: ClientProps): BaseClient

Returns an instance of a client object, which provides an interface to read state, trigger actions and listen to events of our SDK.

Types

ClientProps type

The parameters that are acceptable by the createClient method.

ParamTypeDescription
environmentIdstringThe ID of the environment of your dynamic application.
apiBaseUrlstring?Allows you to override the URL to which the SDK will make its API requests.
cssOverridesstring?Allows you to inject CSS into our UI modules (currently out of effect)
appNamestring?How you’d like your app to be named in our copies.
appLogoUrlstring?A URL of the logo of your app.

BaseClient type

The base type of a client.

Since clients can be extended (and thus have their types composed with those of the extensions), this is considered the most basic kind of client: the one that is returned from the createClient method.

Besides the .extend method which is inherited from the Extendable class, it is composed of properties which we call modules.

Note that all client modules implement an event emitter interface that allows you to call on, off and once to create and destroy event listeners.

For every property that is a state, there will always be an event name with the same name plus "Changed", which will be triggered when the property changes value. We will omit these from the docs below as they are implicit.

auth module

Provides access to authentication related properties and methods of the SDK.

PropertyTypeDescription
tokenstring | nullThe JWT of the currently logged in user.
authenticatedUserUserProfile | nullThe UserProfile object of the logged in user.
logout() => Promise<void>Allows you to log the current user out.
signInWithExternalJwt({ externalJwt: string, externalUserId: string }) => Promise<void>Logs the user in with a third-party JWT. This must be enabled in dashboard first.
Event nameTypeDescription
logout() => voidTriggered when the user is logged out.

auth.email submodule

Provides methods to send, re-send and verify OTPs to email.

PropertyTypeDescription
sendOTP(target: string) => Promise<void>Sends an OTP token to the target email.
resendOTP() => Promise<void>Sends another OTP token to the same email as the last call to sendOTP.
verifyOTP(token: string) => Promise<void>Receives an OTP token and logs the user in if it is valid.

auth.sms submodule

Provides methods to send, re-send and verify OTPs to phone numbers.

PropertyTypeDescription
sendOTP(target: PhoneData) => Promise<void>Sends an OTP token to the target PhoneData.
resendOTP() => Promise<void>Sends another OTP token to the same phone number as the last call to sendOTP.
verifyOTP(token: string) => Promise<void>Receives an OTP token and logs the user in if it is valid.

auth.social submodule

Provides a method to connect social accounts.

PropertyTypeDescription
connect(args: { provider: SocialProvider }) => Promise<void>Requests social connection to the provided SocialProvider.

sdk module

Gives insight over the state of the SDK.

PropertyTypeDescription
loadedbooleanWhether the SDK has loaded and is ready to handle requests.

ui module

Provides access to Dynamic’s UI.

PropertyTypeDescription
auth.show() => voidOpens up Dynamic’s authentication flow modal for your user to sign in. Automatically closes when finished.
userProfile.show() => voidOpens up Dynamic’s user profile modal, allowing your user to manage their profile and wallets.

wallets module

Provides access to the user’s wallets.

PropertyTypeDescription
primaryBaseWallet | undefinedThe primary wallet of the user.
userWalletsBaseWallet[]The array of all the user’s wallets.

wallets.embedded submodule

Allows interacting with and creating an embedded wallet for the current user.

PropertyTypeDescription
hasWalletbooleanWhether the logged in user has an embedded wallet.
getWallet() => BaseWallet | nullRetrieves the embedded wallet of the current user, or null if it doesn’t exist.
createWallet() => BaseWallet Creates an embedded wallet for the current user. Throws if one already exists.

Extendable class

An object that can be extended by calling its .extend method with an Extension.

To extend here means to add or replace the existing properties of this object, as well as kicking off any related procedures. Like a structure on which you can attach lego bricks.

Since our client extends this class, you are able to easily pick and choose exactly which features you will need, maximizing the control, simplicity and package size of your project.

PropertyTypeDescription
extend<T>(extension: Extension<T>): T & typeof thisAllows you to extend the properties of the calling object and kick off related procedures.

Extension method

Extension<T>(extendable: Extendable, core: Core): T

A method that can be passed to the .extend method of an Extendable object to extend its properties and trigger related procedures.

We do not currently provide support on how to create your own custom extensions, though it can be achieved.