The npm registry (api) isn’t documented very well.
You can find some docs in npm/registry
, but most of it can be best
perused by reading code, such as libnpmaccess
.
…or read this document.
First, make sure to set npm to use 2fa for auth-only. Proper 2fa doesn’t work well as you’d have to fill in OTPs all the time.
npm profile enable-2fa auth-only
Then, create an npm token:
npm token create
Store that somewhere in a dotenv.
org=remarkjs
curl "https://registry.npmjs.org/-/org/$org/team" \
-H "Authorization: Bearer $token"
# ["remarkjs:developers","remarkjs:foo"]
org=remarkjs
curl "https://registry.npmjs.org/-/org/$org/package"
# {"remark":"write",…"remark-external-links":"write"}
Only users the token can see are shown.
org=remarkjs
curl "https://registry.npmjs.org/-/org/$org/user" \
-H "Authorization: Bearer $token"
# {"wooorm":"owner",…"murderlon":"admin"}
org=remarkjs
user="wooorm"
role="owner" # "developer", "owner", or "admin"
# See https://docs.npmjs.com/org-roles-and-permissions.
curl "https://registry.npmjs.org/-/org/$org/user" \
-X PUT \
-H "Authorization: Bearer $token" \
-H "Content-Type: application/json" \
-d "{\"user\": \"$user\", \"role\": \"$role\"}"
# {"org":{"name":"remarkjs","size":5},"user":"wooorm","role":"owner"}
org=remarkjs
user="wooorm"
curl "https://registry.npmjs.org/-/org/$org/user" \
-X DELETE \
-H "Authorization: Bearer $token" \
-H "Content-Type: application/json" \
-d "{\"user\": \"$user\"}"
org=remarkjs
team=bar
description=bravo
curl "https://registry.npmjs.org/-/org/$org/team" \
-X PUT \
-H "Authorization: Bearer $token" \
-H "Content-Type: application/json" \
-d "{\"name\": \"$team\",\"description\": \"$description\"}"
# {"name":"bar"}
org=remarkjs
team=developers
curl "https://registry.npmjs.org/-/team/$org/$team/user" \
-H "Authorization: Bearer $token"
# ["wooorm",…]
org=remarkjs
team=foo
user=wooorm
curl "https://registry.npmjs.org/-/team/$org/$team/user" \
-X PUT \
-H "Authorization: Bearer $token" \
-H "Content-Type: application/json" \
-d "{\"user\":\"$user\"}"
# {}
org=remarkjs
team=foo
user=johno
curl "https://registry.npmjs.org/-/team/$org/$team/user" \
-X DELETE \
-H "Authorization: Bearer $token" \
-H "Content-Type: application/json" \
-d "{\"user\":\"$user\"}"
# empty
org=remarkjs
team=developers
curl "https://registry.npmjs.org/-/team/$org/$team/package" \
-H "Authorization: Bearer $token"
# {"remark":"write",…"remark-external-links":"write"}
org=remarkjs
team=foo
package=remark-parse
permissions="read-write" # "read-only" or "read-write"
curl "https://registry.npmjs.org/-/team/$org/$team/package" \
-X PUT \
-H "Authorization: Bearer $token" \
-H "Content-Type: application/json" \
-d "{\"package\": \"$package\", \"permissions\": \"$permissions\"}"
# {}
org=remarkjs
team=foo
package=remark-parse
curl "https://registry.npmjs.org/-/team/$org/$team/package" \
-X DELETE \
-H "Authorization: Bearer $token" \
-H "Content-Type: application/json" \
-d "{\"package\": \"$package\"}"
# empty response
package=remark-parse # Use "@foo%2bar" for scoped packages
curl "https://registry.npmjs.org/$package" \
-H "Accept: application/vnd.npm.install-v1+json" # Remove for full metadata.
# {"_id":"remark-parse","_rev":"35-c4b211558296c2be5fad20fd0a7b3b25","name":"remark-parse","maintainers":[…],…}
This can be used to find maintainers
.
package=remark-parse
curl "https://registry.npmjs.org/-/package/$package/collaborators" \
-H "Authorization: Bearer $token"
# {"wooorm":"write",…}
package=remark-parse
rev=10-4193cf2ba92283e3e8fd605d75108054
curl "https://registry.npmjs.org/$package/-rev/$rev" \
-X PUT \
-H "Authorization: Bearer $token" \
-H "Content-Type: application/json" \
-d "{
\"_id\": \"$package\",
\"_rev\": \"$rev\",
\"maintainers\": [
{\"email\":\"[email protected]\",\"name\":\"vweevers\"},
{\"email\":\"[email protected]\",\"name\":\"wooorm\"}
]
}" \
--verbose
package=remark-parse
tfa=true # true or false
curl "https://registry.npmjs.org/-/package/$package/access" \
-X POST \
-H "Authorization: Bearer $token" \
-H "Content-Type: application/json" \
-d "{\"publish_requires_tfa\": $tfa}"
# empty
curl "https://registry.npmjs.org/-/npm/v1/user" \
-H "Authorization: Bearer $token"
# {"tfa":{"pending":false,…"fullname":"Titus Wormer",…"twitter":"wooorm","github":"wooorm"}
user=wooorm
curl "https://registry.npmjs.org/-/user/org.couchdb.user:$user"
# {"_id":"org.couchdb.user:wooorm","email":"[email protected]","name":"wooorm"}
user=wooorm
curl "https://registry.npmjs.org/-/user/$user/package"
# {"retext-latin":"write",…"remark-bookmarks":"write"}