1# libnpmaccess 2 3[](https://npm.im/libnpmaccess) 4[](https://npm.im/libnpmaccess) 5[](https://github.com/npm/cli/actions/workflows/ci-libnpmaccess.yml) 6 7[`libnpmaccess`](https://github.com/npm/libnpmaccess) is a Node.js 8library that provides programmatic access to the guts of the npm CLI's `npm 9access` command. This includes managing account mfa settings, listing 10packages and permissions, looking at package collaborators, and defining 11package permissions for users, orgs, and teams. 12 13## Example 14 15```javascript 16const access = require('libnpmaccess') 17const opts = { '//registry.npmjs.org/:_authToken: 'npm_token } 18 19// List all packages @zkat has access to on the npm registry. 20console.log(Object.keys(await access.getPackages('zkat', opts))) 21``` 22 23### API 24 25#### `opts` for all `libnpmaccess` commands 26 27`libnpmaccess` uses [`npm-registry-fetch`](https://npm.im/npm-registry-fetch). 28 29All options are passed through directly to that library, so please refer 30to [its own `opts` 31documentation](https://www.npmjs.com/package/npm-registry-fetch#fetch-options) 32for options that can be passed in. 33 34#### `spec` parameter for all `libnpmaccess` commands 35 36`spec` must be an [`npm-package-arg`](https://npm.im/npm-package-arg)-compatible 37registry spec. 38 39#### `access.getCollaborators(spec, opts) -> Promise<Object>` 40 41Gets collaborators for a given package 42 43#### `access.getPackages(user|scope|team, opts) -> Promise<Object>` 44 45Gets all packages for a given user, scope, or team. 46 47Teams should be in the format `scope:team` or `@scope:team` 48 49Users and scopes can be in the format `@scope` or `scope` 50 51#### `access.getVisibility(spec, opts) -> Promise<Object>` 52 53Gets the visibility of a given package 54 55#### `access.removePermissions(team, spec, opts) -> Promise<Boolean>` 56 57Removes the access for a given team to a package. 58 59Teams should be in the format `scope:team` or `@scope:team` 60 61#### `access.setAccess(package, access, opts) -> Promise<Boolean>` 62 63Sets access level for package described by `spec`. 64 65The npm registry accepts the following `access` levels: 66 67`public`: package is public 68`private`: package is private 69 70The npm registry also only allows scoped packages to have their access 71level set. 72 73#### access.setMfa(spec, level, opts) -> Promise<Boolean>` 74 75Sets the publishing mfa requirements for a given package. Level must be one of the 76following 77 78`none`: mfa is not required to publish this package. 79`publish`: mfa is required to publish this package, automation tokens 80cannot be used to publish. 81`automation`: mfa is required to publish this package, automation tokens 82may also be used for publishing from continuous integration workflows. 83 84#### access.setPermissions(team, spec, permssions, opts) -> Promise<Boolean>` 85 86Sets permissions levels for a given team to a package. 87 88Teams should be in the format `scope:team` or `@scope:team` 89 90The npm registry accepts the following `permissions`: 91 92`read-only`: Read only permissions 93`read-write`: Read and write (aka publish) permissions 94