A simple and easy to use SDK for SiYuan Note.
Getting Started
Installation
Using npm:
$ npm install @siyuan-community/siyuan-sdk
Using pnpm:
$ pnpm i @siyuan-community/siyuan-sdk
Using yarn:
$ yarn add @siyuan-community/siyuan-sdk
Examples
Initialize the client
import { Client } from "siyuan-sdk";
const client = new Client({
baseURL: "http://localhost:6806/",
token: "0123456789abcdef",
timeout: 10_000,
});
Update client configuration
client.updateOptions({
timeout: 30_000,
});
Call Kernel API (async)
import { KernelError, HTTPError } from "siyuan-sdk";
async function func() {
try {
const response = await client.pushMsg({
msg: "This is a notification message",
timeout: 7_000,
});
console.log(response);
}
catch (error) {
if (error instanceof KernelError) {
console.error(error.body);
}
else if (error instanceof HTTPError) {
console.error(error.status);
}
else {
throw error;
}
}
finally {
}
}
Call Kernel API (Promise)
import { KernelError, HTTPError } from "siyuan-sdk";
function func() {
client
.pushErrMsg({
msg: "This is an error message",
timeout: 7_000,
})
.then((response) => {
console.log(response);
})
.catch((error) => {
if (error instanceof KernelError) {
console.error(error.body);
}
else if (error instanceof HTTPError) {
console.error(error.status);
}
else {
throw error;
}
})
.finally(() => {
});
}
Use type definitions
import { types } from "@siyuan-community/siyuan-sdk";
const payload: types.kernel.api.notification.pushMsg.IPayload = {
msg: "This is a notification message",
timeout: 7_000,
};
import pushMsg from "@siyuan-community/siyuan-sdk/dist/src/types/kernel/api/notification/pushMsg";
const payload: pushMsg.IPayload = {
msg: "This is a notification message",
timeout: 7_000,
};
References
API References
Changelog
CHANGELOG.md