New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@siyuan-community/siyuan-sdk

Package Overview
Dependencies
Maintainers
3
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@siyuan-community/siyuan-sdk

A simple and easy to use SDK for SiYuan.

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
22
increased by120%
Maintainers
3
Weekly downloads
 
Created
Source

SiYuan SDK

GitHub LICENSE GitHub repo size GitHub code size GitHub commits GitHub latest commit Hits

NPM version NPM dependents (via libraries.io) NPM type definition NPM downloads NPM downloads (yearly) NPM downloads (monthly) NPM downloads (weekly)


简体中文 | English


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";

/* Initialize the client */
const client = new Client({
    /**
     * (Optional) SiYuan kernel service URL
     * @default: document.baseURI
     */
    baseURL: "http://localhost:6806/",

    /**
     * (Optional) SiYuan kernel service token
     * @default: empty
     */
    token: "0123456789abcdef", // , default is empty

    /**
     * (Optional) HTTP request timeout
     * Unit: milliseconds (ms)
     * @default: 60_000
     */
    timeout: 10_000,

    /**
     * (Optional) Other Axios request configurations
     * REF: https://axios-http.com/zh/docs/req_config
     * REF: https://www.axios-http.cn/docs/req_config
     */
});

Update client configuration

client.updateOptions({
    timeout: 30_000, // Change HTTP request timeout to 30 seconds
});

Call Kernel API (async)

import { KernelError, HTTPError } from "siyuan-sdk";

async function func() {
    try {
        /**
         * Asynchronously call the Kernel API `/api/notification/pushMsg`
         * Push notification message
         */
        const response = await client.pushMsg({
            msg: "This is a notification message", // Notification content
            timeout: 7_000, // Notification display time
        });
        console.log(response); // { "code": 0, "msg": "", "data": { "id": "0a1b2c3" } }
    }
    catch (error) {
        if (error instanceof KernelError) { // Kernel error
            console.error(error.body); // Response body { "code": -1, "msg": "error message", "data": null }
        }
        else if (error instanceof HTTPError) { // HTTP request error
            console.error(error.status); // HTTP status code
        }
        else { // Other uncaught errors
            throw error;
        }
    }
    finally {
        /* ... */
    }
}

Call Kernel API (Promise)

import { KernelError, HTTPError } from "siyuan-sdk";

function func() {
    /**
     * Asynchronously call the Kernel API `/api/notification/pushErrMsg`
     * Push error message
     */
    client
        .pushErrMsg({
            msg: "This is an error message", // Notification content
            timeout: 7_000, // Notification display time
        })
        .then((response) => {
            console.log(response); // { "code": 0, "msg": "", "data": { "id": "0a1b2c3" } }
        })
        .catch((error) => {
            if (error instanceof KernelError) { // Kernel error
                console.error(error.body); // Response body { "code": -1, "msg": "error message", "data": null }
            }
            else if (error instanceof HTTPError) { // HTTP request error
                console.error(error.status); // HTTP status code
            }
            else { // Other uncaught errors
                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", // Notification content
    timeout: 7_000, // Notification display time
};

import pushMsg from "@siyuan-community/siyuan-sdk/dist/src/types/kernel/api/notification/pushMsg";

const payload: pushMsg.IPayload = {
    msg: "This is a notification message", // Notification content
    timeout: 7_000, // Notification display time
};

References

API References

Changelog

CHANGELOG.md

Keywords

FAQs

Package last updated on 18 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc