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

my613-js

v0.1.0

Published

Client library for My613

Downloads

5

Readme

my613-js

my613-js is a client library that makes using My613 easier. It provides support for authentication, including social login. It also exposes hooks for using My613 with Relay and other libraries.

My613-js is a universal JavaScript library, so it works in the browser, React Native and Node.js. However, log in with social providers (the login() method) is only available in the browser. Log in with Auth0 (loginWithToken()) is also supported on React Native.

Installation

npm install my613-js

Usage

Import the library

import my613 from 'my613-js'

Create an instance.

const my613 = new my613('https://YOUR-My613-URL.my613.com');

API

new My613(url: String) -> My613

Create a new instance of My613. Usually only one instance is needed so you can create it in one model and export.

import my613 from 'my613';

const my613 = new My613('https://YOUR-My613-URL.my613.com');
export default My613;

In browser environment, if token was stored in localStorage, it will be retrieved and stored inside the instance.

Authentication

.login(providerName: String) -> Promise

Browser only

Attempt to login with a providerName (google, facebook, twitter or github). The provider should be set up and enabled in your My613 app.

Opens a browser window with provider's login screen, where the user needs to grant your application permissions to read their data. If everything succeeds the promise returned is resolved with an object with following properties:

  • token - JSON Web Token for the user,
  • user - information about the user.

If the log in fails, the promise is reject with an error.

The token is stored in the My613 instance and in localStorage of the browser.

Emits login and tokenChange events.

.loginWithToken(providerName: String, loginToken: String)

Attempt to login to My613 with an Auth0 id_token. My613 validates the token on the backend side and logs the user in. Like login, sets token in the My613 object and stores it in localStorage (if available).

Emits login and tokenChange events.

Example usage with Auth0 Lock:

const my613 = new My613(MY613URL);
const lock = new Auth0Lock(auth0ClientID, auth0Domain);
lock.show((error, profile, id_token) => {
  My613.loginWithToken('auth0', id_token);
});
.logout() -> Promise

Browser only

Clears token from the instance and localStorage. Resolve promise with map of token and user, both of which are null.

Emits logout and tokenChange events.

.isLoggedIn() -> Boolean

Returns true if there is a token stored inside the instance.

.setToken(token: String)

Set the token manually. Can be used when custom authentication provider is used or on server.

Emits tokenChange event.

Querying

.query(query: String, variables: Object) -> Promise

Queries the My613 backend. Returns Promise that resolves if HTTP request succeeded, rejects otherwise.

.getAuthenticationHeaders() -> Object

Returns map of header name to value that need to be used to authenticate request with My613 backend.

Usage with Relay

.getRelayNetworkLayer(timeout: int, retryDelays: int) -> RelayNetworkLayer

Returns RelayNetworkLayer. Usage:

import Relay from 'react-relay';
import my613 from 'my613-js';

const my613 = new My613('https://YOUR-MY613-URL.my613.com');

Relay.injectNetworkLayer(My613.getRelayNetworkLayer());

Events

My613 extends EventEmitter, so it can be (un)subscribed with on and off. Here are the possible events:

login (loginResponse: Object)

When login succeded. loginResponse is the response from backend.

logout

When logout succeded.

tokenChange (token: String)

When token changes. token is the new token.

Compiling manually

To build UMD bundle:

npm run build:umd