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

kepler-sdk

v0.13.0

Published

This module provides a convenient Typescript interface for accessing orbits in [Kepler](https://github.com/spruceid/kepler).

Downloads

58

Readme

Kepler Typescript SDK

This module provides a convenient Typescript interface for accessing orbits in Kepler.

Quickstart

See the example dapp in ./example.

Installation

kepler-sdk is available via NPM:

npm install kepler-sdk

and Yarn:

yarn add kepler-sdk

The following webpack configuration is required:

module.exports = {
    experiments: {
        asyncWebAssembly: true,
    },
}

Concepts

Hosts and Orbits

Kepler is an application which provides user-controlled private, federated IPFS networks, called Orbits. For practical purposes, an Orbit can be thought of as analogous to an AWS S3 Bucket. A Host is a node in the federated IPFS network of an Orbit, designated by the controlling user(s) in the configuration options of the Orbit (called an Orbit Manifest).

Authorization and Delegation

To enforce the sole controllership of the user (or users), all requests to modify the content of an Orbit must be authenticated and correctly authorized. As such they must be signed by either a controlling user, or a delegate which correctly authorized by a controlling user.

Usage

The top-level Kepler class provides an API for connecting to a Kepler node and accessing an orbit belonging to an ethereum account.

import { Kepler } from 'kepler-sdk';
import { providers } from "ethers";

const metamaskSigner = new providers.Web3Provider(window.ethereum).getSigner();
const kepler = new Kepler(metamaskSigner, { hosts: ["http://localhost:8000"] });

OrbitConnection Interface

The OrbitConnection class provides a simple CRUD interface for Blob storage, for a storage bucket belonging to the connected ethereum account. It can be created from the Kepler object.

const orbitConnection: OrbitConnection | undefined = await kepler.orbit();

Once created, an OrbitConnection instance can upload objects to the Orbit:

const { ok, statusText } = await orbitConnection.put('my-content', new Blob( ... ));

if (!ok) {
    console.log("request failed: ", statusText)
}

Download objects from the Orbit:

const { data, ok } = await orbitConnection.get('my-content');

if (ok) {
    // use the data
}

Return just the metadata of an object:

const { headers, ok } = await orbitConnection.head('my-content');

if (ok) {
    headers.get('content-type');
}

List objects in the Orbit by prefix (returns an array of strings):

const { data, ok } = await orbitConnection.list('prefix');

if (ok) {
    for (key in data) {
        console.log(key)
    }
}

Delete objects from the Orbit:

const { ok } = await orbitConnection.delete('my-content');

if (ok) {
    // object has been deleted
}

Responses to the methods on OrbitConnection are a restricted version of the WHATWG-compliant Response object:

const response: { 
    data?: any,
    ok: boolean,
    status: number,
    statusText: string,
    headers: Headers
} = await orbitConnection.get('my-content');

One major difference to the above-linked Response type is the data property. This property is only inhabited when calling get or list. If the request parameter { streamBody: true } is provided, then data will be a ReadableStream:

await orbit.list('prefix', { streamBody: true })
    .then(({ data }: { data?: ReadableStream }) => {
        // consume the stream
    });

await orbitConnection.put('myGif', new Blob([gifData], {'image/gif'}));
await orbitConnection.get('myGif', { streamBody: true })
    .then(({ data }: { data?: ReadableStream }) => {
        // consume the stream
    });

Otherwise, for the list function data will always be of type string[], i.e. an array of keys. For the get function the type of data depends on the value that is being retrieved:

await orbitConnection.put('myPlainText', 'a string');
await orbitConnection.get('myPlainText')
    .then(({ data }: { data?: string }) => console.log(data));
// should log: 'a string'

await orbitConnection.put('myJson', { x: 1, y: true });
await orbitConnection.get('myJson')
    .then(({ data }: { data?: { x: number, y: boolean } }) => console.log(data));
// should log: '{x: 1, y: true}'

await orbitConnection.put('myBlob', new Blob([{ x: 1, y: true }], {'application/json'}));
await orbitConnection.get('myBlob')
    .then(({ data }: { data?: { x: number, y: boolean } }) => console.log(data));
// should log: '{x: 1, y: true}'

await orbitConnection.put('myGif', new Blob([gifData], {'image/gif'}));
await orbitConnection.get('myGif', { streamBody: true })
    .then(({ data }: { data?: Blob }) => {
        // use the Blob
    });

await orbit.list('prefix')
    .then(({ data }: { data?: string[] }) => {
        // use the list of keys
    });