tough-cookie 2.4.3 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -4
- package/lib/cookie.js +54 -3
- package/lib/memstore.js +5 -0
- package/lib/store.js +4 -0
- package/lib/version.js +2 -0
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -198,7 +198,7 @@ compute the TTL relative to `now` (milliseconds). The same precedence rules as
|
|
|
198
198
|
|
|
199
199
|
The "number" `Infinity` is returned for cookies without an explicit expiry and `0` is returned if the cookie is expired. Otherwise a time-to-live in milliseconds is returned.
|
|
200
200
|
|
|
201
|
-
### `.
|
|
201
|
+
### `.canonicalizedDomain()`
|
|
202
202
|
|
|
203
203
|
### `.cdomain()`
|
|
204
204
|
|
|
@@ -354,6 +354,16 @@ The `store` argument is optional, but must be a _synchronous_ `Store` instance i
|
|
|
354
354
|
|
|
355
355
|
The _source_ and _destination_ must both be synchronous `Store`s. If one or both stores are asynchronous, use `.clone` instead. Recall that `MemoryCookieStore` supports both synchronous and asynchronous API calls.
|
|
356
356
|
|
|
357
|
+
### `.removeAllCookies(cb(err))`
|
|
358
|
+
|
|
359
|
+
Removes all cookies from the jar.
|
|
360
|
+
|
|
361
|
+
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.
|
|
362
|
+
|
|
363
|
+
### `.removeAllCookiesSync()`
|
|
364
|
+
|
|
365
|
+
Sync version of `.removeAllCookies()`
|
|
366
|
+
|
|
357
367
|
## Store
|
|
358
368
|
|
|
359
369
|
Base class for CookieJar stores. Available as `tough.Store`.
|
|
@@ -418,19 +428,29 @@ Removes matching cookies from the store. The `path` parameter is optional, and
|
|
|
418
428
|
|
|
419
429
|
Pass an error ONLY if removing any existing cookies failed.
|
|
420
430
|
|
|
431
|
+
### `store.removeAllCookies(cb(err))`
|
|
432
|
+
|
|
433
|
+
_Optional_. Removes all cookies from the store.
|
|
434
|
+
|
|
435
|
+
Pass an error if one or more cookies can't be removed.
|
|
436
|
+
|
|
437
|
+
**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.
|
|
438
|
+
|
|
421
439
|
### `store.getAllCookies(cb(err, cookies))`
|
|
422
440
|
|
|
423
|
-
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.
|
|
441
|
+
_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.
|
|
424
442
|
|
|
425
443
|
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.
|
|
426
444
|
|
|
427
445
|
Pass an error if retrieval fails.
|
|
428
446
|
|
|
447
|
+
**Note**: not all Stores can implement this due to technical limitations, so it is optional.
|
|
448
|
+
|
|
429
449
|
## MemoryCookieStore
|
|
430
450
|
|
|
431
451
|
Inherits from `Store`.
|
|
432
452
|
|
|
433
|
-
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.
|
|
453
|
+
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`.
|
|
434
454
|
|
|
435
455
|
## Community Cookie Stores
|
|
436
456
|
|
|
@@ -473,7 +493,7 @@ These are some Store implementations authored and maintained by the community. T
|
|
|
473
493
|
|
|
474
494
|
# Copyright and License
|
|
475
495
|
|
|
476
|
-
|
|
496
|
+
BSD-3-Clause:
|
|
477
497
|
|
|
478
498
|
```text
|
|
479
499
|
Copyright (c) 2015, Salesforce.com, Inc.
|
package/lib/cookie.js
CHANGED
|
@@ -36,7 +36,7 @@ var pubsuffix = require('./pubsuffix-psl');
|
|
|
36
36
|
var Store = require('./store').Store;
|
|
37
37
|
var MemoryCookieStore = require('./memstore').MemoryCookieStore;
|
|
38
38
|
var pathMatch = require('./pathMatch').pathMatch;
|
|
39
|
-
var VERSION = require('
|
|
39
|
+
var VERSION = require('./version');
|
|
40
40
|
|
|
41
41
|
var punycode;
|
|
42
42
|
try {
|
|
@@ -1371,7 +1371,6 @@ CookieJar.deserializeSync = function(strOrObj, store) {
|
|
|
1371
1371
|
};
|
|
1372
1372
|
CookieJar.fromJSON = CookieJar.deserializeSync;
|
|
1373
1373
|
|
|
1374
|
-
CAN_BE_SYNC.push('clone');
|
|
1375
1374
|
CookieJar.prototype.clone = function(newStore, cb) {
|
|
1376
1375
|
if (arguments.length === 1) {
|
|
1377
1376
|
cb = newStore;
|
|
@@ -1382,10 +1381,61 @@ CookieJar.prototype.clone = function(newStore, cb) {
|
|
|
1382
1381
|
if (err) {
|
|
1383
1382
|
return cb(err);
|
|
1384
1383
|
}
|
|
1385
|
-
CookieJar.deserialize(
|
|
1384
|
+
CookieJar.deserialize(serialized, newStore, cb);
|
|
1386
1385
|
});
|
|
1387
1386
|
};
|
|
1388
1387
|
|
|
1388
|
+
CAN_BE_SYNC.push('removeAllCookies');
|
|
1389
|
+
CookieJar.prototype.removeAllCookies = function(cb) {
|
|
1390
|
+
var store = this.store;
|
|
1391
|
+
|
|
1392
|
+
// Check that the store implements its own removeAllCookies(). The default
|
|
1393
|
+
// implementation in Store will immediately call the callback with a "not
|
|
1394
|
+
// implemented" Error.
|
|
1395
|
+
if (store.removeAllCookies instanceof Function &&
|
|
1396
|
+
store.removeAllCookies !== Store.prototype.removeAllCookies)
|
|
1397
|
+
{
|
|
1398
|
+
return store.removeAllCookies(cb);
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
store.getAllCookies(function(err, cookies) {
|
|
1402
|
+
if (err) {
|
|
1403
|
+
return cb(err);
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
if (cookies.length === 0) {
|
|
1407
|
+
return cb(null);
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
var completedCount = 0;
|
|
1411
|
+
var removeErrors = [];
|
|
1412
|
+
|
|
1413
|
+
function removeCookieCb(removeErr) {
|
|
1414
|
+
if (removeErr) {
|
|
1415
|
+
removeErrors.push(removeErr);
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
completedCount++;
|
|
1419
|
+
|
|
1420
|
+
if (completedCount === cookies.length) {
|
|
1421
|
+
return cb(removeErrors.length ? removeErrors[0] : null);
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
cookies.forEach(function(cookie) {
|
|
1426
|
+
store.removeCookie(cookie.domain, cookie.path, cookie.key, removeCookieCb);
|
|
1427
|
+
});
|
|
1428
|
+
});
|
|
1429
|
+
};
|
|
1430
|
+
|
|
1431
|
+
CookieJar.prototype._cloneSync = syncWrap('clone');
|
|
1432
|
+
CookieJar.prototype.cloneSync = function(newStore) {
|
|
1433
|
+
if (!newStore.synchronous) {
|
|
1434
|
+
throw new Error('CookieJar clone destination store is not synchronous; use async API instead.');
|
|
1435
|
+
}
|
|
1436
|
+
return this._cloneSync(newStore);
|
|
1437
|
+
};
|
|
1438
|
+
|
|
1389
1439
|
// Use a closure to provide a true imperative API for synchronous stores.
|
|
1390
1440
|
function syncWrap(method) {
|
|
1391
1441
|
return function() {
|
|
@@ -1413,6 +1463,7 @@ CAN_BE_SYNC.forEach(function(method) {
|
|
|
1413
1463
|
CookieJar.prototype[method+'Sync'] = syncWrap(method);
|
|
1414
1464
|
});
|
|
1415
1465
|
|
|
1466
|
+
exports.version = VERSION;
|
|
1416
1467
|
exports.CookieJar = CookieJar;
|
|
1417
1468
|
exports.Cookie = Cookie;
|
|
1418
1469
|
exports.Store = Store;
|
package/lib/memstore.js
CHANGED
|
@@ -149,6 +149,11 @@ MemoryCookieStore.prototype.removeCookies = function(domain, path, cb) {
|
|
|
149
149
|
return cb(null);
|
|
150
150
|
};
|
|
151
151
|
|
|
152
|
+
MemoryCookieStore.prototype.removeAllCookies = function(cb) {
|
|
153
|
+
this.idx = {};
|
|
154
|
+
return cb(null);
|
|
155
|
+
}
|
|
156
|
+
|
|
152
157
|
MemoryCookieStore.prototype.getAllCookies = function(cb) {
|
|
153
158
|
var cookies = [];
|
|
154
159
|
var idx = this.idx;
|
package/lib/store.js
CHANGED
|
@@ -66,6 +66,10 @@ Store.prototype.removeCookies = function(domain, path, cb) {
|
|
|
66
66
|
throw new Error('removeCookies is not implemented');
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
+
Store.prototype.removeAllCookies = function(cb) {
|
|
70
|
+
throw new Error('removeAllCookies is not implemented');
|
|
71
|
+
}
|
|
72
|
+
|
|
69
73
|
Store.prototype.getAllCookies = function(cb) {
|
|
70
74
|
throw new Error('getAllCookies is not implemented (therefore jar cannot be serialized)');
|
|
71
75
|
};
|
package/lib/version.js
ADDED
package/package.json
CHANGED
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"RFC6265",
|
|
44
44
|
"RFC2965"
|
|
45
45
|
],
|
|
46
|
-
"version": "2.
|
|
46
|
+
"version": "2.5.0",
|
|
47
47
|
"homepage": "https://github.com/salesforce/tough-cookie",
|
|
48
48
|
"repository": {
|
|
49
49
|
"type": "git",
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"lib"
|
|
58
58
|
],
|
|
59
59
|
"scripts": {
|
|
60
|
+
"version": "genversion lib/version.js && git add lib/version.js",
|
|
60
61
|
"test": "vows test/*_test.js",
|
|
61
62
|
"cover": "nyc --reporter=lcov --reporter=html vows test/*_test.js"
|
|
62
63
|
},
|
|
@@ -65,12 +66,13 @@
|
|
|
65
66
|
},
|
|
66
67
|
"devDependencies": {
|
|
67
68
|
"async": "^1.4.2",
|
|
69
|
+
"genversion": "^2.1.0",
|
|
68
70
|
"nyc": "^11.6.0",
|
|
69
71
|
"string.prototype.repeat": "^0.2.0",
|
|
70
|
-
"vows": "^0.8.
|
|
72
|
+
"vows": "^0.8.2"
|
|
71
73
|
},
|
|
72
74
|
"dependencies": {
|
|
73
|
-
"psl": "^1.1.
|
|
74
|
-
"punycode": "^1.
|
|
75
|
+
"psl": "^1.1.28",
|
|
76
|
+
"punycode": "^2.1.1"
|
|
75
77
|
}
|
|
76
78
|
}
|