Mojito API Kit
⚙️ How to Install and Setup the Mojito Core-service SDK module.
Overview
The Mojito Core Service SDK provides convenient abstractions for interacting with the core-service APIs in a TypeScript/JavaScript environment. It simplifies integrating the SDK into your application by offering a range of APIs for the secondary marketplace, claim token, and auction functionalities.
This guide will help you better understand how to use and integrate the Core-service SDK into your application.
Note:For more detailed information and examples, you can refer to the NPM Packages here.
Prerequisite
Before proceeding with the installation steps, ensure that you have the following prerequisites in place:
- Node.js and NPM/Yarn: Make sure you have Node.js installed on your machine, along with either NPM (Node Package Manager) or Yarn. You can download and install Node.js from the official website here.
- Authentication Provider: To obtain the necessary token for authentication, you need to have an authentication provider set up. This can be a JWT (JSON Web Token) or an Auth0 token, which will be passed as the "token" property in the configuration.
- API URL: Determine the appropriate API URL to use based on your environment.
Installation and Setup
Step 1: Install the Core-service Module
Install the Mojito Core-service SDK module on your project by using one of the following methods below:
Install using NPM:
npm i @mojito-inc/core-serviceInstall using Yarn:
yarn add @mojito-inc/core-serviceInstall via package.json:
"@mojito-inc/core-service": "1.0.4"
Step 2: Wrap the Provider and Set API URL and Bearer Token
In your project's root file, follow these steps to wrap the provider and configure the API URL and Bearer token:
-
Determine the appropriate API URL based on your environment:
- For the development environment, set
API_URLtohttps://api-dev.mojito.xyz/query. - For the production environment, set
API_URLtohttps://api.mojito.xyz/query.
- For the development environment, set
-
Obtain a JWT token or Auth0 token from your authentication provider.
- This token will be passed as the "token" property in the provider configuration.
-
Wrap the provider using the
CoreServiceProvidercomponent from the Mojito Core Service SDK.- Import the
CoreServiceProviderfrom@mojitoinc/core-servicein your JavaScript file. - Use the
CoreServiceProvidercomponent and provide the following props:uri: Set this prop to the determinedAPI_URLbased on your environment.token: Pass the obtained JWT token or Auth0 token as the value for this prop. Use the formatBearer <Token>.
- Import the
import { CoreServiceProvider } from "@mojitoinc/core-service";
<CoreServiceProvider uri={API_URL } token={ 'Bearer <Token>' }>
{ children }
</CoreServiceProvider>Step 3: Using the useUser Service and the updateUserOrgSettings API
useUser Service and the updateUserOrgSettings APITo update user organization settings, follow these steps:
-
Import the necessary modules and types from the
@mojitoinc/mojito-core-servicepackage:import { useUser, updateUserOrgSettingsData } from "@mojitoinc/mojito-core-service"; -
Invoke the
useUserservice to access theupdateUserOrgSettingsfunction:const { updateUserOrgSettings } = useUser(); -
Fill in the required parameters for the
updateUserOrgSettingsParameter Type Required userOrgId string ✅ username string ✅ avatar string ✅ settingsJson string - profilePic string - -
Call the
updateUserOrgSettingsAPI by providing the required parameters and awaiting its response:const response: Response<updateUserOrgSettingsData> = await updateUserOrgSettings({ userOrgId: <USER_ORG_ID>, username: <USER_NAME>, avatar: <AVATAR>, settingsJson: <SETTING_JSON>, profilePic: <PROFILE_PIC> });
Response
Upon successfully calling the API, you will receive a response object with the following structure:
{
"data": {
"updateUserOrgSettings": {
"id": "d1a59f7e-8626-46f9-b0ca-b70477910c8c",
"username": "test",
"avatar": "U0BpDFXLEKmMNPly"
}
}
}
Note:For complete documentation of the Core-service SDK offerings, see the core-service.
Updated 5 months ago
