A client for npm's internal acl service, and maybe eventually api.npmjs.com
var npm = require('acl-client')()
npm.packages.get('browserify')
.then(function(pkg){ /* yay */ })
.catch(function(err){ /* oof */ })
api.npmjs.com set process.env.ACL_CLIENT_HOST.Every request takes an optional options object as its last argument. The following options are allowed:
ttl - time in seconds to cache the response in redis. If not set, cache will not be used. Value can also be a human-friendly string like 5 minutes or 4 hours.bearer - a string of the current username. Can be used if hapiRequest is not available. If both hapiRequest and bearer options are specified, bearer takes precedence.logger - an object with four methods: debug, info, warn, and error. See the bole API for more info.hapiRequest - a Hapi request object. If the request is from a logged-in user, this will set bearer automatically. The client will also emit log messages using the given request's logger.All PUT, POST, and DELETE operations require a bearer token. Some GET requests do too.
To inject a bearer token into the request, pass a hapi request object as the last argument, or an object with a bearer string:
npm.collaborators.get('@npm/foo', {hapiRequest: request})
// or
npm.collaborators.get('@npm/foo', {bearer: 'zeke'})
To enable the built-in redis cache, set ACL_CLIENT_REDIS_URL in the environment before
requiring the client. To cache a request, specify a TTL in seconds or a human-friendly
string like 5 hours or 20 minutes.
// set this _before_ requiring the module
process.env.ACL_CLIENT_REDIS_URL = 'redis://localhost:6379'
// initialize the client. The redis instance will be attached to each method
var npm = require('@npm/acl-client')()
// set a `ttl` option in seconds
npm.packages.get('browserify', {ttl: 60})
// or use a human-friendly string
npm.packages.get('browserify', {ttl: '2 hours'})
To invalidate the cache for a specific request, call that request's cache.drop method,
passing the same arguments used when making the initial request:
npm.packages.get.cache.drop('browserify')
.then(function(){
// bye-bye browserify
})
Note: the optional options object used to initially make the request, e.g.
{ttl: 60, logger: null}, need not be present when calling cache.drop()
ACL_CLIENT_HOST (required): the hostname (and optional port) to make requests to, sans http(s) scheme.ACL_CLIENT_CUSTOMER_HOST (optional): the hostname for npm.customer requestsACL_CLIENT_REDIS_URL (optional): a redis instance for caching request responsesSee dist/operations.json for more details about the methods below.
packages.get(packageName, [query], [options])packages.list([query], [options])packages.count([query], [options])packages.star(packageName, body, [options])packages.perms(packageName, [query], [options])packages.delete(packageName, [options])packages.create(body, [options])packages.getDefaultTeam(packageName, [query], [options])collaborators.list(packageName, [query], [options])collaborators.add(packageName, body, [options])collaborators.update(packageName, userName, body, [options])collaborators.delete(packageName, userName, [options])users.create(body, [options])users.update(userName, body, [options])users.get(userName, [query], [options])users.delete(userName, [options])users.login(userName, body, [options])users.verify(userName, body, [options])users.getPackages(userName, [query], [options])users.getStars(userName, [query], [options])users.createPackage(userName, body, [options])users.setLicense(userName, body, [options])users.getLicense(userName, body, [options])users.search([query], [options])teams.update(teamName, body, [options])teams.delete(teamName, [options])teams.addPackage(teamName, body, [options])teams.removePackage(teamName, [options])teams.addUser(teamName, body, [options])teams.removeUser(teamName, [options])orgs.create(body, [options])orgs.get(orgName, [query], [options])orgs.delete(orgName, [options])orgs.update(orgName, body, [options])orgs.addUser(orgName, body, [options])orgs.users.list(orgName, [query], [options])orgs.users.delete(orgName, [options])orgs.users.update(orgName, userName, body, [options])orgs.packages.list(orgName, [query], [options])orgs.packages.create(orgName, body, [options])orgs.teams.list(orgName, [query], [options])orgs.teams.create(orgName, body, [options])orgs.listScopes(orgName, [query], [options])orgs.setLicense(orgName, body, [options])customers.get(userName, [query], [options])customers.create(body, [options])customers.update(userName, body, [options])customers.delete(userName, [options])src/operations.yml defines a list of http operations. An operation looks like this:
name: packages.get
description: Get metadata for a specific npm package
path: /package/{name}
method: GET
When you require('acl-client')(), the index iterates over each
operation in the schema and binds a reusable request function to each. The end result
is a tree of functions, namespaced by their dot-delimited name property from the schema:
packages: {
get: [Function],
list: [Function],
count: [Function],
star: [Function],
perms: [Function],
delete: [Function],
create: [Function],
getDefaultTeam: [Function]
},
collaborators: {
list: [Function],
add: [Function],
update: [Function],
delete: [Function]
},
...