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

@parallelmarkets/vanilla

v2.1.1

Published

ParallelMarkets.com JavaScript SDK loading utility

Downloads

2,634

Readme

Parallel Markets JavaScript SDK ES Module

CI Status npm version

This library provides a loading wrapper for the Parallel Markets JavaScript SDK as an ES module.

For a quick start, check out the example app.

Installation

Use npm to install the Parallel JS SDK module:

$> npm install --save @parallelmarkets/vanilla

Usage

The loadParallel function returns a promise that resolves once the SDK is loaded and ready. See below for an example using the async/await syntax in vanilla JavaScript.

import { loadParallel } from '@parallelmarkets/vanilla'

// load the parallel library with the given configuration information
const parallel = await loadParallel({ client_id: '123', environment: 'demo' })

// any element with the "parallel-login-button" class will render a button
parallel.showButton()

// at this point, all of the SDK functions can be called - i.e.,
// parallel.login(), parallel.subscribe(), etc.

Once the library is loaded, you can immediately utilize the SDK.

Initiating a Parallel Flow

After the Parallel SDK has been initialized (via loadParallel()), you can show a Parallel button or explicitly initiate a flow.

To automatically load a Parallel Passport button on your page, just follow these steps:

  1. Add the HTML class parallel-login-button to the parent element where you want the button to appear.
  2. Call showButton(), which will then find any elements with that class and render a login button child element for each.

For instance, to add a "Parallel Passport" button somewhere on your page:

<div class="parallel-login-button"></div>
import { loadParallel } from '@parallelmarkets/vanilla'

// wait for the loading to finish before calling any functions
const parallel = await loadParallel({ client_id: '123', environment: 'demo', flow_type: 'overlay' })

parallel.showButton()

Alternatively, you can provide your own button or link and call Parallel.login() when you're ready to send the user into an authentication flow. For instance:

<a href="#" onClick="showParallelFlow()">Log in with Parallel </a>
import { loadParallel } from '@parallelmarkets/vanilla'

// wait for the loading to finish before calling any functions
const parallel = await loadParallel({ client_id: '123', environment: 'demo', flow_type: 'overlay' })

const showParallelFlow = () => {
  parallel.login()
}

Upon completion, the user will be on the same page on your site where the authentication flow was initiated regardless of flow_type. This must be the same URL as the redirect_uri you provided when your account was first set up. This URL must match only for the initial authentication process. After that, you can call the getLoginStatus() and getProfile() functions on any page in your domain that has the Parallel Javascript SDK loaded.

Getting the Parallel ID

The result of any successful authentication event will include an authResponse field that indicates the status of the handoff. Once the status is connected, you can call the getProfile() function to get the Parallel ID for the user or business that completed the flow (along with other profile information). The ID can then be saved to your backend so your servers can make ongoing calls to get/update information for the user/business.

Here's an example of a few lines you can add to the example above if you want to send the profile information (including Parallel ID) to your backend.

parallel.subscribe('auth.login', () => {
  parallel.getProfile((profile) => {
    // example showing structure of the profile information
    console.log("Here's the profile info:", profile)

    // Call your backend to save the resulting ID to your backend so your server
    // can make ongoing calls to get/update information for this user/business.
    // In this example, your server would just save the resulting Parallel ID in
    // the profile information POSTed alongside the other investor profile information
    // you have stored on your backend.  For example, assuming that getInvestorId() returns
    // your unique ID for the user/business:
    const body = JSON.stringify({ profile, internalId: getInvestorId() })
    fetch('/save-parallel-id', { method: 'POST', body })
  })
})