npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@siyuan-community/siyuan-sdk

v0.3.11

Published

A simple and easy to use SDK for SiYuan.

Downloads

258

Readme

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

Default configuration

import { Client } from "@siyuan-community/siyuan-sdk";

/* Initialize the client (Axios is used to issue XHR by default) */
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) Other Axios request configurations
     * REF: https://axios-http.com/zh/docs/req_config
     * REF: https://www.axios-http.cn/docs/req_config
     */
});

Configure as a XHR client

import { Client } from "@siyuan-community/siyuan-sdk";

/* Initialize the XHR client (Axios is used to issue XHR) */
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) Other Axios request configurations
         * REF: https://axios-http.com/zh/docs/req_config
         * REF: https://www.axios-http.cn/docs/req_config
         */
    },
    "xhr",
);

Configure as a Fetch client

import { Client } from "@siyuan-community/siyuan-sdk";

/* Initialize the Fetch client (ofetch is used to issue Fetch request) */
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) Other ofetch request configurations
         * REF: https://www.npmjs.com/package/ofetch
         * REF: https://www.jsdocs.io/package/ofetch
         */
    },
    "fetch",
);

Update the model of HTTP client

client._setClientType("fetch"); // Change the client mode to Fetch
client._setClientType("xhr"); // Change the client mode to XHR

Update client global configuration

/* The global configuration of the current mode is updated by default */
client._updateOptions({
    token: "abcdef0123456789", // Change SiYuan API token to abcdef0123456789
});

/* Update the global configuration of XHR client Axios */
client._updateOptions(
    {
        timeout: 10_000, // The request timeout period is 10s
        /* Other Axios request configurations */
    },
    "xhr",
);

/* Update the global configuration of Fetch client ofetch */
client._updateOptions(
    {
        retry: 3, // The number of request retries is 3
        /* Other ofetch request configurations */
    },
    "fetch",
);

Call Kernel API (async)

import { KernelError, HTTPError } from "@siyuan-community/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-community/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/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