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

@blockv/web-face-sdk

v1.5.0

Published

This is the official BLOCKv Web Face SDK. It allows you to easily build Web Faces which communicate with compatible Vatom Viewers.

Downloads

69

Readme

BLOCKv Web Face SDK

This is the official BLOCKv Web Face SDK. It allows you to easily build Web Faces which communicate with compatible Vatom Viewers.

Installation

Install from npm

npm install @blockv/web-face-sdk

Import (ES6 & ES7)

import Blockv from '@blockv/web-face-sdk'

Import via script tag

<script src='https://unpkg.com/@blockv/web-face-sdk/dist/web-face-sdk.min.js'></script>

Interacting with the SDK

The Web Face SDK provides a simple interface into the underlying Vatom Viewer.

Getting Started

If you would like to access the backing Vatom or interact with the BLOCKv platform in any way, you should start by initializing the SDK.

Trying to access any other features of the SDK prior to initialization will cause an error to be thrown.

    Blockv.init()
      .then((data) => {
        // the SDK is ready to use
        return data;
      })
      .catch((error) => {
        // this web code is not being displayed by a BLOCKv viewer
      });

By initializing the SDK you allow it to establish a connection with the underlying viewer and gain context of the backing Vatom.

Backing Vatom

Object containing the data for the backing Vatom. The backing Vatom is the Vatom to which this face belongs, typically, it is Vatom currently being displayed by the viewer.

Trying to access this prior to initializing the SDK will cause an error to be thrown.

    Blockv.backingVatom;

Backing Face

This is the data for the selected face being used to display this Vatom.

Trying to access this prior to initializing the SDK will cause an error to be thrown.

    Blockv.backingFace;

Backing Vatom Updates

Respond to updates to the backing Vatom, e.g. state updates, by adding an event listener.

    Blockv.backingVatom.addEventListener('update', (vatom) => {
        // Vatom is the updated backing vatom
    });

Fetching a Vatom

Fetch a permitted Vatom by providing its id.

Restriction: Only the backing Vatom of one of its immediate children may be queried.

Providing an id that is not the backing Vatom or one its immediate children will throw an error.

    Blockv.vatomManager
      .getVatom(Blockv.backingVatom.id)
      .then((vatom) => {
        // success
      });

Fetching a Vatom's Children

Fetch the children of the backing Vatom by providing its id.

Restriction: Only the backing Vatom may be queried.

Providing an id that is not the backing Vatom will throw an error.

    Blockv
      .vatomManager
      .getChildren(Blockv.backingVatom.id)
      .then((children) => {
        // children is an array of vatoms
      });

Performing an Action

Perform an action on a the backing Vatom by providing an action payload.

Restriction: Only permitted on the backing Vatom.

Providing an id that is not the backing Vatom throw an error.

    Blockv.vatomManager
      .performAction('<action-name>', {
          'this.id': Blockv.backingVatom.id, // this.id must match the backing vatom's id
          // ... other properties required for the action.
        })
      .then((response) => {
        // success
      });

Fetching a User's Public Profile

Fetch the public profile of any user by providing their id.

    Blockv.userManager
      .getPublicUser(Blockv.backingVatom.properties.owner)
      .then((user) => {
        // success
      })

Fetching the Current User's Public Profile

Fetch the public profile of the current user with additional information regarding their tokens.

    Blockv.userManager
      .getCurrentUser()
      .then((user) => {
        // success
      })

Updating the Parent ID of a Child Vatom

Allows the Web Face to set the parent ID of the one of the backing vAtoms children. This essentially gives the Web Face the ability to "Split" a child vAtom from the parent's folder.

    let parentID = null;
    let firstID = null;
    return Promise.resolve().then(() => {
      parentID = Blockv.backingVatom.properties.propertyData.parent_id;
      // find all children
      return Blockv.vatomManager.getChildren(Blockv.backingVatom.id);
    }).then((children) => {
      // sanity check
      if (children.length === 0) throw new Error('No child vatom found');
      // grab first id
      firstID = children[0].id;
      // set parent ID
      return Blockv.vatomManager.setParentId(firstID, parentID);
    }).then(() => {
      // parent id update on the child has been requested
    })

Observing Updates to the Backing Vatom's Children

Allows the Web face to observe changes to the backing Vatom's children.

// add a listener on for child updates
Blockv.init()
    .then((data) => {
        Blockv.backingVatom.addEventListener('children', this.onBackingVatomChildrenUpdate.bind(this));
      }
// function to call
onBackingVatomChildrenUpdate(data) {
    // handle changes to the 'vatoms' array containing the backing vatom's children
  }

Displaying Vatom Resources

Displaying Vatom resources requires each URL to be encoded with BLOCKv access credentials.

    Blockv.resourceManager
      .encodeResources(Blockv
        .backingVatom
        .properties
        .resources.map(res => res.value.value))
      .then((resources) => {
        // resources is an ordered array of encoded urls
      })

Custom Messages

You are able to send any custom messages to the viewer as follows (note, the message name must be prefixed with viewer.).

Sending a message with a name not prefixed by viewer. will throw an error.

    Blockv.sendMessage('viewer.<custom-message>', {/* ... custom data*/})
      .then((data) => {
        // success
      });

You are also able to receive custom messages sent by the viewer.

    Blockv.addRequestHandler('viewer.<custom-message>', data => {
      // ...
    });

Supported Custom Messages

All BLOCKv Vatoms apps support the following face messages:

| Method | Description | |-----------------------|--------------------------------------------------------------------------------------| | viewer.vatom.show | Request the viewer to engage the specified Vatom. | | viewer.map.show | Request the viewer to shows its map UI. | | viewer.qr.scan | Request the viewer to show a QR scanner and passes back the response to the web app. | | viewer.view.close | Request the viewer to close the current Vatom. | | viewer.scanner.show | Request the viewer to open a scanner and to interpret the scan result itself. | | viewer.card.show | Request the viewer to show the card view mode. | | viewer.url.open | Request the viewer to open the URL. | | viewer.scanner.show | Request the viewer to open the image recognition scanner. | | viewer.action.send | Request the viewer to prompt the user to send the vatom to another user. | | viewer.action.share | Request the viewer to prompt the user to share the vatom to another user. |

Author

BLOCKv

License

BLOCKv is available under the BLOCKv AG license. See the LICENSE file for more info.