├── .github
├── settings.yml
└── workflows
│ └── ci.yml
├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── index.js
├── package-lock.json
├── package.json
└── test
├── fixtures
└── tnock.js
└── index.js
/.github/settings.yml:
--------------------------------------------------------------------------------
1 | ---
2 | _extends: '.github:npm-cli/settings.yml'
3 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | ---
2 | ################################################################################
3 | # Template - Node CI
4 | #
5 | # Description:
6 | # This contains the basic information to: install dependencies, run tests,
7 | # get coverage, and run linting on a nodejs project. This template will run
8 | # over the MxN matrix of all operating systems, and all current LTS versions
9 | # of NodeJS.
10 | #
11 | # Dependencies:
12 | # This template assumes that your project is using the `tap` module for
13 | # testing. If you're not using this module, then the step that runs your
14 | # coverage will need to be adjusted.
15 | #
16 | ################################################################################
17 | name: Node CI
18 |
19 | on: [push, pull_request]
20 |
21 | jobs:
22 | build:
23 | strategy:
24 | fail-fast: false
25 | matrix:
26 | node-version: [10.x, 12.x, 13.x]
27 | os: [ubuntu-latest, windows-latest, macOS-latest]
28 |
29 | runs-on: ${{ matrix.os }}
30 |
31 | steps:
32 | # Checkout the repository
33 | - uses: actions/checkout@v2
34 | # Installs the specific version of Node.js
35 | - name: Use Node.js ${{ matrix.node-version }}
36 | uses: actions/setup-node@v1
37 | with:
38 | node-version: ${{ matrix.node-version }}
39 |
40 | ################################################################################
41 | # Install Dependencies
42 | #
43 | # ASSUMPTIONS:
44 | # - The project has a package-lock.json file
45 | #
46 | # Simply run the tests for the project.
47 | ################################################################################
48 | - name: Install dependencies
49 | run: npm ci
50 |
51 | ################################################################################
52 | # Run Testing
53 | #
54 | # ASSUMPTIONS:
55 | # - The project has `tap` as a devDependency
56 | # - There is a script called "test" in the package.json
57 | #
58 | # Simply run the tests for the project.
59 | ################################################################################
60 | - name: Run tests
61 | run: npm test -- --no-coverage
62 |
63 | ################################################################################
64 | # Run coverage check
65 | #
66 | # ASSUMPTIONS:
67 | # - The project has `tap` as a devDependency
68 | # - There is a script called "coverage" in the package.json
69 | #
70 | # Coverage should only be posted once, we are choosing the latest LTS of
71 | # node, and ubuntu as the matrix point to post coverage from. We limit
72 | # to the 'push' event so that coverage ins't posted twice from the
73 | # pull-request event, and push event (line 3).
74 | ################################################################################
75 | - name: Run coverage report
76 | if: github.event_name == 'push' && matrix.node-version == '12.x' && matrix.os == 'ubuntu-latest'
77 | run: npm test
78 | env:
79 | # The environment variable name is leveraged by `tap`
80 | COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
81 |
82 | ################################################################################
83 | # Run linting
84 | #
85 | # ASSUMPTIONS:
86 | # - There is a script called "lint" in the package.json
87 | #
88 | # We run linting AFTER we run testing and coverage checks, because if a step
89 | # fails in an GitHub Action, all other steps are not run. We don't want to
90 | # fail to run tests or coverage because of linting. It should be the lowest
91 | # priority of all the steps.
92 | ################################################################################
93 | - name: Run linter
94 | run: npm run lint
95 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .nyc_output
3 | coverage/
4 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 |
4 | ## [4.0.0](https://github.com/npm/libnpmaccess/compare/v3.0.2...v4.0.0) (2020-03-02)
5 |
6 | ### BREAKING CHANGES
7 | - `25ac61b` fix: remove figgy-pudding ([@claudiahdz](https://github.com/claudiahdz))
8 | - `8d6f692` chore: rename opts.mapJson to opts.mapJSON ([@mikemimik](https://github.com/mikemimik))
9 |
10 | ### Features
11 | - `257879a` chore: removed standard-version as a dep; updated scripts for version/publishing ([@mikemimik](https://github.com/mikemimik))
12 | - `46c6740` fix: pull-request feedback; read full commit message ([@mikemimik](https://github.com/mikemimik))
13 | - `778c102` chore: updated test, made case more clear ([@mikemimik](https://github.com/mikemimik))
14 | - `6dc9852` fix: refactored 'pwrap' function out of code base; use native promises ([@mikemimik](https://github.com/mikemimik))
15 | - `d2e7219` chore: updated package scripts; update CI workflow ([@mikemimik](https://github.com/mikemimik))
16 | - `5872364` chore: renamed test/util/ to test/fixture/; tap will ignore now ([@mikemimik](https://github.com/mikemimik))
17 | - `3c6b71d` chore: linted test file; made tap usage 'better' ([@mikemimik](https://github.com/mikemimik))
18 | - `20f0858` fix: added default values to params for API functions (with tests) ([@mikemimik](https://github.com/mikemimik))
19 | - `3218289` feat: replace get-stream with minipass ([@mikemimik](https://github.com/mikemimik))
20 |
21 | ### Documentation
22 | - `6c8ffa0` docs: removed opts.Promise from docs; no longer in use ([@mikemimik](https://github.com/mikemimik))
23 | - `311bff5` chore: added return types to function docs in README ([@mikemimik](https://github.com/mikemimik))
24 | - `823726a` chore: removed travis badge, added github actions badge ([@mikemimik](https://github.com/mikemimik))
25 | - `80e80ac` chore: updated README ([@mikemimik](https://github.com/mikemimik))
26 |
27 | ### Dependencies
28 | - `baed2b9` deps: standard-version@7.1.0 (audit fix) ([@mikemimik](https://github.com/mikemimik))
29 | - `65c2204` deps: nock@12.0.1 (audit fix) ([@mikemimik](https://github.com/mikemimik))
30 | - `2668386` deps: npm-registry-fetch@8.0.0 ([@mikemimik](https://github.com/mikemimik))
31 | - `ef093e2` deps: tap@14.10.6 ([@mikemimik](https://github.com/mikemimik))
32 |
33 | ### Miscellanieous
34 | - `8e33902` chore: basic project updates ([@claudiahdz](https://github.com/claudiahdz))
35 | - `50e1433` fix: update return value; add tests ([@mikemimik](https://github.com/mikemimik))
36 | - `36d5c80` chore: updated gitignore; includes coverage folder ([@mikemimik](https://github.com/mikemimik))
37 |
38 | ---
39 |
40 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
41 |
42 |
43 | ## [3.0.2](https://github.com/npm/libnpmaccess/compare/v3.0.1...v3.0.2) (2019-07-16)
44 |
45 |
46 |
47 |
48 | ## [3.0.1](https://github.com/npm/libnpmaccess/compare/v3.0.0...v3.0.1) (2018-11-12)
49 |
50 |
51 | ### Bug Fixes
52 |
53 | * **ls-packages:** fix confusing splitEntity arg check ([1769090](https://github.com/npm/libnpmaccess/commit/1769090))
54 |
55 |
56 |
57 |
58 | # [3.0.0](https://github.com/npm/libnpmaccess/compare/v2.0.1...v3.0.0) (2018-08-24)
59 |
60 |
61 | ### Features
62 |
63 | * **api:** overhaul API ergonomics ([1faf00a](https://github.com/npm/libnpmaccess/commit/1faf00a))
64 |
65 |
66 | ### BREAKING CHANGES
67 |
68 | * **api:** all API calls where scope and team were separate, or
69 | where team was an extra, optional argument should now use a
70 | fully-qualified team name instead, in the `scope:team` format.
71 |
72 |
73 |
74 |
75 | ## [2.0.1](https://github.com/npm/libnpmaccess/compare/v2.0.0...v2.0.1) (2018-08-24)
76 |
77 |
78 |
79 |
80 | # [2.0.0](https://github.com/npm/libnpmaccess/compare/v1.2.2...v2.0.0) (2018-08-21)
81 |
82 |
83 | ### Bug Fixes
84 |
85 | * **json:** stop trying to parse response JSON ([20fdd84](https://github.com/npm/libnpmaccess/commit/20fdd84))
86 | * **lsPackages:** team URL was wrong D: ([b52201c](https://github.com/npm/libnpmaccess/commit/b52201c))
87 |
88 |
89 | ### BREAKING CHANGES
90 |
91 | * **json:** use cases where registries were returning JSON
92 | strings in the response body will no longer have an effect. All
93 | API functions except for lsPackages and lsCollaborators will return
94 | `true` on completion.
95 |
96 |
97 |
98 |
99 | ## [1.2.2](https://github.com/npm/libnpmaccess/compare/v1.2.1...v1.2.2) (2018-08-20)
100 |
101 |
102 | ### Bug Fixes
103 |
104 | * **docs:** tiny doc hiccup fix ([106396f](https://github.com/npm/libnpmaccess/commit/106396f))
105 |
106 |
107 |
108 |
109 | ## [1.2.1](https://github.com/npm/libnpmaccess/compare/v1.2.0...v1.2.1) (2018-08-20)
110 |
111 |
112 | ### Bug Fixes
113 |
114 | * **docs:** document the stream interfaces ([c435aa2](https://github.com/npm/libnpmaccess/commit/c435aa2))
115 |
116 |
117 |
118 |
119 | # [1.2.0](https://github.com/npm/libnpmaccess/compare/v1.1.0...v1.2.0) (2018-08-20)
120 |
121 |
122 | ### Bug Fixes
123 |
124 | * **readme:** fix up appveyor badge url ([42b45a1](https://github.com/npm/libnpmaccess/commit/42b45a1))
125 |
126 |
127 | ### Features
128 |
129 | * **streams:** add streaming result support for lsPkg and lsCollab ([0f06f46](https://github.com/npm/libnpmaccess/commit/0f06f46))
130 |
131 |
132 |
133 |
134 | # [1.1.0](https://github.com/npm/libnpmaccess/compare/v1.0.0...v1.1.0) (2018-08-17)
135 |
136 |
137 | ### Bug Fixes
138 |
139 | * **2fa:** escape package names correctly ([f2d83fe](https://github.com/npm/libnpmaccess/commit/f2d83fe))
140 | * **grant:** fix permissions validation ([07f7435](https://github.com/npm/libnpmaccess/commit/07f7435))
141 | * **ls-collaborators:** fix package name escaping + query ([3c02858](https://github.com/npm/libnpmaccess/commit/3c02858))
142 | * **ls-packages:** add query + fix fallback request order ([bdc4791](https://github.com/npm/libnpmaccess/commit/bdc4791))
143 | * **node6:** stop using Object.entries() ([4fec03c](https://github.com/npm/libnpmaccess/commit/4fec03c))
144 | * **public/restricted:** body should be string, not bool ([cffc727](https://github.com/npm/libnpmaccess/commit/cffc727))
145 | * **readme:** fix up title and badges ([2bd6113](https://github.com/npm/libnpmaccess/commit/2bd6113))
146 | * **specs:** require specs to be registry specs ([7892891](https://github.com/npm/libnpmaccess/commit/7892891))
147 |
148 |
149 | ### Features
150 |
151 | * **test:** add 100% coverage test suite ([22b5dec](https://github.com/npm/libnpmaccess/commit/22b5dec))
152 |
153 |
154 |
155 |
156 | # 1.0.0 (2018-08-17)
157 |
158 |
159 | ### Bug Fixes
160 |
161 | * **test:** -100 is apparently bad now ([a5ab879](https://github.com/npm/libnpmaccess/commit/a5ab879))
162 |
163 |
164 | ### Features
165 |
166 | * **impl:** initial implementation of api ([7039390](https://github.com/npm/libnpmaccess/commit/7039390))
167 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright npm, Inc
2 |
3 | Permission to use, copy, modify, and/or distribute this software for any
4 | purpose with or without fee is hereby granted, provided that the above
5 | copyright notice and this permission notice appear in all copies.
6 |
7 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # We've Moved! 🚚
2 | The code for this repo is now a workspace in the npm CLI repo.
3 |
4 | [github.com/npm/cli](https://github.com/npm/cli)
5 |
6 | You can find the workspace in /workspaces/libnpmaccess
7 |
8 | Please file bugs and feature requests as issues on the CLI and tag the issue with "ws:libnpmaccess".
9 |
10 | [github.com/npm/cli/issues](https://github.com/npm/cli)
11 |
12 | # libnpmaccess
13 |
14 | [](https://npm.im/libnpmaccess)
15 | [](https://npm.im/libnpmaccess)
16 | [](https://github.com/npm/libnpmaccess/actions?query=workflow%3A%22Node+CI%22)
17 | [](https://coveralls.io/github/npm/libnpmaccess?branch=latest)
18 |
19 | [`libnpmaccess`](https://github.com/npm/libnpmaccess) is a Node.js
20 | library that provides programmatic access to the guts of the npm CLI's `npm
21 | access` command and its various subcommands. This includes managing account 2FA,
22 | listing packages and permissions, looking at package collaborators, and defining
23 | package permissions for users, orgs, and teams.
24 |
25 | ## Example
26 |
27 | ```javascript
28 | const access = require('libnpmaccess')
29 |
30 | // List all packages @zkat has access to on the npm registry.
31 | console.log(Object.keys(await access.lsPackages('zkat')))
32 | ```
33 |
34 | ## Table of Contents
35 |
36 | * [Installing](#install)
37 | * [Example](#example)
38 | * [Contributing](#contributing)
39 | * [API](#api)
40 | * [access opts](#opts)
41 | * [`public()`](#public)
42 | * [`restricted()`](#restricted)
43 | * [`grant()`](#grant)
44 | * [`revoke()`](#revoke)
45 | * [`tfaRequired()`](#tfa-required)
46 | * [`tfaNotRequired()`](#tfa-not-required)
47 | * [`lsPackages()`](#ls-packages)
48 | * [`lsPackages.stream()`](#ls-packages-stream)
49 | * [`lsCollaborators()`](#ls-collaborators)
50 | * [`lsCollaborators.stream()`](#ls-collaborators-stream)
51 |
52 | ### Install
53 |
54 | `$ npm install libnpmaccess`
55 |
56 | ### API
57 |
58 | #### `opts` for `libnpmaccess` commands
59 |
60 | `libnpmaccess` uses [`npm-registry-fetch`](https://npm.im/npm-registry-fetch).
61 | All options are passed through directly to that library, so please refer to [its
62 | own `opts`
63 | documentation](https://www.npmjs.com/package/npm-registry-fetch#fetch-options)
64 | for options that can be passed in.
65 |
66 | A couple of options of note for those in a hurry:
67 |
68 | * `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.
69 | * `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>}`
70 |
71 | #### `> access.public(spec, [opts]) -> Promise`
72 |
73 | `spec` must be an [`npm-package-arg`](https://npm.im/npm-package-arg)-compatible
74 | registry spec.
75 |
76 | Makes package described by `spec` public.
77 |
78 | ##### Example
79 |
80 | ```javascript
81 | await access.public('@foo/bar', {token: 'myregistrytoken'})
82 | // `@foo/bar` is now public
83 | ```
84 |
85 | #### `> access.restricted(spec, [opts]) -> Promise`
86 |
87 | `spec` must be an [`npm-package-arg`](https://npm.im/npm-package-arg)-compatible
88 | registry spec.
89 |
90 | Makes package described by `spec` private/restricted.
91 |
92 | ##### Example
93 |
94 | ```javascript
95 | await access.restricted('@foo/bar', {token: 'myregistrytoken'})
96 | // `@foo/bar` is now private
97 | ```
98 |
99 | #### `> access.grant(spec, team, permissions, [opts]) -> Promise`
100 |
101 | `spec` must be an [`npm-package-arg`](https://npm.im/npm-package-arg)-compatible
102 | registry spec. `team` must be a fully-qualified team name, in the `scope:team`
103 | format, with or without the `@` prefix, and the team must be a valid team within
104 | that scope. `permissions` must be one of `'read-only'` or `'read-write'`.
105 |
106 | Grants `read-only` or `read-write` permissions for a certain package to a team.
107 |
108 | ##### Example
109 |
110 | ```javascript
111 | await 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 | #### `> access.revoke(spec, team, [opts]) -> Promise`
118 |
119 | `spec` must be an [`npm-package-arg`](https://npm.im/npm-package-arg)-compatible
120 | registry spec. `team` must be a fully-qualified team name, in the `scope:team`
121 | format, with or without the `@` prefix, and the team must be a valid team within
122 | that scope. `permissions` must be one of `'read-only'` or `'read-write'`.
123 |
124 | Removes access to a package from a certain team.
125 |
126 | ##### Example
127 |
128 | ```javascript
129 | await access.revoke('@foo/bar', '@foo:myteam', {
130 | token: 'myregistrytoken'
131 | })
132 | // @foo:myteam can no longer access `@foo/bar`
133 | ```
134 |
135 | #### `> access.tfaRequired(spec, [opts]) -> Promise`
136 |
137 | `spec` must be an [`npm-package-arg`](https://npm.im/npm-package-arg)-compatible
138 | registry spec.
139 |
140 | Makes it so publishing or managing a package requires using 2FA tokens to
141 | complete operations.
142 |
143 | ##### Example
144 |
145 | ```javascript
146 | await access.tfaRequires('lodash', {token: 'myregistrytoken'})
147 | // Publishing or changing dist-tags on `lodash` now require OTP to be enabled.
148 | ```
149 |
150 | #### `> access.tfaNotRequired(spec, [opts]) -> Promise`
151 |
152 | `spec` must be an [`npm-package-arg`](https://npm.im/npm-package-arg)-compatible
153 | registry spec.
154 |
155 | Disabled the package-level 2FA requirement for `spec`. Note that you will need
156 | to pass in an `otp` token in `opts` in order to complete this operation.
157 |
158 | ##### Example
159 |
160 | ```javascript
161 | await 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 | #### `> access.lsPackages(entity, [opts]) -> Promise