libnpmaccess
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -5,2 +5,17 @@ # Change Log | ||
<a name="1.2.0"></a> | ||
# [1.2.0](https://github.com/npm/libnpmaccess/compare/v1.1.0...v1.2.0) (2018-08-20) | ||
### Bug Fixes | ||
* **readme:** fix up appveyor badge url ([42b45a1](https://github.com/npm/libnpmaccess/commit/42b45a1)) | ||
### Features | ||
* **streams:** add streaming result support for lsPkg and lsCollab ([0f06f46](https://github.com/npm/libnpmaccess/commit/0f06f46)) | ||
<a name="1.1.0"></a> | ||
@@ -7,0 +22,0 @@ # [1.1.0](https://github.com/npm/libnpmaccess/compare/v1.0.0...v1.1.0) (2018-08-17) |
99
index.js
'use strict' | ||
const figgyPudding = require('figgy-pudding') | ||
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 validate = require('aproba') | ||
@@ -74,5 +77,26 @@ | ||
cmd.lsPackages = (scope, team, opts) => { | ||
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.stream = (scope, team, opts) => { | ||
opts = AccessConfig(opts) | ||
return new opts.Promise((resolve, reject) => { | ||
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] | ||
} | ||
}) | ||
new opts.Promise((resolve, reject) => { | ||
validate('SSO|SZO', [scope, team, opts]) | ||
@@ -87,16 +111,45 @@ scope = scope.replace(/^@/, '') | ||
opts = opts.concat({query: {format: 'cli'}}) | ||
return npmFetch.json(uri, opts).catch(err => { | ||
return npmFetch(uri, opts).catch(err => { | ||
if (err.code === 'E404' && !team) { | ||
uri = `/-/user/${eu(scope)}/package` | ||
return npmFetch.json(uri, opts) | ||
return npmFetch(uri, opts) | ||
} else { | ||
throw err | ||
} | ||
}).then(translatePermissions).then(resolve, reject) | ||
}) | ||
}).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) | ||
} | ||
cmd.lsCollaborators = (spec, user, opts) => { | ||
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.stream = (spec, user, opts) => { | ||
opts = AccessConfig(opts) | ||
return new opts.Promise((resolve, reject) => { | ||
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] | ||
} | ||
}) | ||
new opts.Promise((resolve, reject) => { | ||
spec = npar(spec) | ||
@@ -107,24 +160,16 @@ validate('OSO|OZO', [spec, user, opts]) | ||
if (user) { query.user = user } | ||
return npmFetch.json(uri, opts.concat({ | ||
return npmFetch(uri, opts.concat({ | ||
query | ||
})).then(translatePermissions).then(resolve, reject) | ||
}) | ||
})).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) | ||
} | ||
function translatePermissions (perms) { | ||
if (!perms) { return null } | ||
const newPerms = {} | ||
for (let key of Object.keys(perms)) { | ||
const val = perms[key] | ||
if (val === 'read') { | ||
newPerms[key] = 'read-only' | ||
} else if (val === 'write') { | ||
newPerms[key] = 'read-write' | ||
} else { | ||
newPerms[key] = val | ||
} | ||
} | ||
return newPerms | ||
} | ||
cmd.tfaRequired = (spec, opts) => setRequires2fa(spec, true, opts) | ||
@@ -131,0 +176,0 @@ cmd.tfaNotRequired = (spec, opts) => setRequires2fa(spec, false, opts) |
{ | ||
"name": "libnpmaccess", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "programmatic library for `npm access` commands", | ||
@@ -35,3 +35,5 @@ "author": { | ||
"dependencies": { | ||
"JSONStream": "^1.3.4", | ||
"aproba": "^2.0.0", | ||
"get-stream": "^4.0.0", | ||
"npm-package-arg": "^6.1.0", | ||
@@ -38,0 +40,0 @@ "npm-registry-fetch": "^3.2.1" |
@@ -1,2 +0,2 @@ | ||
# libnpmaccess [![npm version](https://img.shields.io/npm/v/libnpmaccess.svg)](https://npm.im/libnpmaccess) [![license](https://img.shields.io/npm/l/libnpmaccess.svg)](https://npm.im/libnpmaccess) [![Travis](https://img.shields.io/travis/npm/libnpmaccess/latest.svg)](https://travis-ci.org/npm/libnpmaccess) [![AppVeyor](https://img.shields.io/appveyor/ci/zkat/libnpmaccess/latest.svg)](https://ci.appveyor.com/project/npm/libnpmaccess) [![Coverage Status](https://coveralls.io/repos/github/npm/libnpmaccess/badge.svg?branch=latest)](https://coveralls.io/github/npm/libnpmaccess?branch=latest) | ||
# libnpmaccess [![npm version](https://img.shields.io/npm/v/libnpmaccess.svg)](https://npm.im/libnpmaccess) [![license](https://img.shields.io/npm/l/libnpmaccess.svg)](https://npm.im/libnpmaccess) [![Travis](https://img.shields.io/travis/npm/libnpmaccess/latest.svg)](https://travis-ci.org/npm/libnpmaccess) [![AppVeyor](https://img.shields.io/appveyor/ci/zkat/libnpmaccess/latest.svg)](https://ci.appveyor.com/project/zkat/libnpmaccess) [![Coverage Status](https://coveralls.io/repos/github/npm/libnpmaccess/badge.svg?branch=latest)](https://coveralls.io/github/npm/libnpmaccess?branch=latest) | ||
@@ -3,0 +3,0 @@ [`libnpmaccess`](https://github.com/npm/libnpmaccess) is a Node.js |
'use strict' | ||
const figgyPudding = require('figgy-pudding') | ||
const getStream = require('get-stream') | ||
const {test} = require('tap') | ||
@@ -198,2 +199,23 @@ const tnock = require('./util/tnock.js') | ||
test('ls-packages stream', t => { | ||
const serverPackages = { | ||
'@foo/bar': 'write', | ||
'@foo/util': 'read', | ||
'@foo/other': 'shrödinger' | ||
} | ||
const clientPackages = [ | ||
['@foo/bar', 'read-write'], | ||
['@foo/util', 'read-only'], | ||
['@foo/other', 'shrödinger'] | ||
] | ||
tnock(t, REG).get( | ||
'/-/org/myorg/myteam/package?format=cli' | ||
).reply(200, serverPackages) | ||
return getStream.array( | ||
access.lsPackages.stream('myorg', 'myteam', OPTS) | ||
).then(data => { | ||
t.deepEqual(data, clientPackages, 'got streamed client package info') | ||
}) | ||
}) | ||
test('ls-collaborators', t => { | ||
@@ -218,2 +240,23 @@ const serverCollaborators = { | ||
test('ls-collaborators stream', t => { | ||
const serverCollaborators = { | ||
'myorg:myteam': 'write', | ||
'myorg:anotherteam': 'read', | ||
'myorg:thirdteam': 'special-case' | ||
} | ||
const clientCollaborators = [ | ||
['myorg:myteam', 'read-write'], | ||
['myorg:anotherteam', 'read-only'], | ||
['myorg:thirdteam', 'special-case'] | ||
] | ||
tnock(t, REG).get( | ||
'/-/package/%40foo%2Fbar/collaborators?format=cli' | ||
).reply(200, serverCollaborators) | ||
return getStream.array( | ||
access.lsCollaborators.stream('@foo/bar', null, OPTS) | ||
).then(data => { | ||
t.deepEqual(data, clientCollaborators, 'got collaborators') | ||
}) | ||
}) | ||
test('ls-collaborators w/scope', t => { | ||
@@ -220,0 +263,0 @@ const serverCollaborators = { |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
58963
490
0
5
+ AddedJSONStream@^1.3.4
+ Addedget-stream@^4.0.0
+ Addedget-stream@4.1.0(transitive)