@blocklet/sdk
Blocklet SDK for blocklet developer
Install
yarn add @blocklet/sdk
or
npm install @blocklet/sdk
Auth SDK
Usage
const Auth = require('@blocklet/sdk/service/auth');
const client = new Auth();
const userDid = 'xxxxxxxx';
const { user } = await client.getUser(userDid);
Api
client.getUser(did)
Get user by user did
client.getUsers()
Get all users of the team
client.updateUserRole(did, role)
client.getPermissionsByRole(role)
Get all permissions of a role
client.getRoles()
Get all roles of the team
client.getPermissions()
Get all permissions of the team
Notification SDK
Usage
const Notification = require('@blocklet/sdk/service/notification');
const userDid = 'xxxxxxxx';
const notification = {
title: 'xxx',
body: 'xxx',
attachments: [
{
type: 'asset',
data: {
did: 'xxx',
chainHost: 'https://chainhost',
},
},
],
actions: [
{
name: 'xxx',
title: 'Go To Website',
link: 'https://arcblock.io',
},
],
};
const content = { message: 'this is a message' };
const actions = [];
await Notification.sendToUser(userDid, notification);
await Notification.sendToUser(userDid, [notification, anotherNotification]);
await Notification.sendToUser([userDid, anotherUserDid], notification);
await Notification.sendToUser([userDid, anotherUserDid], [notification, anotherNotification]);
Api
notification.sendToUser(receiver, notification)
Send notification to an account
- receiver
string | array<string>
required - notification
object | array<object>
required
- notification.title
string
- notification.body
string
- notification.attachments
array<object>
- attachment.type
enum
'asset', 'vc', 'token' required - attachment.data
object
- type: text
- type
string
- message
string
- type: asset
- did
string
did - chainHost
string
uri
- type: vc
- credential
object
- tag
string
- type: token
- address
string
did - amount
string
- symbol
string
- senderDid
string
did - chainHost
string
- decimal
integer
- notification.actions
array<object>
- name
string
required - title
string
- color
string
- bgColor
string
- link
string
uri
WalletAuthenticator SDK
Usage
const { WalletAuthenticator } = require('@blocklet/sdk');
const authenticator = new WalletAuthenticator();
WalletHandler SDK
Usage
const AuthStorage = require('@arcblock/did-auth-storage-nedb');
const { WalletAuthenticator, WalletHandlers } = require('@blocklet/sdk');
const authenticator = new WalletAuthenticator();
const handlers = new WalletHandlers({
authenticator,
tokenGenerator: () => Date.now().toString(),
tokenStorage: new AuthStorage({
dbPath: path.join(process.env.BLOCKLET_DATA_DIR, 'auth.db'),
onload: (err) => {
if (err) {
console.error(`Failed to load database from ${path.join(process.env.BLOCKLET_DATA_DIR, 'auth.db')}`, err);
}
},
}),
});
Database SDK
A database library for develop blocklet, it's a wrapper of nedb.
Supply a simpler way to use nedb. Just use new Database([dbName])
, or you can pass a object option as second parameter to create a database as origin nedb way new Database([dbName], [options])
Supply full-promise support.
Usage
const { Database } = require('@blocklet/sdk');
(async () => {
const db1 = new Database('db1');
const data1 = await db1.find().skip(1).limit(10);
class MyDatabase extends Database {
constructor(name) {
super(name);
}
async extraFn() {
return 'extra';
}
}
const db2 = new MyDatabase('db2');
const data2 = await db2.find().paginate(1, 10);
const data2Extra = await db2.extraFn();
})();