libnpmaccess
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -5,2 +5,7 @@ # Change Log | ||
<a name="2.0.1"></a> | ||
## [2.0.1](https://github.com/npm/libnpmaccess/compare/v2.0.0...v2.0.1) (2018-08-24) | ||
<a name="2.0.0"></a> | ||
@@ -7,0 +12,0 @@ # [2.0.0](https://github.com/npm/libnpmaccess/compare/v1.2.2...v2.0.0) (2018-08-21) |
149
index.js
@@ -5,6 +5,5 @@ 'use strict' | ||
const getStream = require('get-stream') | ||
const JSONStream = require('JSONStream') | ||
const npa = require('npm-package-arg') | ||
const npmFetch = require('npm-registry-fetch') | ||
const PassThrough = require('stream').PassThrough | ||
const {PassThrough} = require('stream') | ||
const validate = require('aproba') | ||
@@ -78,12 +77,15 @@ | ||
cmd.lsPackages = (...args) => { | ||
return getStream.array( | ||
cmd.lsPackages.stream(...args) | ||
).then(data => data.reduce((acc, [key, val]) => { | ||
if (!acc) { | ||
acc = {} | ||
} | ||
acc[key] = val | ||
return acc | ||
}, null)) | ||
cmd.lsPackages = (scope, team, opts) => { | ||
opts = AccessConfig(opts) | ||
return new opts.Promise((resolve, reject) => { | ||
return getStream.array( | ||
cmd.lsPackages.stream(scope, team, opts) | ||
).then(data => data.reduce((acc, [key, val]) => { | ||
if (!acc) { | ||
acc = {} | ||
} | ||
acc[key] = val | ||
return acc | ||
}, null)).then(resolve, reject) | ||
}) | ||
} | ||
@@ -93,50 +95,49 @@ | ||
opts = AccessConfig(opts) | ||
const parser = JSONStream.parse('*', (value, [key]) => { | ||
if (value === 'read') { | ||
return [key, 'read-only'] | ||
} else if (value === 'write') { | ||
return [key, 'read-write'] | ||
} else { | ||
return [key, value] | ||
validate('SSO|SZO', [scope, team, opts]) | ||
scope = scope.replace(/^@/, '') | ||
let uri | ||
if (team) { | ||
uri = `/-/team/${eu(scope)}/${eu(team)}/package` | ||
} else { | ||
uri = `/-/org/${eu(scope)}/package` | ||
} | ||
opts = opts.concat({ | ||
query: {format: 'cli'}, | ||
mapJson (value, [key]) { | ||
if (value === 'read') { | ||
return [key, 'read-only'] | ||
} else if (value === 'write') { | ||
return [key, 'read-write'] | ||
} else { | ||
return [key, value] | ||
} | ||
} | ||
}) | ||
new opts.Promise((resolve, reject) => { | ||
validate('SSO|SZO', [scope, team, opts]) | ||
scope = scope.replace(/^@/, '') | ||
let uri | ||
if (team) { | ||
uri = `/-/team/${eu(scope)}/${eu(team)}/package` | ||
const ret = new PassThrough({objectMode: true}) | ||
npmFetch.json.stream(uri, '*', opts).on('error', err => { | ||
if (err.code === 'E404' && !team) { | ||
uri = `/-/user/${eu(scope)}/package` | ||
npmFetch.json.stream(uri, '*', opts).on( | ||
'error', err => ret.emit('error', err) | ||
).pipe(ret) | ||
} else { | ||
uri = `/-/org/${eu(scope)}/package` | ||
ret.emit('error', err) | ||
} | ||
opts = opts.concat({query: {format: 'cli'}}) | ||
return npmFetch(uri, opts).catch(err => { | ||
if (err.code === 'E404' && !team) { | ||
uri = `/-/user/${eu(scope)}/package` | ||
return npmFetch(uri, opts) | ||
} else { | ||
throw err | ||
} | ||
}).then(resolve, reject) | ||
}).then(res => { | ||
// NOTE: I couldn't figure out how to test the following, so meh | ||
/* istanbul ignore next */ | ||
res.body.on('error', err => parser.emit('error', err)) | ||
return res.body.pipe(parser) | ||
}, err => parser.emit('error', err)) | ||
const pt = new PassThrough({objectMode: true}) | ||
parser.on('error', err => pt.emit('error', err)) | ||
return parser.pipe(pt) | ||
}).pipe(ret) | ||
return ret | ||
} | ||
cmd.lsCollaborators = (...args) => { | ||
return getStream.array( | ||
cmd.lsCollaborators.stream(...args) | ||
).then(data => data.reduce((acc, [key, val]) => { | ||
if (!acc) { | ||
acc = {} | ||
} | ||
acc[key] = val | ||
return acc | ||
}, null)) | ||
cmd.lsCollaborators = (spec, user, opts) => { | ||
opts = AccessConfig(opts) | ||
return new opts.Promise((resolve, reject) => { | ||
return getStream.array( | ||
cmd.lsCollaborators.stream(spec, user, opts) | ||
).then(data => data.reduce((acc, [key, val]) => { | ||
if (!acc) { | ||
acc = {} | ||
} | ||
acc[key] = val | ||
return acc | ||
}, null)).then(resolve, reject) | ||
}) | ||
} | ||
@@ -146,29 +147,17 @@ | ||
opts = AccessConfig(opts) | ||
const parser = JSONStream.parse('*', (value, [key]) => { | ||
if (value === 'read') { | ||
return [key, 'read-only'] | ||
} else if (value === 'write') { | ||
return [key, 'read-write'] | ||
} else { | ||
return [key, value] | ||
spec = npar(spec) | ||
validate('OSO|OZO', [spec, user, opts]) | ||
const uri = `/-/package/${eu(spec.name)}/collaborators` | ||
return npmFetch.json.stream(uri, '*', opts.concat({ | ||
query: {format: 'cli', user: user || undefined}, | ||
mapJson (value, [key]) { | ||
if (value === 'read') { | ||
return [key, 'read-only'] | ||
} else if (value === 'write') { | ||
return [key, 'read-write'] | ||
} else { | ||
return [key, value] | ||
} | ||
} | ||
}) | ||
new opts.Promise((resolve, reject) => { | ||
spec = npar(spec) | ||
validate('OSO|OZO', [spec, user, opts]) | ||
const uri = `/-/package/${eu(spec.name)}/collaborators` | ||
const query = {format: 'cli'} | ||
if (user) { query.user = user } | ||
return npmFetch(uri, opts.concat({ | ||
query | ||
})).then(resolve, reject) | ||
}).then(res => { | ||
// NOTE: I couldn't figure out how to test the following, so meh | ||
/* istanbul ignore next */ | ||
res.body.on('error', err => parser.emit('error', err)) | ||
return res.body.pipe(parser) | ||
}, err => parser.emit('error', err)) | ||
const pt = new PassThrough({objectMode: true}) | ||
parser.on('error', err => pt.emit('error', err)) | ||
return parser.pipe(pt) | ||
})) | ||
} | ||
@@ -175,0 +164,0 @@ |
{ | ||
"name": "libnpmaccess", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "programmatic library for `npm access` commands", | ||
@@ -35,8 +35,7 @@ "author": { | ||
"dependencies": { | ||
"JSONStream": "^1.3.4", | ||
"aproba": "^2.0.0", | ||
"get-stream": "^4.0.0", | ||
"npm-package-arg": "^6.1.0", | ||
"npm-registry-fetch": "^3.2.1" | ||
"npm-registry-fetch": "^3.8.0" | ||
} | ||
} |
@@ -186,2 +186,12 @@ 'use strict' | ||
test('ls-packages error on user', t => { | ||
const srv = tnock(t, REG) | ||
srv.get('/-/org/myuser/package?format=cli').reply(404, {error: 'not found'}) | ||
srv.get('/-/user/myuser/package?format=cli').reply(404, {error: 'not found'}) | ||
return access.lsPackages('myuser', null, OPTS).then( | ||
() => { throw new Error('should not have succeeded') }, | ||
err => t.equal(err.code, 'E404', 'spit out 404 if both reqs fail') | ||
) | ||
}) | ||
test('ls-packages bad response', t => { | ||
@@ -188,0 +198,0 @@ tnock(t, REG).get( |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4
61920
484
- RemovedJSONStream@^1.3.4
Updatednpm-registry-fetch@^3.8.0