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

fluro

v2.2.36

Published

Promise based HTTP Fluro client for the browser and node.js

Downloads

954

Readme

Fluro Javascript API

Site | Documentation | REST API Documentation | Support

Javascript Frameworks

Frameworks are available for Vue, Angular and React Vue Plugin

Installation

Before installing update the .npmrc file with your font-awesome license number

npm install fluro --save

Getting Started

//Import the Fluro module
import Fluro from 'fluro';

/////////////////////////////////////////////

//Set some defaults 
const API_URL = 'https://api.fluro.io';
const APPLICATION_TOKEN = '$55fkshadh12425324...';
const APPLICATION_DOMAIN_NAME = 'https://myapplication.com'; 

/////////////////////////////////////////////

//Create a new Fluro instance
const fluro = new Fluro({
    apiURL: API_URL,
    applicationToken: APPLICATION_TOKEN,
    domain:APPLICATION_DOMAIN_NAME,
});

/////////////////////////////////////////////

//Optionally set a default timezone (otherwise will default to browser clock timezone)
fluro.date.defaultTimezone = 'Australia/Melbourne';

Authentication

The FluroAuth service makes it easy to handle actions and behaviours like login, logout, signup, reset password etc. It's often a good idea to save the user's session, which contains refresh and access tokens to local storage Once you have authenticated the fluro module will take care of authenticating your requests, refreshing tokens before they expire and caching data for more information checkout the FluroAuth module

If a static application token has been set then when a user signs out of the app all requests are made as the application instead of the user

Listening to user session changes

It's helpful to listen for the 'change' event so that your application can respond to a user logging in/out


//Listen for when the user logs in/out
fluro.auth.addEventListener('change', userUpdated);

/////////////////////////////////////////////

//Update whenever the user session changes
function userUpdated(user) {
    
    if(user) {
    	//The user is logged in and you have their session details
    	window.localStorage.userSession = user;
    } else {
    	//The user is logged out
    }

    //Get new information for the user's 'likes', 'plays', 'pins' etc..
    fluro.stats.refresh();
}

//Set the user session object if we already have it in localStorage
fluro.auth.set(window.localStorage.userSession);

Logging In as a Fluro User

To login and authenticate using your Fluro username and password you can use the FluroAuth.login function, upon successfuly login all subsequent requests to the API will be authenticated with your access token, and your token will be refreshed automatically until you sign out


//Login to the server as a general Fluro user
fluro.auth.login({
	'username':'[email protected]',
	'password':'yourpassword',
}).then(function(user) {
	//We are now logged in
})
.catch(function(err) {
	//Couldn't sign in
	console.log(err.message);
});

Logging in to an application as a managed persona

If your application is a public website or a whitelabelled product that you want users to be able to sign up or log in to, you can allow them to authenticate as a 'managed persona', this allows your users to authenticate without ever hearing or knowing about Fluro, giving you complete control over their usernames, passwords permissions and other information. Managed persona's can sign in to your applications resulting in an access/refresh token pair that grants them both the permissions of the persona AND the permissions of the application.


//Login to the server as a persona (whitelabelled user)
//By providing the application:true property
fluro.auth.login({
	'username':'[email protected]',
	'password':'yourpassword',
}, {
	application:true
}).then(function(user) {
	//We are now logged in
})
.catch(function(err) {
	//Couldn't sign in
	console.log(err.message);
});

Logging Out

//Logout and clear all caches
//And revert back to the application if a token has been provided
fluro.auth.logout()

Handling Errors

The FluroUtils service has a handy function for translating an error into a human readable message, this can be be helpful when needing to show error messages to the user


//Get the user session
fluro.api.get('/content/event/5ca3d64dd2bb085eb9d450db')
.then(function(response) {
	//Success
})
.catch(function(err) {
	var errorMessage = fluro.utils.errorMessage(err);
	console.log(errorMessage);
});