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

@staticbackend/js

v1.5.0

Published

JavaScript client library for StaticBackend

Downloads

12

Readme

@staticbackend/js

StaticBackend's JavaScript client library.

Installation

$> npm install @staticbackend/js

Usage

import { Backend } from "@staticbackend/js";

const bkn = new Backend("your-public-token", "na1");

Parameters:

  • Your public key
  • The region (we only supports na1 or dev for now)

If using the development server:

You may initiate the client like this for development:

const bkn = new Backend("anything", "dev");

When using the development server you don't need a valid public key.

Available helpers

register(email: string, password: string)

All you users will need a session token to perform CRUD operations against your database. Note that it's possible to have public repository.

const registerButton = document.getElementById("registerButton");
registerButton.addEventListener("click", async (e) => {
	const result = await bkn.register("[email protected]", "their-password");
	if (!result.ok) {
		// could not register that user
		console.error(result.content);
		return
	}

	// you must use this token on all sub-sequent requests:
	const token = result.content;

	// Ideally you'd store that somewhere for that user to retrieve like 
	// SessionStorage for instance.
});

login(email: string, password: string)

The login function is identical to the register. You'll receive a session token on successful login.

const result = await bkn.login(email, pass);
// handle result.ok == false or result.content contains their token.

Database

create(token: string, repo: string, doc)

createProjectButton.addEventListener("click", async (e) => {
	// thos values would come from <input> or something from your app
	const project = {
		name: "New project name",
		active: false,
		created: new Date()
	};

	const result = await bkn.create(token, "projects", project);
	// handle !result.ok or created document in result.content
});

list(token: string, repo: string)

const result = await bkn.list(token, "projects");
// handle !result.ok or result.content is an object
/*
{
	"page": 1,
	"total": 159,
	"results": [{
		id: "an id",
		name: "New project name",
		active: false,
		created: "20201223T07:48:24"
	}]
}
*/

getById(token: string, repo: string, id: string)

This return the document by ID.

query(token: string, repo: string, filters)

const filters = [
	["active", "==", false]
];

const result = await bkn.query(token, "projects", filters)
// handle !result.ok or result.content contains same as list().

The filters is an array or array having the following format:

["field-name", "operator", value]

The supported operators are:

"==", "!=", ">", "<", ">=", "<=", "in", "!in"

update(token: string, repo: string, id: string, doc)

Update a document by its ID, and only for the properties in the doc parameter.

delete(token: string, repo: string, id: string)

Delete a document by its ID

Upload file

<form enctype="multipart/form-data">
	<input type="file" name="file" />
</form>
<p>
	<button id="upbtn">upload file</button>
</p>
const upbtn = document.getElementById("upbtn");
upbtn.addEventListener("click", async (e) => {
	// you can grab your form by ID or whatever
	const form = document.forms[0];
	const result = await bkn.storeFile(token, form);
	if (!result.ok) {
		console.error(result.content);
		return;
	}

	console.log("file url", result.content);
})

When using the development server the URLs return will not be fully qualified domain name.

In production our CDN URL are returned.