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

signeasy

v0.2.0

Published

Node SDK for SignEasy Apis

Downloads

2

Readme

Node SDK for SignEasy [BETA]

A node sdk client for Signeasy API which will simplify the integration of Signeasy Authentication & APIs in your Express based Node web apps.

Requirements

Node 4 or above

Installation

Using NPM

npm i signeasy --save

Usage

This SDK contains 2 modules. One is a OAuth2 based custom passport-strategy for authentication of Signeasy users. Authentication will be needed to retreive accessToken & refreshToken.

Passport.js based Signeasy's OAuth Strategy for Express

const express = require('express');
const session = require('express-session');
const passport = require('passport');
const SEAuth = require('signeasy').OAuthStrategy;
const SEApi = require('signeasy').ApiClient;
const cfg = require('./config');
const server = express();


// Ideally, one would use something like Redis in production for storing our
// sessions
const userSessionCache = {};

server.use(
  session({
    secret: 'secret token',
    resave: true,
    saveUninitialized: true
  })
);

// Initialize Passport
server.use(passport.initialize());
server.use(passport.session());

// Add Signeasy OAuthClient as passport-strategy for authentication
passport.use(
  new SEAuth(
    {
      sandbox: true,
      clientID: cfg.clientID,
      clientSecret: cfg.clientSecret,
      callbackURL: cfg.callbackURL,
      scope: 'user:read rs:read rs:create rs:update original:read original:create original:update signed:create signed:read signed:update files:read template:manage webhooks:manage'
    },
    function(accessToken, refreshToken, profile, done) {

      const apiClient = new SEApi({
        sandbox: true,
        clientId: cfg.clientID,
        clientSecret: cfg.clientSecret,
        accessToken: accessToken,
        refreshToken: refreshToken
      });

      apiClient.getProfile((err, user) => {
        if (err) {
          done(err);
          return;
        }

        user.accessToken = accessToken;
        user.refreshToken = refreshToken;

        done(null, user);
      });
    }
  )
);

// More about serializeUser & deserializeUser functions here -
// http://www.passportjs.org/docs/configure/
passport.serializeUser(function(user, done) {
  userSessionCache[user.id] = user;
  done(undefined, user.id);
});

passport.deserializeUser(function(id, done) {
  done(undefined, userSessionCache[id]);
});

server.get('/auth/provider', passport.authenticate('signeasy'));
server.get(
  '/auth/provider/callback',
  passport.authenticate('signeasy'),
  (req, res) => {
    if (req.user) {
      res.json(req.user);
    } else {
      res.redirect('/auth/provider');
    }
  }
);

server.get('/', (req, res) => {
  res.sendFile(__dirname + '/index.html');
});

server.use((err, req, res, next) => {
  console.error('Server error', err);

  // Do not expose system error(`err`) to outside world
  res.status(500).json({
    errors: ['Something went wrong. Please try again later']
  });
});

server.listen(cfg.port, function() {
  console.log(`Visit ${cfg.baseUrl} to view the app`);
});

Using SignEasy API Client for making API requests

Once we have the accessToken & refreshToken, we can instantiate our new Signeasy API Client using which we will make all our api calls.

const SEApi = require('signeasy').ApiClient;

// Instantiating our new ApiClient
const apiClient = new SEApi({
  clientId: 'CLIENT_ID_HERE',
  clientSecret: 'CLIENT_SECRET_HERE',
  accessToken: 'ACCESS_TOKEN_HERE', // retrieved as part of Authorization
  refreshToken: 'REFRESH_TOKEN_HERE' // retrieved as part of Authorization
});

// Fetching current user profile
apiClient.getProfile((err, profile) => {
  if (err) {
    throw err;
  }

  console.log('Fetched user profile', profile);
})


// Fetching all files of current user
apiClient.getAllFiles((err, files) => {
  if (err) {
    throw err;
  }

  console.log('Fetched all files', files);
})

Docs

List of all functions & their usage is available here

Tests

Tests can be run either against Dev apis or production apis. To run tests, one needs to pass the following values as environment variables CLIENT_ID CLIENT_SECRET ACCESS_TOKEN REFRESH_TOKEN

To run tests against Dev apis, run the below command

ACCESS_TOKEN=YOUR_ACCESS_TOKEN REFRESH_TOKEN=YOUR_REFRESH_TOKEN CLIENT_ID=YOUR_CLIENT_ID CLIENT_SECRET=YOUR_CLIENT_SECRET npm test

To run tests against Production apis, run the below command

NODE_ENVIRONMENT=PRODUCTION ACCESS_TOKEN=YOUR_ACCESS_TOKEN REFRESH_TOKEN=YOUR_REFRESH_TOKEN CLIENT_ID=YOUR_CLIENT_ID CLIENT_SECRET=YOUR_CLIENT_SECRET npm test

Support

License

MIT