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

@privacybydesign/yivi-core

v0.1.3

Published

The state machine for implementing Yivi flows, that plugins can register on

Downloads

685

Readme

Yivi core

This package contains the state machine for implementing Yivi flows. yivi-core itself does not provide any real functionality. Plugins can be registered at the state machine and the plugins then provide the functionality depending on the state the state machine is in. The plugins can also request state modifications to the state machine.

Yivi core can be initialized in the following way:

const YiviCore = require('@privacybydesign/yivi-core');
const yivi     = new YiviCore(/* options */);

yivi.use(/* Plugin A */);
yivi.use(/* Plugin B */);

yivi.start();

You can pass an options object to the constructor, which will be passed on to each plugin that you register. Each plugin can choose which of your options to use or ignore.

const yivi = new YiviCore({
  debugging: true,            // Used by state machine and multiple plugins
  element:   '#yivi-web-form' // Used by `yivi-web` plugin
});

Documentation

More elaborate documentation on how to use this module can be found in the Yivi documentation. You can also find here how to design your own plugin.

API

use method

With the use method, new plugins can be added to the Yivi core instance. This method takes care of instantiating the plugin. You simply pass the plugin class as an argument to this function; you must not instantiate the plugin yourself.

yivi.use(/* Plugin A */);
yivi.use(/* Plugin B */);

start method

The start method starts the state machine and returns a Promise. Whatever parameters you pass to the start method get passed to the start method of the plugins too, but no plugins currently make use of that.

yivi.start()
    .then(result => console.log("Successful disclosure! 🎉", result))
    .catch(error => console.error("Couldn't do what you asked 😢", error));

The returned Promise only resolves when the state machine reaches the Success state and only rejects when the machine reaches a state with a final transaction. The end states BrowserNotSupported and Aborted always lead to a reject. The other possible end states are Cancelled, Timeout and Error.

In case none of the plugins supplied a return value via its close() method (which is the case for all our plugins in the /plugin directory), the return value on resolve will be the payload of the 'succeed' transition. In case of reject, the return value indicates in what state the state machine stopped, so: BrowserNotSupported, Cancelled, Timeout, Error or Aborted.

In case one or more plugins return a value on close(), the return value will be an array containing the yivi-core return value (as described above) as first item and the return values of the plugins as subsequent items. The order of the subsequent items is determined by the order in which the plugins were added with 'use'. Plugins that did not return a value, have the result undefined then.

yivi.start()
    .then(result => console.log("Successful disclosure! 🎉", result))
    .catch(error => {
          if (error === 'Aborted') {
            console.log('We closed it ourselves, so no problem 😅');
            return;
          }
          console.error("Couldn't do what you asked 😢", error);
    });

In the reject case, plugins may already inform the user of this issue, so please test if you need to catch the state yourself. You may wish to fall back to another authentication method automatically by catching the rejection and redirecting the user.

abort method

The abort method forces an yivi-core instance to abort the session and all associated plugins should stop making changes. In this way you can stop the instance from being active when it is not relevant anymore. The promise returned by the start method will be rejected with a Aborted message when abort is called. When start has not been called yet or when the start promise has already finished, then calling abort has no effect.

yivi.abort();