Used to check for browser translation.
用于检测浏览器翻译。
ブラウザの翻訳を検出する

Blocklet SDK (Browser)

zhanghan
2024-09-07 03:22
· edited

The Blocklet JS SDK is the official frontend library provided to assist in the development of blocklets.

It mainly includes the following functions:

  1. Provide fetch and axios creation functions that can automatically update tokens.
  2. Provide user profile related interface requests

Initialize the instance#

import { BlockletSDK } from '@blocklet/js-sdk';
const sdk = new BlockletSDK();

User Information Example#

user.getUserPublicInfo

Get user's public information.

type UserPublicInfo = {
avatar: string;
did: string;
fullName: string;
};
const publicInfo: UserPublicInfo = await sdk.user.getUserPublicInfo(userDid: string);

user.getProfileUrl

Get user personal center address

const profileUrl = await sdk.user.getProfileUrl({did: string; locale: string});

user.logout

Log out

await sdk.user.logout();


Create an axios instance#

createAxios

This example will manage the update of sessionToken and refreshToken.

import { createAxios } from '@blocklet/js-sdk';
import type { AxiosRequestConfig, AxiosInstance } from 'axios';


type RequestParams = {
  lazy?: boolean; // 是否需要将请求延迟响应
  lazyTime?: number; // 延迟响应的时间,默认 300 ms
};

const api = createAxios(config?: AxiosRequestConfig, requestParams?:RequestParams)

createFetch

This instance will manage the updating of sessionToken and refreshToken.

import { createFetch } from '@blocklet/js-sdk';

type RequestParams = {
  lazy?: boolean; // 是否需要将请求延迟响应
  lazyTime?: number; // 延迟响应的时间,默认 300 ms
};

const api = createFetch(options?: RequestInit, requestParams?:RequestParams)
Sticker