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

cimpress-client-request

v0.6.0

Published

A reference implementation of a cimpress.io API client embodied in a wrapped version of request

Downloads

3

Readme

cimpress-client-request

A module for handling generation of OAuth Bearer tokens issued by Auth0 by integrating credential management into request.js.

Installation

npm i cimpress-client-request --save

or

yarn add cimpress-client-request

Usage

This module exposes a single method:

module.exports.request = function(config, cb) {}

This works as a drop-in replacement for request. Adopting this flow is as simple as these two surgical incisions:

//var request = require('request');
var request = require('cimpress-client-request');


// Note the set of 6 possible new options that can be passed in the request.js options.auth object.
// Every other property in the request options object works as normal, and you can call all of the
// convenience methods exposed by request.js.
var options = {
    auth: {
        client_id: 'see below',
        client_secret: 'see below',
        refresh_token: 'see below',
        target_id: 'see below'
    },
    keyGen: function(method, url, accessToken){ return url + method + accessToken },
    retry_count: 2,
};
request(options);

Here's how you should use those 4 auth parameters + 2 new parameters:

| Property | Description | |---|---| | client_id | The client id you wish to use to request client credential grants (https://auth0.com/docs/api-auth/grant/client-credentials). | | client_secret | The client secret you wish to use to request client credential grants (https://auth0.com/docs/api-auth/grant/client-credentials). | | refresh_token | A refresh token for use in delegation flows, retrieved from developer.cimpress.io. Defaults to the environment variable CIMPRESS_IO_REFRESH_TOKEN. | | target_id | OPTIONAL The client id for which you are trying to retrieve a delegated token. Note, if you don't know this, you can rely on a 401 with a Www-Authenticate to provide the client id. If you don't provide this config, and the service doesn't provide that header, your call will fail with a 401. | | authorization_server | OPTIONAL The server to call to request client credential grants (https://auth0.com/docs/api-auth/grant/client-credentials). This defaults to https://cimpress-dev.auth0.com/oauth/token. | audience | OPTIONAL The audience to send when requesting client credential grants (https://auth0.com/docs/api-auth/grant/client-credentials). This defaults to https://api.cimpress.io/ | | keyGen | OPTIONAL A function that returns a string to be used when caching responses. Takes in the url, method, and access token used. If not specified a default function is used | | retry_count | OPTIONAL The number of times to retry when receiving a non-2XX response |

You can specify your caching method by calling:

var request = require('cimpress-client-request');
var altCache = require('alternative-caching-library-here');

request.set_credentials_cache = altCache;

Note that the alternative caching method you use must support callbacks and have the following function definitions:

  • get(key, callback)
  • set(key, value, ttl)
  • flushAll()

Tests

You might also want to look at our tests to see some examples of usage.

You can run tests via grunt or grunt test.

Development

Install Nodejs & Grunt

sudo apt-get install nodejs

If you are running Ubuntu you need to create a symlink for node. (There is a naming conflict with the node package).

sudo ln -s /usr/bin/nodejs /usr/bin/node

Install Grunt command line tool:

sudo npm -g grunt-cli

If you see an error about NPM not installed, run the following command to install:

sudo apt-get install npm

Getting Started from Source

cd src/
sudo npm install
grunt

Package & Install without pushing to a remote NPM registry

To package:

npm pack

This will generate a tarball gzipped following a file name convention of: <module>-<version>.tgz

To install:

npm install <path-to-tgz>

git - pre-commit hook

If you would like to run jslint and units tests before your commit then create a file in .git/hooks/pre-commit with execute permissions with the following content:

#!/bin/sh

grunt --gruntfile $(git rev-parse --show-toplevel)/src/Gruntfile.js