npm-registry-fetch
Advanced tools
Comparing version 4.0.2 to 4.0.3
@@ -5,2 +5,13 @@ # Change Log | ||
<a name="4.0.3"></a> | ||
## [4.0.3](https://github.com/npm/registry-fetch/compare/v4.0.2...v4.0.3) (2020-02-13) | ||
### Bug Fixes | ||
* always bypass cache when ?write=true ([ba8b4fe](https://github.com/npm/registry-fetch/commit/ba8b4fe)) | ||
* use 30s default for timeout as per README ([69c2977](https://github.com/npm/registry-fetch/commit/69c2977)), closes [#20](https://github.com/npm/registry-fetch/issues/20) | ||
<a name="4.0.2"></a> | ||
@@ -7,0 +18,0 @@ ## [4.0.2](https://github.com/npm/registry-fetch/compare/v4.0.0...v4.0.2) (2019-10-04) |
@@ -78,3 +78,5 @@ 'use strict' | ||
'strict-ssl': {}, | ||
'timeout': {}, | ||
'timeout': { | ||
default: 30 * 1000 | ||
}, | ||
'user-agent': { | ||
@@ -81,0 +83,0 @@ default: `${ |
32
index.js
@@ -56,6 +56,9 @@ 'use strict' | ||
} | ||
if (opts.query) { | ||
let q = opts.query | ||
let q = opts.query | ||
if (q) { | ||
if (typeof q === 'string') { | ||
q = qs.parse(q) | ||
} else if (typeof q !== 'object') { | ||
throw new TypeError('invalid query option, must be string or object') | ||
} | ||
@@ -67,12 +70,21 @@ Object.keys(q).forEach(key => { | ||
}) | ||
if (Object.keys(q).length) { | ||
const parsed = url.parse(uri) | ||
parsed.search = '?' + qs.stringify( | ||
parsed.query | ||
? Object.assign(qs.parse(parsed.query), q) | ||
: q | ||
) | ||
uri = url.format(parsed) | ||
} | ||
const parsed = url.parse(uri) | ||
const query = parsed.query ? Object.assign(qs.parse(parsed.query), q || {}) | ||
: Object.keys(q || {}).length ? q | ||
: null | ||
if (query) { | ||
if (String(query.write) === 'true' && opts.method === 'GET') { | ||
opts = opts.concat({ | ||
offline: false, | ||
'prefer-offline': false, | ||
'prefer-online': true | ||
}) | ||
} | ||
parsed.search = '?' + qs.stringify(query) | ||
uri = url.format(parsed) | ||
} | ||
return opts.Promise.resolve(body).then(body => fetch(uri, { | ||
@@ -79,0 +91,0 @@ agent: opts.agent, |
{ | ||
"name": "npm-registry-fetch", | ||
"version": "4.0.2", | ||
"version": "4.0.3", | ||
"description": "Fetch-based http client for use with npm registry APIs", | ||
@@ -10,2 +10,5 @@ "main": "index.js", | ||
], | ||
"publishConfig": { | ||
"tag": "latest-v4" | ||
}, | ||
"scripts": { | ||
@@ -12,0 +15,0 @@ "prerelease": "npm t", |
@@ -53,2 +53,21 @@ # npm-registry-fetch [![npm version](https://img.shields.io/npm/v/npm-registry-fetch.svg)](https://npm.im/npm-registry-fetch) [![license](https://img.shields.io/npm/l/npm-registry-fetch.svg)](https://npm.im/npm-registry-fetch) [![Travis](https://img.shields.io/travis/npm/npm-registry-fetch/latest.svg)](https://travis-ci.org/npm/npm-registry-fetch) [![AppVeyor](https://img.shields.io/appveyor/ci/zkat/npm-registry-fetch/latest.svg)](https://ci.appveyor.com/project/npm/npm-registry-fetch) [![Coverage Status](https://coveralls.io/repos/github/npm/npm-registry-fetch/badge.svg?branch=latest)](https://coveralls.io/github/npm/npm-registry-fetch?branch=latest) | ||
#### Caching and `write=true` query strings | ||
Before performing any PUT or DELETE operation, npm clients first make a | ||
GET request to the registry resource being updated, which includes | ||
the query string `?write=true`. | ||
The semantics of this are, effectively, "I intend to write to this thing, | ||
and need to know the latest current value, so that my write can land | ||
cleanly". | ||
The public npm registry handles these `?write=true` requests by ensuring | ||
that the cache is re-validated before sending a response. In order to | ||
maintain the same behavior on the client, and not get tripped up by an | ||
overeager local cache when we intend to write data to the registry, any | ||
request that comes through `npm-registry-fetch` that contains `write=true` | ||
in the query string will forcibly set the `prefer-online` option to `true`, | ||
and set both `prefer-offline` and `offline` to false, so that any local | ||
cached value will be revalidated. | ||
#### <a name="fetch"></a> `> fetch(url, [opts]) -> Promise<Response>` | ||
@@ -395,2 +414,5 @@ | ||
This option is set to `true` when the request includes `write=true` in the | ||
query string. | ||
##### <a name="opts-otp"></a> `opts.otp` | ||
@@ -407,3 +429,3 @@ | ||
* Alias: _password | ||
* Alias: `_password` | ||
* Type: String | ||
@@ -438,2 +460,5 @@ * Default: null | ||
This option is set to `false` when the request includes `write=true` in the | ||
query string. | ||
##### <a name="opts-prefer-online"></a> `opts.prefer-online` | ||
@@ -450,2 +475,4 @@ | ||
This option is set to `true` when the request includes `write=true` in the | ||
query string. | ||
@@ -614,2 +641,2 @@ ##### <a name="opts-project-scope"></a> `opts.project-scope` | ||
** DEPRECATED ** This is a legacy authentication token supported only for | ||
*compatibility. Please use [`opts.token`](#opts-token) instead. | ||
compatibility. Please use [`opts.token`](#opts-token) instead. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45117
524
637
78
2
2
8