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

kju-client

v0.0.14

Published

A JavaScript client for kju

Downloads

12

Readme

KJU JavaScript SDK

This is the official JavaScript Client for KJU, that runs on Node.js and in the Browser

The SDK comes with two APIs:

For details about KJU, visit the KJU Website.

Install

npm

npm i kju-client

Browser

<script src="https://cdn.jsdelivr.net/gh/kju-org/kju-client/index.js"></script>

Example

// Initialize
kju = new KJU();

// Create a token
kju.personalToken({
		contact: "email"
	},token => {
	console.log(token) // sdn23nf29q...
})

// Create a message
kju.createMessage({
	msg: {
		content: "Will you agree?",
		reciever: "[email protected]",
		responses: ["Yes", "No"]
	},
	token: "ksdnt2n30...."
}, data => {
	console.log(data) // { messagee ... }
})

kju.redeemResonse({
	msgId: "2u192rj923rr",
	respId: "Yes",
	token: "293rhj238nj2fm"
}, data => {
	console.log(data) // { msg: "ok" }
})

Client API

The kju JS client has the folllowing functions:

personalToken

Creates a personalToken

kju.personalToken({
		contact: "email",
	}, token => {
	console.log(token) // sdn23nf29q...
})

createMessage

Creates a message

kju.createMessage({
	msg: {
		content: "Some text",
		reciever: "optional reciever(s)",
		responses: ["One", "Two"] // An array of predefined responses
	},
	token: "The creationToken"
}, data => {
	console.log(data) // returns the message
})

permitCorrespondence

Permits a given sender to send further messages

kju.createMessage({
	contact: "email of sender",
	token: "The creationToken"
}, data => {
	console.log(data) // returns ok
})

getMessage

Returns a single message by id

kju.getMessage({
	msgId: "The message Id"
	token: "The consumer token"
}, data => {
	console.log(data) // returns the message
})

deleteMessage

Delete a single message by id

kju.deleteMessage({
	msgId: "The message Id"
	token: "The creationToken that the message was created with"
}, data => {
	console.log(data) // returns a success message
})

getMessages

Returns multiple messages that have the message Tag embedded in the consumer token

kju.getMessages({
	token: "The consumer token"
}, data => {
	console.log(data) // returns the messages
})

redeemResponse

Redeems a response

kju.redeemResponse({
	msgId: "The message Id",
	respId: "The identifier of the response",
	token: "The consumer token"
}, data => {
	console.log(data) // returns a success message
})

redeemResponseByLink

Redeems a response using the complete link

kju.redeemResponseByLink("https://whater...", data => {
	console.log(data) // returns a success message
})

Processing API

This Part of the API is for automated message processing. You can use this API to listen to messages and programatically redeem responses.

listenHttp

Creates an express server and listens for messages on a specified http endpoint. When this endpoint is set as reciever in a message, the message will be transmitted to the listener for further processing.

Message example

{
	content: "blablalba",
	reciever: "http://myendpoint.com"
}

Example Listener

kju.listenHttp({
	route: '/', // path to listen on. "/"" is default
	port: 3000, // port to listen on. 3000 is default
	handler: ((msg, success, err) => {
		// msg is the message
		// success must be called with the responseId that should be auto-redeemed. Like: success("yes");
		// err should be called when something goes wrong on your side
	})
})