Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@blockv/web-face-sdk

Package Overview
Dependencies
Maintainers
3
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@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.

  • 1.5.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
19
increased by18.75%
Maintainers
3
Weekly downloads
 
Created
Source

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:

MethodDescription
viewer.vatom.showRequest the viewer to engage the specified Vatom.
viewer.map.showRequest the viewer to shows its map UI.
viewer.qr.scanRequest the viewer to show a QR scanner and passes back the response to the web app.
viewer.view.closeRequest the viewer to close the current Vatom.
viewer.scanner.showRequest the viewer to open a scanner and to interpret the scan result itself.
viewer.card.showRequest the viewer to show the card view mode.
viewer.url.openRequest the viewer to open the URL.
viewer.scanner.showRequest the viewer to open the image recognition scanner.
viewer.action.sendRequest the viewer to prompt the user to send the vatom to another user.
viewer.action.shareRequest 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.

FAQs

Package last updated on 27 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc