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

nonstop-index-client

v0.2.0

Published

Library for communicating with the nonstop index HTTP API.

Downloads

9

Readme

nonstop-index-client

Library for communicating with the nonstop index HTTP API.

Built around hypermedia with hyped and halon.

Use

To get a configured instance of the server API, you can use one of the following approaches:

Configuration hash

See the Configuration section for a detailed explanation of the possible configuration values

// for uploading
var server = require( 'nonstop-index-client' )( {
	index: {
		host: 'my-index',
		port: 443,
		ssl: true
	}
} );

// for getting package lists/downloading
var server = require( 'nonstop-index-client' )( {
	index: {
		host: 'my-index',
		port: 443,
		ssl: true
	},
	package: {
		project: 'test',
		owner: 'arobson',
		branch: 'master'
	}
} );

// package lists will use the following URL (note - architecture and platform are set automatically)
// https://my-index:443/api/package/list?project=test&owner=arobson&branch=master&platform=darwin&architecture=x64

Daedalus - Service and Configuration

This example is a bit over-simplified. See daedalus for more advanced use patterns. The point is to show how you can easily use this library in conjunction with daedalus and fount to auto-discover the nonstop-index end point from Consul.

index.js

var daedalus = require( 'daedalus' )();
var server;

daedalus.initialize( {
	index: {
		service: 'conitnua-index',
		module: './index-client.js',
		config: 'index-client'
	}
} )
.then( function( fount ) {
	fount.resolve( 'index', function( index ) { server = index; } );
} );

index-client.js

// the format of the function returned from the module matches
// what daedalus expects
module.exports = require( 'nonstop-index-client' );

Configuration

The configuration hash can contain a lot of information. Depending on your use case, the required minimum information changes to ensure proper function. Defaults are shown for most values except where noted.

{
	index: {
		host: 'localhost',
		api: '/api',
		packages: '/nonstop/package', // URL segment where packages available for download are located
		port: 12321,
		ssl: false,
		token: '' // API token used to connect to the index
	},
	package: {
		architecture: , // defaults to your system's architecture, x86 or x64
		branch: undefined,
		build: undefined,
		downloads: './downloads', // where to download packages
		owner: undefined,
		platform: sysInfo.platform, // defaults to the platform of your OS: 'win32', 'linux' or 'darwin'
		project: undefined,
		releaseOnly: false, // indicates you only want to see releases when requesting the latest
		version: undefined
	}
}

Because this library uses configya, you can provide environment variables to override any of the values above. Here is a list for convenience:

  • NONSTOP_INDEX_HOST
  • NONSTOP_INDEX_API
  • NONSTOP_INDEX_PACKAGES
  • NONSTOP_INDEX_PORT
  • NONSTOP_INDEX_SSL
  • NONSTOP_INDEX_TOKEN
  • NONSTOP_PACKAGE_ARCHITECTURE
  • NONSTOP_PACKAGE_BRANCH
  • NONSTOP_PACKAGE_BUILD
  • NONSTOP_PACKAGE_FILES
  • NONSTOP_PACKAGE_OWNER
  • NONSTOP_PACKAGE_PLATFORM
  • NONSTOP_PACKAGE_PROJECT
  • NONSTOP_PACKAGE_RELEASE
  • NONSTOP_PACKAGE_VERSION

Note: if you will be requesting package lists, you must provide project, owner and branch in the config. There are no defaults for these values.

Uploading Packages (cli/build agent)

The only required information can be provided via the service argument from daedalus or via the config argument.

var index = require( 'nonstop-index-client' )( { host: 'my-index', port: 80 } );

Listing and Downloading Packages (bootstrapper)

Listing and downloading require the project, owner and branch to be specified (at least). The platform and architecture are automatically populated based on the machine the code is running on.

var server = require( 'nonstop-index-client' )( { 
	index: {
		host: 'my-index',
		port: 80,
		project: 'test',
		owner: 'arobson',
		branch: 'master',
		token: 'yourAPIToken'
	}
} );

Server API

Once you have access to the server instance, you can find the latest package version available, download a package or upload a package.

Changing the package filter

The parameters you set during configuration which change what packages will be "available" when getting latest can be changed during runtime by accessing the filter. The filter exposes a chainable set of calls for each of the parameters.

// changing the owner and branch of the package
index.config.filter.owner( 'mainRepo' ).branch( 'production' );

These changes will take affect the very next time getLatest is called.

download( package )

Downloads the target package. The file will be downloaded to the path specified by the downloads property of the config hash (default is './downloads'). Returns a promise that resolves to an object with the format:

	{ 
		path: /* path where the file was downloaded */, 
		installPath: /* path where packages should be unpacked */, 
		file: /* the file that was downloaded */
	}
// target - the full package name to download
index.download( 'test~arobson~master~0.1.0~1~darwin~any~any~x64.tar.gz' )
	.then( function( info ) {
		// on success
	} );

getLatest( ignore )

Gets information for the latest available package given the package properties set by config (or by the set calls). Returns a promise that resolves to a package information object with the format:

	{
		file: 'proj1~owner1~branch2~0.1.0~1~darwin~OSX~10.9.2~x64.tar.gz'
		project: 'test',
		owner: 'arobson',
		branch: 'master',
		version: '0.1.0-1',
		build: '1',
		platform: 'darwin',
		osName: 'any',
		osVersion: 'any',
		architecture: 'x64'
	}

Most likely, the property you need from this object will be the file property - supplying this to the download call will allow your application to download the latest package matching the configured filter.

// ignore - an array of versions that should be ignored when determining the latest package
index.getLatest( [] )
	.then( function( latest ) {
		index.download( latest.file )
			.then( function( info ) {
				...
			} ) 
	} );

upload( file )

Uploads a package. Returns a promise that resolves to the package information on success (statusCode === 200).

index.upload( './path/proj1~owner1~branch2~0.1.0~1~darwin~OSX~10.9.2~x64.tar.gz' )
	.then( function( packageInfo ) {
		// on success
	} );

Dependencies

This would not have been possible without several great Node modules:

  • configya
  • debug
  • fount
  • halon
  • lodash
  • machina
  • mkdirp
  • nonstop-pack
  • request
  • when

Dependents

The following nonstop projects rely on this library: