tough-cookie
Advanced tools
Comparing version 2.4.3 to 2.5.0
@@ -39,3 +39,3 @@ /*! | ||
var pathMatch = require('./pathMatch').pathMatch; | ||
var VERSION = require('../package.json').version; | ||
var VERSION = require('./version'); | ||
@@ -1375,3 +1375,2 @@ var punycode; | ||
CAN_BE_SYNC.push('clone'); | ||
CookieJar.prototype.clone = function(newStore, cb) { | ||
@@ -1387,6 +1386,57 @@ if (arguments.length === 1) { | ||
} | ||
CookieJar.deserialize(newStore, serialized, cb); | ||
CookieJar.deserialize(serialized, newStore, cb); | ||
}); | ||
}; | ||
CAN_BE_SYNC.push('removeAllCookies'); | ||
CookieJar.prototype.removeAllCookies = function(cb) { | ||
var store = this.store; | ||
// Check that the store implements its own removeAllCookies(). The default | ||
// implementation in Store will immediately call the callback with a "not | ||
// implemented" Error. | ||
if (store.removeAllCookies instanceof Function && | ||
store.removeAllCookies !== Store.prototype.removeAllCookies) | ||
{ | ||
return store.removeAllCookies(cb); | ||
} | ||
store.getAllCookies(function(err, cookies) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
if (cookies.length === 0) { | ||
return cb(null); | ||
} | ||
var completedCount = 0; | ||
var removeErrors = []; | ||
function removeCookieCb(removeErr) { | ||
if (removeErr) { | ||
removeErrors.push(removeErr); | ||
} | ||
completedCount++; | ||
if (completedCount === cookies.length) { | ||
return cb(removeErrors.length ? removeErrors[0] : null); | ||
} | ||
} | ||
cookies.forEach(function(cookie) { | ||
store.removeCookie(cookie.domain, cookie.path, cookie.key, removeCookieCb); | ||
}); | ||
}); | ||
}; | ||
CookieJar.prototype._cloneSync = syncWrap('clone'); | ||
CookieJar.prototype.cloneSync = function(newStore) { | ||
if (!newStore.synchronous) { | ||
throw new Error('CookieJar clone destination store is not synchronous; use async API instead.'); | ||
} | ||
return this._cloneSync(newStore); | ||
}; | ||
// Use a closure to provide a true imperative API for synchronous stores. | ||
@@ -1419,2 +1469,3 @@ function syncWrap(method) { | ||
exports.version = VERSION; | ||
exports.CookieJar = CookieJar; | ||
@@ -1421,0 +1472,0 @@ exports.Cookie = Cookie; |
@@ -152,2 +152,7 @@ /*! | ||
MemoryCookieStore.prototype.removeAllCookies = function(cb) { | ||
this.idx = {}; | ||
return cb(null); | ||
} | ||
MemoryCookieStore.prototype.getAllCookies = function(cb) { | ||
@@ -154,0 +159,0 @@ var cookies = []; |
@@ -69,4 +69,8 @@ /*! | ||
Store.prototype.removeAllCookies = function(cb) { | ||
throw new Error('removeAllCookies is not implemented'); | ||
} | ||
Store.prototype.getAllCookies = function(cb) { | ||
throw new Error('getAllCookies is not implemented (therefore jar cannot be serialized)'); | ||
}; |
@@ -46,3 +46,3 @@ { | ||
], | ||
"version": "2.4.3", | ||
"version": "2.5.0", | ||
"homepage": "https://github.com/salesforce/tough-cookie", | ||
@@ -61,2 +61,3 @@ "repository": { | ||
"scripts": { | ||
"version": "genversion lib/version.js && git add lib/version.js", | ||
"test": "vows test/*_test.js", | ||
@@ -70,10 +71,11 @@ "cover": "nyc --reporter=lcov --reporter=html vows test/*_test.js" | ||
"async": "^1.4.2", | ||
"genversion": "^2.1.0", | ||
"nyc": "^11.6.0", | ||
"string.prototype.repeat": "^0.2.0", | ||
"vows": "^0.8.1" | ||
"vows": "^0.8.2" | ||
}, | ||
"dependencies": { | ||
"psl": "^1.1.24", | ||
"punycode": "^1.4.1" | ||
"psl": "^1.1.28", | ||
"punycode": "^2.1.1" | ||
} | ||
} |
@@ -201,3 +201,3 @@ [RFC6265](https://tools.ietf.org/html/rfc6265) Cookies and CookieJar for Node.js | ||
### `.canonicalizedDoman()` | ||
### `.canonicalizedDomain()` | ||
@@ -358,2 +358,12 @@ ### `.cdomain()` | ||
### `.removeAllCookies(cb(err))` | ||
Removes all cookies from the jar. | ||
This is a new backwards-compatible feature of `tough-cookie` version 2.5, so not all Stores will implement it efficiently. For Stores that do not implement `removeAllCookies`, the fallback is to call `removeCookie` after `getAllCookies`. If `getAllCookies` fails or isn't implemented in the Store, that error is returned. If one or more of the `removeCookie` calls fail, only the first error is returned. | ||
### `.removeAllCookiesSync()` | ||
Sync version of `.removeAllCookies()` | ||
## Store | ||
@@ -423,5 +433,13 @@ | ||
### `store.removeAllCookies(cb(err))` | ||
_Optional_. Removes all cookies from the store. | ||
Pass an error if one or more cookies can't be removed. | ||
**Note**: New method as of `tough-cookie` version 2.5, so not all Stores will implement this, plus some stores may choose not to implement this. | ||
### `store.getAllCookies(cb(err, cookies))` | ||
Produces an `Array` of all cookies during `jar.serialize()`. The items in the array can be true `Cookie` objects or generic `Object`s with the [Serialization Format] data structure. | ||
_Optional_. Produces an `Array` of all cookies during `jar.serialize()`. The items in the array can be true `Cookie` objects or generic `Object`s with the [Serialization Format] data structure. | ||
@@ -432,2 +450,4 @@ Cookies SHOULD be returned in creation order to preserve sorting via `compareCookies()`. For reference, `MemoryCookieStore` will sort by `.creationIndex` since it uses true `Cookie` objects internally. If you don't return the cookies in creation order, they'll still be sorted by creation time, but this only has a precision of 1ms. See `compareCookies` for more detail. | ||
**Note**: not all Stores can implement this due to technical limitations, so it is optional. | ||
## MemoryCookieStore | ||
@@ -437,3 +457,3 @@ | ||
A just-in-memory CookieJar synchronous store implementation, used by default. Despite being a synchronous implementation, it's usable with both the synchronous and asynchronous forms of the `CookieJar` API. | ||
A just-in-memory CookieJar synchronous store implementation, used by default. Despite being a synchronous implementation, it's usable with both the synchronous and asynchronous forms of the `CookieJar` API. Supports serialization, `getAllCookies`, and `removeAllCookies`. | ||
@@ -481,3 +501,3 @@ ## Community Cookie Stores | ||
(tl;dr: BSD-3-Clause with some MPL/2.0) | ||
BSD-3-Clause: | ||
@@ -484,0 +504,0 @@ ```text |
86644
10
1649
528
5
+ Addedpunycode@2.3.1(transitive)
- Removedpunycode@1.4.1(transitive)
Updatedpsl@^1.1.28
Updatedpunycode@^2.1.1