diff options
author | Kat Marchán <kzm@sykosomatic.org> | 2017-05-09 14:46:02 -0700 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-05-23 19:39:43 +0200 |
commit | c0d858f8bb8ba5212548da2fba6a7bc02db0462b (patch) | |
tree | 99f043ec5aec3f5150a2aed0f62597234b158140 /deps/npm/node_modules/npm-registry-client/lib/org.js | |
parent | 994617370e8e66f3ea9488fec32fd912e7902396 (diff) | |
download | android-node-v8-c0d858f8bb8ba5212548da2fba6a7bc02db0462b.tar.gz android-node-v8-c0d858f8bb8ba5212548da2fba6a7bc02db0462b.tar.bz2 android-node-v8-c0d858f8bb8ba5212548da2fba6a7bc02db0462b.zip |
deps: upgrade npm beta to 5.0.0-beta.56
PR-URL: https://github.com/nodejs/node/pull/12936
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'deps/npm/node_modules/npm-registry-client/lib/org.js')
-rw-r--r-- | deps/npm/node_modules/npm-registry-client/lib/org.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/deps/npm/node_modules/npm-registry-client/lib/org.js b/deps/npm/node_modules/npm-registry-client/lib/org.js new file mode 100644 index 0000000000..7c73caf7da --- /dev/null +++ b/deps/npm/node_modules/npm-registry-client/lib/org.js @@ -0,0 +1,62 @@ +'use strict' + +module.exports = org + +var assert = require('assert') +var url = require('url') + +var subcommands = {} + +function org (subcommand, uri, params, cb) { + orgAssertions(subcommand, uri, params, cb) + return subcommands[subcommand].call(this, uri, params, cb) +} + +subcommands.set = subcommands.add = function (uri, params, cb) { + return this.request(apiUri(uri, 'org', params.org, 'user'), { + method: 'PUT', + auth: params.auth, + body: JSON.stringify({ + user: params.user, + role: params.role + }) + }, cb) +} + +subcommands.rm = function (uri, params, cb) { + return this.request(apiUri(uri, 'org', params.org, 'user'), { + method: 'DELETE', + auth: params.auth, + body: JSON.stringify({ + user: params.user + }) + }, cb) +} + +subcommands.ls = function (uri, params, cb) { + return this.request(apiUri(uri, 'org', params.org, 'user'), { + method: 'GET', + auth: params.auth + }, cb) +} + +function apiUri (registryUri) { + var path = Array.prototype.slice.call(arguments, 1) + .map(encodeURIComponent) + .join('/') + return url.resolve(registryUri, '-/' + path) +} + +function orgAssertions (subcommand, uri, params, cb) { + assert(subcommand, 'subcommand is required') + assert(subcommands.hasOwnProperty(subcommand), + 'org subcommand must be one of ' + Object.keys(subcommands)) + assert(typeof uri === 'string', 'registry URI is required') + assert(typeof params === 'object', 'params are required') + assert(typeof params.auth === 'object', 'auth is required') + assert(!cb || typeof cb === 'function', 'callback must be a function') + assert(typeof params.org === 'string', 'org name is required') + if (subcommand === 'rm' || subcommand === 'add' || subcommand === 'set') { + assert(typeof params.user === 'string', 'user is required') + } +} |