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

dynalist-js

v1.0.3

Published

A Node.JS Client for dynalist.io

Downloads

598

Readme

client.js - a Node.JS Client for dynalist.io

CI Package Build

A thin client for accessing the Client API.

Installation

# NPM:
npm install dynalist-js

# Yarn:
yarn add dynalist-js

API client usage

Create Dynalist client instance

Require the module, then create an instance with the API Secret Token.

const Client = require('dynalist-js');

const dyn = new Client('<my developer api token>');

The API token can also be set/changed afterwards:

dyn.setToken('<my developer api token>');

Promises

All API methods return a promise object that can be used with .then or async/await.

Callbacks

All API methods can be called with a callback function as the last parameter.

Callback functions are always called with err and data parameters.

err is either null or an object with the attributes _code and _msg as described in the API documentation.

data is an object representing the JSON response without modifications.

API methods

listFiles - Get all documents and folders

// Using promise interface

dyn.listFiles()
    .then(response => console.log)
    .catch(error => console.log);

// Using async/await

async function getMyFiles() {
    const data = await dyn.listFiles();

    // …
}

// With callback

dyn.listFiles(function(err, data) {
    // …
});

You can use dyn.buildNodeTree(data.files) to create a hierarchical tree of folders and files.

editFile - Make changes to documents and folders

let changes = [
    // …
];

dyn.editFile(changes, function(err, data) {
    // …
});

readDocument - Get content of a document

let file_id = '…';

dyn.readDocument(file_id, function(err, data) {
    // …
});

You can use dyn.buildNodeTree(data.nodes) to create a hierarchical tree of the content.

checkForDocumentUpdates - Check if documents has been updated

let file_ids = ['…'];

dyn.checkForDocumentUpdates(file_ids, function(err, data) {
    // …
});

editDocument - Make change to the content of a document

let file_id = '…';

let changes = [
    // …
];

dyn.editDocument(file_id, changes, function(err, data) {
    // …
});

See API documentation for formatting changes.

sendToInbox - Send to inbox

let content = 'Call Dana';

let options = {
    index: -1,
    // See API documentation for more options:
    // https://apidocs.dynalist.io/#send-to-inbox
};

dyn.sendToInbox(content, options, function(err, data) {
    // …
});

options can be omitted when not needed:

dyn.sendToInbox('Call Fox', function(err, data) {
    // …
});

upload - Upload file (Pro only)

This API method is not yet implemented.

Utilities

Some helpers to massage data. They work only on local data.

util.buildUrl - Generate URL to document/node

let file_id = 'fe7a87a626f241b18ef30661';

let link_to_document = dyn.util.buildUrl(file_id);
// => https://dynalist.io/d/fe7a87a626f241b18ef30661

let node_id = '7be6403186fb8a7ed11931ed';

let link_to_node = dyn.util.buildUrl(file_id, node_id);
// => https://dynalist.io/d/fe7a87a626f241b18ef30661#z=7be6403186fb8a7ed11931ed

util.buildNodeMap - Generate a hash map of nodes

The document tree and the node tree inside a file are returned from the API as a flat array.

This method converts that array into an object with each node's id as the key.

dyn.readDocument('my document id', function(err, doc) {
    const nodeMap = dyn.util.buildNodeMap(doc.nodes);
    
    // Now the nodes can be accessed by using their ID as the key:
    console.log(nodeMap['7be6403186fb8a7ed11931ed']);
});

util.buildNodeTree - Generate a tree of nodes

Converts a flat array of nodes into a tree based on children associations.

dyn.readDocument(documentId, function(err, doc) {
    const tree = dyn.util.buildNodeTree(doc.nodes);

    console.log(JSON.stringify(tree, 0, 4));
});

Test

Rudimentary tests exist but could be extended by a lot. They are written with mocha and should.

The tests require a working API token and the ID of a file that can be used by the tests. The file will be modified, therefore it should not contain actually important information. Also note that frequent test runs may run into the API's rate limiting.

There is no option to run tests only offline yet. Tests WILL modify data in your account.

# Install dependencies
npm install

# Run test, passing in API token and file ID as environment variables
API_TOKEN=my_api_token FILE_ID=my_test_file npm test

# If you want to pass options to mocha you need to call mocha directly: 
API_TOKEN=my_api_token FILE_ID=my_test_file ./node_modules/.bin/mocha --grep "Client#listFiles"