• Home
Name
Date
Size
#Lines
LOC

..--

test/12-May-2024-361329

.travis.ymlD12-May-202472 87

CHANGELOG.mdD12-May-20243.8 KiB13061

LICENSED12-May-2024717 1411

PULL_REQUEST_TEMPLATED12-May-2024183 80

README.mdD12-May-20249.3 KiB259184

appveyor.ymlD12-May-2024334 2317

index.jsD12-May-20245.2 KiB202186

package.jsonD12-May-20242 KiB6867

README.md

1# 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)
2
3[`libnpmaccess`](https://github.com/npm/libnpmaccess) is a Node.js
4library that provides programmatic access to the guts of the npm CLI's `npm
5access` command and its various subcommands. This includes managing account 2FA,
6listing packages and permissions, looking at package collaborators, and defining
7package permissions for users, orgs, and teams.
8
9## Example
10
11```javascript
12const access = require('libnpmaccess')
13
14// List all packages @zkat has access to on the npm registry.
15console.log(Object.keys(await access.lsPackages('zkat')))
16```
17
18## Table of Contents
19
20* [Installing](#install)
21* [Example](#example)
22* [Contributing](#contributing)
23* [API](#api)
24  * [access opts](#opts)
25  * [`public()`](#public)
26  * [`restricted()`](#restricted)
27  * [`grant()`](#grant)
28  * [`revoke()`](#revoke)
29  * [`tfaRequired()`](#tfa-required)
30  * [`tfaNotRequired()`](#tfa-not-required)
31  * [`lsPackages()`](#ls-packages)
32  * [`lsPackages.stream()`](#ls-packages-stream)
33  * [`lsCollaborators()`](#ls-collaborators)
34  * [`lsCollaborators.stream()`](#ls-collaborators-stream)
35
36### Install
37
38`$ npm install libnpmaccess`
39
40### Contributing
41
42The npm team enthusiastically welcomes contributions and project participation!
43There's a bunch of things you can do if you want to contribute! The [Contributor
44Guide](CONTRIBUTING.md) has all the information you need for everything from
45reporting bugs to contributing entire new features. Please don't hesitate to
46jump in if you'd like to, or even ask us questions if something isn't clear.
47
48All participants and maintainers in this project are expected to follow [Code of
49Conduct](CODE_OF_CONDUCT.md), and just generally be excellent to each other.
50
51Please refer to the [Changelog](CHANGELOG.md) for project history details, too.
52
53Happy hacking!
54
55### API
56
57#### <a name="opts"></a> `opts` for `libnpmaccess` commands
58
59`libnpmaccess` uses [`npm-registry-fetch`](https://npm.im/npm-registry-fetch).
60All options are passed through directly to that library, so please refer to [its
61own `opts`
62documentation](https://www.npmjs.com/package/npm-registry-fetch#fetch-options)
63for options that can be passed in.
64
65A couple of options of note for those in a hurry:
66
67* `opts.token` - can be passed in and will be used as the authentication token for the registry. For other ways to pass in auth details, see the n-r-f docs.
68* `opts.otp` - certain operations will require an OTP token to be passed in. If a `libnpmaccess` command fails with `err.code === EOTP`, please retry the request with `{otp: <2fa token>}`
69* `opts.Promise` - If you pass this in, the Promises returned by `libnpmaccess` commands will use this Promise class instead. For example: `{Promise: require('bluebird')}`
70
71#### <a name="public"></a> `> access.public(spec, [opts]) -> Promise`
72
73`spec` must be an [`npm-package-arg`](https://npm.im/npm-package-arg)-compatible
74registry spec.
75
76Makes package described by `spec` public.
77
78##### Example
79
80```javascript
81await access.public('@foo/bar', {token: 'myregistrytoken'})
82// `@foo/bar` is now public
83```
84
85#### <a name="restricted"></a> `> access.restricted(spec, [opts]) -> Promise`
86
87`spec` must be an [`npm-package-arg`](https://npm.im/npm-package-arg)-compatible
88registry spec.
89
90Makes package described by `spec` private/restricted.
91
92##### Example
93
94```javascript
95await access.restricted('@foo/bar', {token: 'myregistrytoken'})
96// `@foo/bar` is now private
97```
98
99#### <a name="grant"></a> `> access.grant(spec, team, permissions, [opts]) -> Promise`
100
101`spec` must be an [`npm-package-arg`](https://npm.im/npm-package-arg)-compatible
102registry spec. `team` must be a fully-qualified team name, in the `scope:team`
103format, with or without the `@` prefix, and the team must be a valid team within
104that scope. `permissions` must be one of `'read-only'` or `'read-write'`.
105
106Grants `read-only` or `read-write` permissions for a certain package to a team.
107
108##### Example
109
110```javascript
111await access.grant('@foo/bar', '@foo:myteam', 'read-write', {
112  token: 'myregistrytoken'
113})
114// `@foo/bar` is now read/write enabled for the @foo:myteam team.
115```
116
117#### <a name="revoke"></a> `> access.revoke(spec, team, [opts]) -> Promise`
118
119`spec` must be an [`npm-package-arg`](https://npm.im/npm-package-arg)-compatible
120registry spec. `team` must be a fully-qualified team name, in the `scope:team`
121format, with or without the `@` prefix, and the team must be a valid team within
122that scope. `permissions` must be one of `'read-only'` or `'read-write'`.
123
124Removes access to a package from a certain team.
125
126##### Example
127
128```javascript
129await access.revoke('@foo/bar', '@foo:myteam', {
130  token: 'myregistrytoken'
131})
132// @foo:myteam can no longer access `@foo/bar`
133```
134
135#### <a name="tfa-required"></a> `> access.tfaRequired(spec, [opts]) -> Promise`
136
137`spec` must be an [`npm-package-arg`](https://npm.im/npm-package-arg)-compatible
138registry spec.
139
140Makes it so publishing or managing a package requires using 2FA tokens to
141complete operations.
142
143##### Example
144
145```javascript
146await access.tfaRequires('lodash', {token: 'myregistrytoken'})
147// Publishing or changing dist-tags on `lodash` now require OTP to be enabled.
148```
149
150#### <a name="tfa-not-required"></a> `> access.tfaNotRequired(spec, [opts]) -> Promise`
151
152`spec` must be an [`npm-package-arg`](https://npm.im/npm-package-arg)-compatible
153registry spec.
154
155Disabled the package-level 2FA requirement for `spec`. Note that you will need
156to pass in an `otp` token in `opts` in order to complete this operation.
157
158##### Example
159
160```javascript
161await access.tfaNotRequired('lodash', {otp: '123654', token: 'myregistrytoken'})
162// Publishing or editing dist-tags on `lodash` no longer requires OTP to be
163// enabled.
164```
165
166#### <a name="ls-packages"></a> `> access.lsPackages(entity, [opts]) -> Promise`
167
168`entity` must be either a valid org or user name, or a fully-qualified team name
169in the `scope:team` format, with or without the `@` prefix.
170
171Lists out packages a user, org, or team has access to, with corresponding
172permissions. Packages that the access token does not have access to won't be
173listed.
174
175In order to disambiguate between users and orgs, two requests may end up being
176made when listing orgs or users.
177
178For a streamed version of these results, see
179[`access.lsPackages.stream()`](#ls-package-stream).
180
181##### Example
182
183```javascript
184await access.lsPackages('zkat', {
185  token: 'myregistrytoken'
186})
187// Lists all packages `@zkat` has access to on the registry, and the
188// corresponding permissions.
189```
190
191#### <a name="ls-packages-stream"></a> `> access.lsPackages.stream(scope, [team], [opts]) -> Stream`
192
193`entity` must be either a valid org or user name, or a fully-qualified team name
194in the `scope:team` format, with or without the `@` prefix.
195
196Streams out packages a user, org, or team has access to, with corresponding
197permissions, with each stream entry being formatted like `[packageName,
198permissions]`. Packages that the access token does not have access to won't be
199listed.
200
201In order to disambiguate between users and orgs, two requests may end up being
202made when listing orgs or users.
203
204The returned stream is a valid `asyncIterator`.
205
206##### Example
207
208```javascript
209for await (let [pkg, perm] of access.lsPackages.stream('zkat')) {
210  console.log('zkat has', perm, 'access to', pkg)
211}
212// zkat has read-write access to eggplant
213// zkat has read-only access to @npmcorp/secret
214```
215
216#### <a name="ls-collaborators"></a> `> access.lsCollaborators(spec, [user], [opts]) -> Promise`
217
218`spec` must be an [`npm-package-arg`](https://npm.im/npm-package-arg)-compatible
219registry spec. `user` must be a valid user name, with or without the `@`
220prefix.
221
222Lists out access privileges for a certain package. Will only show permissions
223for packages to which you have at least read access. If `user` is passed in, the
224list is filtered only to teams _that_ user happens to belong to.
225
226For a streamed version of these results, see [`access.lsCollaborators.stream()`](#ls-collaborators-stream).
227
228##### Example
229
230```javascript
231await access.lsCollaborators('@npm/foo', 'zkat', {
232  token: 'myregistrytoken'
233})
234// Lists all teams with access to @npm/foo that @zkat belongs to.
235```
236
237#### <a name="ls-collaborators-stream"></a> `> access.lsCollaborators.stream(spec, [user], [opts]) -> Stream`
238
239`spec` must be an [`npm-package-arg`](https://npm.im/npm-package-arg)-compatible
240registry spec. `user` must be a valid user name, with or without the `@`
241prefix.
242
243Stream out access privileges for a certain package, with each entry in `[user,
244permissions]` format. Will only show permissions for packages to which you have
245at least read access. If `user` is passed in, the list is filtered only to teams
246_that_ user happens to belong to.
247
248The returned stream is a valid `asyncIterator`.
249
250##### Example
251
252```javascript
253for await (let [usr, perm] of access.lsCollaborators.stream('npm')) {
254  console.log(usr, 'has', perm, 'access to npm')
255}
256// zkat has read-write access to npm
257// iarna has read-write access to npm
258```
259