Blocklet Service
The BlockletService is a powerful client that acts as the primary interface for your blocklet to interact with the underlying ABT Node services. It simplifies tasks like user management, session handling, role-based access control (RBAC), and retrieving blocklet metadata by wrapping complex GraphQL queries and HTTP requests into a clean, promise-based JavaScript API.
This service is essential for building secure and feature-rich applications that leverage the full power of the Blocklet platform. Before diving into this service, it's helpful to understand the concepts covered in our Authentication guide.
How It Works#
The BlockletService client within your application communicates with the blocklet-service running on the ABT Node. All requests are automatically authenticated using the blocklet's credentials, ensuring secure access to core functionalities.
Getting Started#
To use the service, simply import and instantiate it. The client will automatically configure itself based on the environment variables provided by the Blocklet Server.
Getting Started
import BlockletService from '@blocklet/sdk/service/blocklet';
const client = new BlockletService();
async function main() {
const { user } = await client.getOwner();
console.log('Blocklet owner:', user.fullName);
}
main();Session Management#
login#
Authenticates a user and starts a session.
Parameters
Returns
refreshSession#
Refreshes an expired session using a refresh token.
Parameters
Returns
switchProfile#
Updates a user's profile information.
Parameters
Returns
User Management#
getUser#
Retrieves a single user's profile by their DID.
Parameters
Returns
getUsers#
Retrieves a paginated list of users, with support for filtering and sorting.
Parameters
Returns
getUsersCount#
Gets the total number of users.
Returns
getUsersCountPerRole#
Gets the count of users for each role.
Returns
getOwner#
Retrieves the profile of the blocklet owner.
Returns
updateUserApproval#
Approves or revokes a user's access to the blocklet.
Parameters
Returns
updateUserTags#
Updates the tags associated with a user.
Parameters
Returns
updateUserExtra#
Updates the extra metadata for a user.
Parameters
Returns
updateUserInfo#
Updates a user's general information. Requires a valid user session cookie.
Parameters
Returns
updateUserAddress#
Updates a user's physical address. Requires a valid user session cookie.
Parameters
Returns
User Sessions#
getUserSessions#
Retrieves a list of active sessions for a user.
Parameters
Returns
getUserSessionsCount#
Gets the total count of user sessions, with optional filtering.
Parameters
Returns
Social & Community#
getUserFollowers#
Retrieves a list of users who are following a specific user. Requires a valid user session cookie.
Parameters
Returns
getUserFollowing#
Retrieves a list of users that a specific user is following. Requires a valid user session cookie.
Parameters
Returns
getUserFollowStats#
Gets the number of followers and following for a user. Requires a valid user session cookie.
Parameters
Returns
checkFollowing#
Checks if a user is following one or more other users.
Parameters
Returns
followUser#
Makes one user follow another.
Parameters
Returns
unfollowUser#
Makes one user unfollow another.
Parameters
Returns
getUserInvites#
Retrieves a list of users invited by a specific user. Requires a valid user session cookie.
Parameters
Returns
Tag Management#
getTags#
Retrieves a list of all available user tags.
Parameters
Returns
createTag#
Creates a new user tag.
Parameters
Returns
updateTag#
Updates an existing user tag.
Parameters
Returns
deleteTag#
Deletes a user tag.
Parameters
Returns
Role-Based Access Control (RBAC)#
getRoles#
Retrieves a list of all available roles.
Returns
getRole#
Retrieves a single role by its name.
Parameters
Returns
createRole#
Creates a new role.
Parameters
Returns
updateRole#
Updates an existing role.
Parameters
Returns
deleteRole#
Deletes a role.
Parameters
Returns
getPermissions#
Retrieves a list of all available permissions.
Returns
getPermissionsByRole#
Retrieves all permissions granted to a specific role.
Parameters
Returns
createPermission#
Creates a new permission.
Parameters
Returns
updatePermission#
Updates an existing permission.
Parameters
Returns
deletePermission#
Deletes a permission.
Parameters
Returns
grantPermissionForRole#
Assigns a permission to a role.
Parameters
Returns
revokePermissionFromRole#
Revokes a permission from a role.
Parameters
Returns
updatePermissionsForRole#
Replaces all existing permissions for a role with a new set.
Parameters
Returns
hasPermission#
Checks if a role has a specific permission.
Parameters
Returns
Passport Management#
issuePassportToUser#
Issues a new passport to a user, assigning them a role.
Parameters
Returns
enableUserPassport#
Enables a previously revoked passport for a user.
Parameters
Returns
revokeUserPassport#
Revokes a user's passport.
Parameters
Returns
removeUserPassport#
Permanently removes a user's passport.
Parameters
Returns
Blocklet & Component Info#
getBlocklet#
Retrieves the metadata and state for the current blocklet.
Parameters
Returns
getComponent#
Retrieves the state of a specific component within the current blocklet by its DID.
Parameters
Returns
getTrustedDomains#
Retrieves a list of trusted domains for federated login.
Returns
getVault#
Retrieves and verifies the blocklet's vault information.
Returns
clearCache#
Clears cached data on the node based on a pattern.
Parameters
Returns
Access Key Management#
createAccessKey#
Creates a new access key for programmatic access.
Parameters
Returns
getAccessKey#
Retrieves details for a single access key.
Parameters
Returns
getAccessKeys#
Retrieves a list of access keys.
Parameters
Returns
verifyAccessKey#
Verifies if an access key is valid.
Parameters
Returns
After mastering the BlockletService, you might want to explore how to send messages to your users. Head over to the Notification Service guide to learn more.