2022-01-14 19:42:48 +02:00
|
|
|
# libnpmaccess
|
|
|
|
|
|
|
|
[](https://npm.im/libnpmaccess)
|
|
|
|
[](https://npm.im/libnpmaccess)
|
2022-04-14 21:57:02 +00:00
|
|
|
[](https://github.com/npm/cli/actions/workflows/ci-libnpmaccess.yml)
|
2022-01-14 19:42:48 +02:00
|
|
|
|
|
|
|
[`libnpmaccess`](https://github.com/npm/libnpmaccess) is a Node.js
|
|
|
|
library that provides programmatic access to the guts of the npm CLI's `npm
|
2022-12-06 22:18:33 -05:00
|
|
|
access` command. This includes managing account mfa settings, listing
|
|
|
|
packages and permissions, looking at package collaborators, and defining
|
2022-01-14 19:42:48 +02:00
|
|
|
package permissions for users, orgs, and teams.
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
const access = require('libnpmaccess')
|
2022-12-06 22:18:33 -05:00
|
|
|
const opts = { '//registry.npmjs.org/:_authToken: 'npm_token }
|
2022-01-14 19:42:48 +02:00
|
|
|
|
|
|
|
// List all packages @zkat has access to on the npm registry.
|
2022-12-06 22:18:33 -05:00
|
|
|
console.log(Object.keys(await access.getPackages('zkat', opts)))
|
2022-01-14 19:42:48 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
### API
|
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
#### `opts` for all `libnpmaccess` commands
|
2022-01-14 19:42:48 +02:00
|
|
|
|
|
|
|
`libnpmaccess` uses [`npm-registry-fetch`](https://npm.im/npm-registry-fetch).
|
2022-12-06 22:18:33 -05:00
|
|
|
|
|
|
|
All options are passed through directly to that library, so please refer
|
|
|
|
to [its own `opts`
|
2022-01-14 19:42:48 +02:00
|
|
|
documentation](https://www.npmjs.com/package/npm-registry-fetch#fetch-options)
|
|
|
|
for options that can be passed in.
|
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
#### `spec` parameter for all `libnpmaccess` commands
|
2022-01-14 19:42:48 +02:00
|
|
|
|
|
|
|
`spec` must be an [`npm-package-arg`](https://npm.im/npm-package-arg)-compatible
|
|
|
|
registry spec.
|
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
#### `access.getCollaborators(spec, opts) -> Promise<Object>`
|
2022-01-14 19:42:48 +02:00
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
Gets collaborators for a given package
|
2022-01-14 19:42:48 +02:00
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
#### `access.getPackages(user|scope|team, opts) -> Promise<Object>`
|
2022-01-14 19:42:48 +02:00
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
Gets all packages for a given user, scope, or team.
|
2022-01-14 19:42:48 +02:00
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
Teams should be in the format `scope:team` or `@scope:team`
|
2022-01-14 19:42:48 +02:00
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
Users and scopes can be in the format `@scope` or `scope`
|
2022-01-14 19:42:48 +02:00
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
#### `access.getVisibility(spec, opts) -> Promise<Object>`
|
2022-01-14 19:42:48 +02:00
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
Gets the visibility of a given package
|
2022-01-14 19:42:48 +02:00
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
#### `access.removePermissions(team, spec, opts) -> Promise<Boolean>`
|
2022-01-14 19:42:48 +02:00
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
Removes the access for a given team to a package.
|
2022-01-14 19:42:48 +02:00
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
Teams should be in the format `scope:team` or `@scope:team`
|
2022-01-14 19:42:48 +02:00
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
#### `access.setAccess(package, access, opts) -> Promise<Boolean>`
|
2022-01-14 19:42:48 +02:00
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
Sets access level for package described by `spec`.
|
2022-01-14 19:42:48 +02:00
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
The npm registry accepts the following `access` levels:
|
2022-01-14 19:42:48 +02:00
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
`public`: package is public
|
|
|
|
`private`: package is private
|
2022-01-14 19:42:48 +02:00
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
The npm registry also only allows scoped packages to have their access
|
|
|
|
level set.
|
2022-01-14 19:42:48 +02:00
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
#### access.setMfa(spec, level, opts) -> Promise<Boolean>`
|
2022-01-14 19:42:48 +02:00
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
Sets the publishing mfa requirements for a given package. Level must be one of the
|
|
|
|
following
|
2022-01-14 19:42:48 +02:00
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
`none`: mfa is not required to publish this package.
|
|
|
|
`publish`: mfa is required to publish this package, automation tokens
|
|
|
|
cannot be used to publish.
|
|
|
|
`automation`: mfa is required to publish this package, automation tokens
|
|
|
|
may also be used for publishing from continuous integration workflows.
|
2022-01-14 19:42:48 +02:00
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
#### access.setPermissions(team, spec, permssions, opts) -> Promise<Boolean>`
|
2022-01-14 19:42:48 +02:00
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
Sets permissions levels for a given team to a package.
|
2022-01-14 19:42:48 +02:00
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
Teams should be in the format `scope:team` or `@scope:team`
|
2022-01-14 19:42:48 +02:00
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
The npm registry accepts the following `permissions`:
|
2022-01-14 19:42:48 +02:00
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
`read-only`: Read only permissions
|
|
|
|
`read-write`: Read and write (aka publish) permissions
|