libnpmaccess
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -5,2 +5,24 @@ # Change Log | ||
<a name="1.1.0"></a> | ||
# [1.1.0](https://github.com/npm/libnpmaccess/compare/v1.0.0...v1.1.0) (2018-08-17) | ||
### Bug Fixes | ||
* **2fa:** escape package names correctly ([f2d83fe](https://github.com/npm/libnpmaccess/commit/f2d83fe)) | ||
* **grant:** fix permissions validation ([07f7435](https://github.com/npm/libnpmaccess/commit/07f7435)) | ||
* **ls-collaborators:** fix package name escaping + query ([3c02858](https://github.com/npm/libnpmaccess/commit/3c02858)) | ||
* **ls-packages:** add query + fix fallback request order ([bdc4791](https://github.com/npm/libnpmaccess/commit/bdc4791)) | ||
* **node6:** stop using Object.entries() ([4fec03c](https://github.com/npm/libnpmaccess/commit/4fec03c)) | ||
* **public/restricted:** body should be string, not bool ([cffc727](https://github.com/npm/libnpmaccess/commit/cffc727)) | ||
* **readme:** fix up title and badges ([2bd6113](https://github.com/npm/libnpmaccess/commit/2bd6113)) | ||
* **specs:** require specs to be registry specs ([7892891](https://github.com/npm/libnpmaccess/commit/7892891)) | ||
### Features | ||
* **test:** add 100% coverage test suite ([22b5dec](https://github.com/npm/libnpmaccess/commit/22b5dec)) | ||
<a name="1.0.0"></a> | ||
@@ -7,0 +29,0 @@ # 1.0.0 (2018-08-17) |
50
index.js
@@ -13,12 +13,20 @@ 'use strict' | ||
const eu = encodeURIComponent | ||
const npar = spec => { | ||
spec = npa(spec) | ||
if (!spec.registry) { | ||
throw new Error('`spec` must be a registry spec') | ||
} | ||
return spec | ||
} | ||
const cmd = module.exports = {} | ||
cmd.public = (spec, opts) => setAccess(spec, true, opts) | ||
cmd.restricted = (spec, opts) => setAccess(spec, false, opts) | ||
cmd.public = (spec, opts) => setAccess(spec, 'public', opts) | ||
cmd.restricted = (spec, opts) => setAccess(spec, 'restricted', opts) | ||
function setAccess (spec, access, opts) { | ||
opts = AccessConfig(opts) | ||
return new opts.Promise((resolve, reject) => { | ||
spec = npa(spec) | ||
validate('OBO', [spec, access, opts]) | ||
const uri = `/-/package/${spec.escapedName}/access` | ||
spec = npar(spec) | ||
validate('OSO', [spec, access, opts]) | ||
const uri = `/-/package/${eu(spec.name)}/access` | ||
return npmFetch.json(uri, opts.concat({ | ||
@@ -35,7 +43,7 @@ method: 'POST', | ||
return new opts.Promise((resolve, reject) => { | ||
spec = npa(spec) | ||
validate('OSSSO') | ||
spec = npar(spec) | ||
validate('OSSSO', [spec, scope, team, permissions, opts]) | ||
scope = scope.replace(/^@/, '') | ||
if (permissions !== 'read-write' || permissions !== 'read-only') { | ||
throw new Error('`permissions` must be `read-write` or `read-only`. Got `' + permissions + '`instead') | ||
if (permissions !== 'read-write' && permissions !== 'read-only') { | ||
throw new Error('`permissions` must be `read-write` or `read-only`. Got `' + permissions + '` instead') | ||
} | ||
@@ -55,4 +63,4 @@ const uri = `/-/team/${eu(scope)}/${eu(team)}/package` | ||
return new opts.Promise((resolve, reject) => { | ||
spec = npa(spec) | ||
validate('OSSSO') | ||
spec = npar(spec) | ||
validate('OSSO', [spec, scope, team, opts]) | ||
scope = scope.replace(/^@/, '') | ||
@@ -78,7 +86,8 @@ const uri = `/-/team/${eu(scope)}/${eu(team)}/package` | ||
} else { | ||
uri = `/-/user/${eu(scope)}/package` | ||
uri = `/-/org/${eu(scope)}/package` | ||
} | ||
opts = opts.concat({query: {format: 'cli'}}) | ||
return npmFetch.json(uri, opts).catch(err => { | ||
if (err.code === 'E404' && !team) { | ||
uri = `/-/org/${eu(scope)}/package` | ||
uri = `/-/user/${eu(scope)}/package` | ||
return npmFetch.json(uri, opts) | ||
@@ -95,7 +104,9 @@ } else { | ||
return new opts.Promise((resolve, reject) => { | ||
spec = npa(spec) | ||
spec = npar(spec) | ||
validate('OSO|OZO', [spec, user, opts]) | ||
const uri = `/-/package/${spec.escapedName}/collaborators` | ||
const uri = `/-/package/${eu(spec.name)}/collaborators` | ||
const query = {format: 'cli'} | ||
if (user) { query.user = user } | ||
return npmFetch.json(uri, opts.concat({ | ||
query: {user, format: 'cli'} | ||
query | ||
})).then(translatePermissions).then(resolve, reject) | ||
@@ -108,3 +119,4 @@ }) | ||
const newPerms = {} | ||
for (let [key, val] of Object.entries(perms)) { | ||
for (let key of Object.keys(perms)) { | ||
const val = perms[key] | ||
if (val === 'read') { | ||
@@ -126,5 +138,5 @@ newPerms[key] = 'read-only' | ||
return new opts.Promise((resolve, reject) => { | ||
spec = npa(spec) | ||
spec = npar(spec) | ||
validate('OBO', [spec, required, opts]) | ||
const uri = `/-/package/${spec.escapedName}/access` | ||
const uri = `/-/package/${eu(spec.name)}/access` | ||
return npmFetch.json(uri, opts.concat({ | ||
@@ -131,0 +143,0 @@ method: 'POST', |
{ | ||
"name": "libnpmaccess", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "programmatic library for `npm access` commands", | ||
@@ -21,7 +21,8 @@ "author": { | ||
"devDependencies": { | ||
"weallbehave": "*", | ||
"weallcontribute": "*", | ||
"nock": "^9.6.1", | ||
"standard": "*", | ||
"standard-version": "*", | ||
"tap": "*" | ||
"tap": "*", | ||
"weallbehave": "*", | ||
"weallcontribute": "*" | ||
}, | ||
@@ -28,0 +29,0 @@ "repository": { |
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
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
55928
12
405
0
203
6
1