tough-cookie 5.0.0-rc.2 → 5.0.0-rc.4

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.
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.canonicalDomain = void 0;
4
- const punycode_js_1 = require("punycode/punycode.js");
3
+ exports.canonicalDomain = canonicalDomain;
5
4
  const constants_1 = require("./constants");
6
5
  /**
7
6
  * Transforms a domain name into a canonical domain name. The canonical domain name is a domain name
@@ -38,15 +37,21 @@ function canonicalDomain(domainName) {
38
37
  if (domainName == null) {
39
38
  return undefined;
40
39
  }
41
- let _str = domainName.trim().replace(/^\./, ''); // S4.1.2.3 & S5.2.3: ignore leading .
42
- if (constants_1.IP_V6_REGEX_OBJECT.test(_str)) {
43
- _str = _str.replace('[', '').replace(']', '');
40
+ let str = domainName.trim().replace(/^\./, ''); // S4.1.2.3 & S5.2.3: ignore leading .
41
+ if (constants_1.IP_V6_REGEX_OBJECT.test(str)) {
42
+ if (!str.startsWith('[')) {
43
+ str = '[' + str;
44
+ }
45
+ if (!str.endsWith(']')) {
46
+ str = str + ']';
47
+ }
48
+ return new URL(`http://${str}`).hostname.slice(1, -1); // remove [ and ]
44
49
  }
45
50
  // convert to IDN if any non-ASCII characters
46
51
  // eslint-disable-next-line no-control-regex
47
- if (/[^\u0001-\u007f]/.test(_str)) {
48
- _str = (0, punycode_js_1.toASCII)(_str);
52
+ if (/[^\u0001-\u007f]/.test(str)) {
53
+ return new URL(`http://${str}`).hostname;
49
54
  }
50
- return _str.toLowerCase();
55
+ // ASCII-only domain - not canonicalized with new URL() because it may be a malformed URL
56
+ return str.toLowerCase();
51
57
  }
52
- exports.canonicalDomain = canonicalDomain;
@@ -86,7 +86,6 @@ function trimTerminator(str) {
86
86
  }
87
87
  function parseCookiePair(cookiePair, looseMode) {
88
88
  cookiePair = trimTerminator(cookiePair);
89
- validators.validate(validators.isString(cookiePair), cookiePair);
90
89
  let firstEq = cookiePair.indexOf('=');
91
90
  if (looseMode) {
92
91
  if (firstEq === 0) {
@@ -390,7 +389,7 @@ class Cookie {
390
389
  // used to break creation ties in cookieCompare():
391
390
  Object.defineProperty(this, 'creationIndex', {
392
391
  configurable: false,
393
- enumerable: false,
392
+ enumerable: false, // important for assert.deepEqual checks
394
393
  writable: true,
395
394
  value: ++Cookie.cookiesCreated,
396
395
  });
@@ -1,31 +1,6 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.cookieCompare = void 0;
27
- const utils_1 = require("../utils");
28
- const validators = __importStar(require("../validators"));
3
+ exports.cookieCompare = cookieCompare;
29
4
  /**
30
5
  * The maximum timestamp a cookie, in milliseconds. The value is (2^31 - 1) seconds since the Unix
31
6
  * epoch, corresponding to 2038-01-19.
@@ -88,8 +63,6 @@ const MAX_TIME = 2147483647000;
88
63
  * @public
89
64
  */
90
65
  function cookieCompare(a, b) {
91
- validators.validate(validators.isObject(a), (0, utils_1.safeToString)(a));
92
- validators.validate(validators.isObject(b), (0, utils_1.safeToString)(b));
93
66
  let cmp;
94
67
  // descending for length: b CMP a
95
68
  const aPathLen = a.path ? a.path.length : 0;
@@ -109,4 +82,3 @@ function cookieCompare(a, b) {
109
82
  cmp = (a.creationIndex || 0) - (b.creationIndex || 0);
110
83
  return cmp;
111
84
  }
112
- exports.cookieCompare = cookieCompare;
@@ -22,12 +22,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
26
  exports.CookieJar = void 0;
30
- const url_parse_1 = __importDefault(require("url-parse"));
31
27
  const getPublicSuffix_1 = require("../getPublicSuffix");
32
28
  const validators = __importStar(require("../validators"));
33
29
  const validators_1 = require("../validators");
@@ -57,15 +53,26 @@ const defaultGetCookieOptions = {
57
53
  };
58
54
  const SAME_SITE_CONTEXT_VAL_ERR = 'Invalid sameSiteContext option for getCookies(); expected one of "strict", "lax", or "none"';
59
55
  function getCookieContext(url) {
60
- if (url instanceof URL) {
61
- return url;
56
+ if (url &&
57
+ typeof url === 'object' &&
58
+ 'hostname' in url &&
59
+ typeof url.hostname === 'string' &&
60
+ 'pathname' in url &&
61
+ typeof url.pathname === 'string' &&
62
+ 'protocol' in url &&
63
+ typeof url.protocol === 'string') {
64
+ return {
65
+ hostname: url.hostname,
66
+ pathname: url.pathname,
67
+ protocol: url.protocol,
68
+ };
62
69
  }
63
70
  else if (typeof url === 'string') {
64
71
  try {
65
- return (0, url_parse_1.default)(decodeURI(url));
72
+ return new URL(decodeURI(url));
66
73
  }
67
74
  catch {
68
- return (0, url_parse_1.default)(url);
75
+ return new URL(url);
69
76
  }
70
77
  }
71
78
  else {
@@ -73,7 +80,6 @@ function getCookieContext(url) {
73
80
  }
74
81
  }
75
82
  function checkSameSiteContext(value) {
76
- validators.validate(validators.isNonEmptyString(value), value);
77
83
  const context = String(value).toLowerCase();
78
84
  if (context === 'none' || context === 'lax' || context === 'strict') {
79
85
  return context;
@@ -90,7 +96,6 @@ function checkSameSiteContext(value) {
90
96
  * @returns boolean
91
97
  */
92
98
  function isSecurePrefixConditionMet(cookie) {
93
- validators.validate(validators.isObject(cookie), (0, utils_1.safeToString)(cookie));
94
99
  const startsWithSecurePrefix = typeof cookie.key === 'string' && cookie.key.startsWith('__Secure-');
95
100
  return !startsWithSecurePrefix || cookie.secure;
96
101
  }
@@ -106,7 +111,6 @@ function isSecurePrefixConditionMet(cookie) {
106
111
  * @returns boolean
107
112
  */
108
113
  function isHostPrefixConditionMet(cookie) {
109
- validators.validate(validators.isObject(cookie));
110
114
  const startsWithHostPrefix = typeof cookie.key === 'string' && cookie.key.startsWith('__Host-');
111
115
  return (!startsWithHostPrefix ||
112
116
  Boolean(cookie.secure &&
@@ -160,12 +164,15 @@ class CookieJar {
160
164
  }
161
165
  let syncErr = null;
162
166
  let syncResult = undefined;
163
- fn.call(this, (error, result) => {
164
- syncErr = error;
165
- syncResult = result;
166
- });
167
- // These seem to be false positives; it can't detect that the value may be changed in the callback
168
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/only-throw-error
167
+ try {
168
+ fn.call(this, (error, result) => {
169
+ syncErr = error;
170
+ syncResult = result;
171
+ });
172
+ }
173
+ catch (err) {
174
+ syncErr = err;
175
+ }
169
176
  if (syncErr)
170
177
  throw syncErr;
171
178
  return syncResult;
@@ -180,23 +187,28 @@ class CookieJar {
180
187
  }
181
188
  const promiseCallback = (0, utils_1.createPromiseCallback)(callback);
182
189
  const cb = promiseCallback.callback;
183
- if (typeof url === 'string') {
184
- validators.validate(validators.isNonEmptyString(url), callback, (0, utils_1.safeToString)(options));
185
- }
186
- const context = getCookieContext(url);
187
- let err;
188
- if (typeof url === 'function') {
189
- return promiseCallback.reject(new Error('No URL was specified'));
190
- }
191
- if (typeof options === 'function') {
192
- options = defaultSetCookieOptions;
190
+ let context;
191
+ try {
192
+ if (typeof url === 'string') {
193
+ validators.validate(validators.isNonEmptyString(url), callback, (0, utils_1.safeToString)(options));
194
+ }
195
+ context = getCookieContext(url);
196
+ if (typeof url === 'function') {
197
+ return promiseCallback.reject(new Error('No URL was specified'));
198
+ }
199
+ if (typeof options === 'function') {
200
+ options = defaultSetCookieOptions;
201
+ }
202
+ validators.validate(typeof cb === 'function', cb);
203
+ if (!validators.isNonEmptyString(cookie) &&
204
+ !validators.isObject(cookie) &&
205
+ cookie instanceof String &&
206
+ cookie.length == 0) {
207
+ return promiseCallback.resolve(undefined);
208
+ }
193
209
  }
194
- validators.validate(typeof cb === 'function', cb);
195
- if (!validators.isNonEmptyString(cookie) &&
196
- !validators.isObject(cookie) &&
197
- cookie instanceof String &&
198
- cookie.length == 0) {
199
- return promiseCallback.resolve(undefined);
210
+ catch (err) {
211
+ return promiseCallback.reject(err);
200
212
  }
201
213
  const host = (0, canonicalDomain_1.canonicalDomain)(context.hostname) ?? null;
202
214
  const loose = options?.loose || this.enableLooseMode;
@@ -211,7 +223,7 @@ class CookieJar {
211
223
  if (typeof cookie === 'string' || cookie instanceof String) {
212
224
  const parsedCookie = cookie_1.Cookie.parse(cookie.toString(), { loose: loose });
213
225
  if (!parsedCookie) {
214
- err = new Error('Cookie failed to parse');
226
+ const err = new Error('Cookie failed to parse');
215
227
  return options?.ignoreError
216
228
  ? promiseCallback.resolve(undefined)
217
229
  : promiseCallback.reject(err);
@@ -221,7 +233,7 @@ class CookieJar {
221
233
  else if (!(cookie instanceof cookie_1.Cookie)) {
222
234
  // If you're seeing this error, and are passing in a Cookie object,
223
235
  // it *might* be a Cookie object from another loaded version of tough-cookie.
224
- err = new Error('First argument to setCookie must be a Cookie object or string');
236
+ const err = new Error('First argument to setCookie must be a Cookie object or string');
225
237
  return options?.ignoreError
226
238
  ? promiseCallback.resolve(undefined)
227
239
  : promiseCallback.reject(err);
@@ -242,7 +254,7 @@ class CookieJar {
242
254
  : null;
243
255
  if (suffix == null && !constants_1.IP_V6_REGEX_OBJECT.test(cookie.domain)) {
244
256
  // e.g. "com"
245
- err = new Error('Cookie has domain set to a public suffix');
257
+ const err = new Error('Cookie has domain set to a public suffix');
246
258
  return options?.ignoreError
247
259
  ? promiseCallback.resolve(undefined)
248
260
  : promiseCallback.reject(err);
@@ -262,7 +274,7 @@ class CookieJar {
262
274
  // S5.3 step 6:
263
275
  if (cookie.domain) {
264
276
  if (!(0, domainMatch_1.domainMatch)(host ?? undefined, cookie.cdomain() ?? undefined, false)) {
265
- err = new Error(`Cookie not in this host's domain. Cookie:${cookie.cdomain() ?? 'null'} Request:${host ?? 'null'}`);
277
+ const err = new Error(`Cookie not in this host's domain. Cookie:${cookie.cdomain() ?? 'null'} Request:${host ?? 'null'}`);
266
278
  return options?.ignoreError
267
279
  ? promiseCallback.resolve(undefined)
268
280
  : promiseCallback.reject(err);
@@ -287,7 +299,7 @@ class CookieJar {
287
299
  // S5.3 step 9: NOOP; httpOnly attribute
288
300
  // S5.3 step 10
289
301
  if (options?.http === false && cookie.httpOnly) {
290
- err = new Error("Cookie is HttpOnly and this isn't an HTTP API");
302
+ const err = new Error("Cookie is HttpOnly and this isn't an HTTP API");
291
303
  return options.ignoreError
292
304
  ? promiseCallback.resolve(undefined)
293
305
  : promiseCallback.reject(err);
@@ -301,7 +313,7 @@ class CookieJar {
301
313
  // exact match for request-uri's host's registered domain, then
302
314
  // abort these steps and ignore the newly created cookie entirely."
303
315
  if (sameSiteContext === 'none') {
304
- err = new Error('Cookie is SameSite but this is a cross-origin request');
316
+ const err = new Error('Cookie is SameSite but this is a cross-origin request');
305
317
  return options?.ignoreError
306
318
  ? promiseCallback.resolve(undefined)
307
319
  : promiseCallback.reject(err);
@@ -432,12 +444,18 @@ class CookieJar {
432
444
  }
433
445
  const promiseCallback = (0, utils_1.createPromiseCallback)(callback);
434
446
  const cb = promiseCallback.callback;
435
- if (typeof url === 'string') {
436
- validators.validate(validators.isNonEmptyString(url), cb, url);
447
+ let context;
448
+ try {
449
+ if (typeof url === 'string') {
450
+ validators.validate(validators.isNonEmptyString(url), cb, url);
451
+ }
452
+ context = getCookieContext(url);
453
+ validators.validate(validators.isObject(options), cb, (0, utils_1.safeToString)(options));
454
+ validators.validate(typeof cb === 'function', cb);
455
+ }
456
+ catch (parameterError) {
457
+ return promiseCallback.reject(parameterError);
437
458
  }
438
- const context = getCookieContext(url);
439
- validators.validate(validators.isObject(options), cb, (0, utils_1.safeToString)(options));
440
- validators.validate(typeof cb === 'function', cb);
441
459
  const host = (0, canonicalDomain_1.canonicalDomain)(context.hostname);
442
460
  const path = context.pathname || '/';
443
461
  const secure = context.protocol &&
@@ -526,7 +544,7 @@ class CookieJar {
526
544
  }
527
545
  cookies = cookies.filter(matchingCookie);
528
546
  // sorting of S5.4 part 2
529
- if (options && 'sort' in options && options.sort !== false) {
547
+ if ('sort' in options && options.sort !== false) {
530
548
  cookies = cookies.sort(cookieCompare_1.cookieCompare);
531
549
  }
532
550
  // S5.4 part 3
@@ -632,8 +650,6 @@ class CookieJar {
632
650
  */
633
651
  serialize(callback) {
634
652
  const promiseCallback = (0, utils_1.createPromiseCallback)(callback);
635
- const cb = promiseCallback.callback;
636
- validators.validate(typeof cb === 'function', cb);
637
653
  let type = this.store.constructor.name;
638
654
  if (validators.isObject(type)) {
639
655
  type = null;
@@ -834,7 +850,7 @@ class CookieJar {
834
850
  removeErrors.push(removeErr);
835
851
  }
836
852
  completedCount++;
837
- if (completedCount === cookies?.length) {
853
+ if (completedCount === cookies.length) {
838
854
  if (removeErrors[0])
839
855
  cb(removeErrors[0]);
840
856
  else
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultPath = void 0;
3
+ exports.defaultPath = defaultPath;
4
4
  /**
5
5
  * Given a current request/response path, gives the path appropriate for storing
6
6
  * in a cookie. This is basically the "directory" of a "file" in the path, but
@@ -58,4 +58,3 @@ function defaultPath(path) {
58
58
  // but not including, the right-most %x2F ("/")."
59
59
  return path.slice(0, rightSlash);
60
60
  }
61
- exports.defaultPath = defaultPath;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.domainMatch = void 0;
3
+ exports.domainMatch = domainMatch;
4
4
  const canonicalDomain_1 = require("./canonicalDomain");
5
5
  // Dumped from ip-regex@4.0.0, with the following changes:
6
6
  // * all capturing groups converted to non-capturing -- "(?:)"
@@ -92,4 +92,3 @@ function domainMatch(domain, cookieDomain, canonicalize) {
92
92
  /* " * The string is a host name (i.e., not an IP address)." */
93
93
  return !IP_REGEX_LOWERCASE.test(_str);
94
94
  }
95
- exports.domainMatch = domainMatch;
@@ -1,31 +1,6 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.formatDate = void 0;
27
- const validators = __importStar(require("../validators"));
28
- const utils_1 = require("../utils");
3
+ exports.formatDate = formatDate;
29
4
  /**
30
5
  * Format a {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date | Date} into
31
6
  * the {@link https://www.rfc-editor.org/rfc/rfc2616#section-3.3.1 | preferred Internet standard format}
@@ -41,7 +16,5 @@ const utils_1 = require("../utils");
41
16
  * @public
42
17
  */
43
18
  function formatDate(date) {
44
- validators.validate(validators.isDate(date), (0, utils_1.safeToString)(date));
45
19
  return date.toUTCString();
46
20
  }
47
- exports.formatDate = formatDate;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fromJSON = exports.parse = exports.permutePath = exports.parseDate = exports.formatDate = exports.domainMatch = exports.defaultPath = exports.CookieJar = exports.cookieCompare = exports.Cookie = exports.PrefixSecurityEnum = exports.canonicalDomain = exports.version = exports.ParameterError = exports.Store = exports.getPublicSuffix = exports.permuteDomain = exports.pathMatch = exports.MemoryCookieStore = void 0;
3
+ exports.permutePath = exports.parseDate = exports.formatDate = exports.domainMatch = exports.defaultPath = exports.CookieJar = exports.cookieCompare = exports.Cookie = exports.PrefixSecurityEnum = exports.canonicalDomain = exports.version = exports.ParameterError = exports.Store = exports.getPublicSuffix = exports.permuteDomain = exports.pathMatch = exports.MemoryCookieStore = void 0;
4
+ exports.parse = parse;
5
+ exports.fromJSON = fromJSON;
4
6
  var memstore_1 = require("../memstore");
5
7
  Object.defineProperty(exports, "MemoryCookieStore", { enumerable: true, get: function () { return memstore_1.MemoryCookieStore; } });
6
8
  var pathMatch_1 = require("../pathMatch");
@@ -15,7 +17,6 @@ var validators_1 = require("../validators");
15
17
  Object.defineProperty(exports, "ParameterError", { enumerable: true, get: function () { return validators_1.ParameterError; } });
16
18
  var version_1 = require("../version");
17
19
  Object.defineProperty(exports, "version", { enumerable: true, get: function () { return version_1.version; } });
18
- var utils_1 = require("../utils");
19
20
  var canonicalDomain_1 = require("./canonicalDomain");
20
21
  Object.defineProperty(exports, "canonicalDomain", { enumerable: true, get: function () { return canonicalDomain_1.canonicalDomain; } });
21
22
  var constants_1 = require("./constants");
@@ -44,7 +45,6 @@ const cookie_2 = require("./cookie");
44
45
  function parse(str, options) {
45
46
  return cookie_2.Cookie.parse(str, options);
46
47
  }
47
- exports.parse = parse;
48
48
  /**
49
49
  * {@inheritDoc Cookie.fromJSON}
50
50
  * @public
@@ -52,4 +52,3 @@ exports.parse = parse;
52
52
  function fromJSON(str) {
53
53
  return cookie_2.Cookie.fromJSON(str);
54
54
  }
55
- exports.fromJSON = fromJSON;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // date-time parsing constants (RFC6265 S5.1.1)
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.parseDate = void 0;
4
+ exports.parseDate = parseDate;
5
5
  // eslint-disable-next-line no-control-regex
6
6
  const DATE_DELIM = /[\x09\x20-\x2F\x3B-\x40\x5B-\x60\x7B-\x7E]/;
7
7
  const MONTH_TO_NUM = {
@@ -321,4 +321,3 @@ function parseDate(cookieDate) {
321
321
  }
322
322
  return new Date(Date.UTC(year, month, dayOfMonth, hour, minute, second));
323
323
  }
324
- exports.parseDate = parseDate;
@@ -1,30 +1,6 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.permutePath = void 0;
27
- const validators = __importStar(require("../validators"));
3
+ exports.permutePath = permutePath;
28
4
  /**
29
5
  * Generates the permutation of all possible values that {@link pathMatch} the `path` parameter.
30
6
  * The array is in longest-to-shortest order. Useful when building custom {@link Store} implementations.
@@ -39,7 +15,6 @@ const validators = __importStar(require("../validators"));
39
15
  * @public
40
16
  */
41
17
  function permutePath(path) {
42
- validators.validate(validators.isString(path));
43
18
  if (path === '/') {
44
19
  return ['/'];
45
20
  }
@@ -55,4 +30,3 @@ function permutePath(path) {
55
30
  permutations.push('/');
56
31
  return permutations;
57
32
  }
58
- exports.permutePath = permutePath;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPublicSuffix = void 0;
3
+ exports.getPublicSuffix = getPublicSuffix;
4
4
  const tldts_1 = require("tldts");
5
5
  // RFC 6761
6
6
  const SPECIAL_USE_DOMAINS = ['local', 'example', 'invalid', 'localhost', 'test'];
@@ -69,4 +69,3 @@ function getPublicSuffix(domain, options = {}) {
69
69
  if (publicSuffix)
70
70
  return publicSuffix;
71
71
  }
72
- exports.getPublicSuffix = getPublicSuffix;
package/dist/pathMatch.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pathMatch = void 0;
3
+ exports.pathMatch = pathMatch;
4
4
  /**
5
5
  * Answers "does the request-path path-match a given cookie-path?" as per {@link https://www.rfc-editor.org/rfc/rfc6265.html#section-5.1.4 | RFC6265 Section 5.1.4}.
6
6
  * This is essentially a prefix-match where cookiePath is a prefix of reqPath.
@@ -39,4 +39,3 @@ function pathMatch(reqPath, cookiePath) {
39
39
  }
40
40
  return false;
41
41
  }
42
- exports.pathMatch = pathMatch;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.permuteDomain = void 0;
3
+ exports.permuteDomain = permuteDomain;
4
4
  const getPublicSuffix_1 = require("./getPublicSuffix");
5
5
  /**
6
6
  * Generates the permutation of all possible values that {@link domainMatch} the given `domain` parameter. The
@@ -42,4 +42,3 @@ function permuteDomain(domain, allowSpecialUseDomain) {
42
42
  }
43
43
  return permutations;
44
44
  }
45
- exports.permuteDomain = permuteDomain;
package/dist/utils.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.inOperator = exports.createPromiseCallback = exports.safeToString = exports.objectToString = void 0;
3
+ exports.safeToString = exports.objectToString = void 0;
4
+ exports.createPromiseCallback = createPromiseCallback;
5
+ exports.inOperator = inOperator;
4
6
  /** Wrapped `Object.prototype.toString`, so that you don't need to remember to use `.call()`. */
5
7
  const objectToString = (obj) => Object.prototype.toString.call(obj);
6
8
  exports.objectToString = objectToString;
@@ -17,13 +19,16 @@ const safeArrayToString = (arr, seenArrays) => {
17
19
  : safeToStringImpl(val, seenArrays));
18
20
  return mapped.join();
19
21
  };
20
- const safeToStringImpl = (val, seenArrays) => {
22
+ const safeToStringImpl = (val, seenArrays = new WeakSet()) => {
21
23
  // Using .toString() fails for null/undefined and implicit conversion (val + "") fails for symbols
22
24
  // and objects with null prototype
23
- if (val === undefined || val === null || typeof val.toString === 'function') {
25
+ if (typeof val !== 'object' || val === null) {
26
+ return String(val);
27
+ }
28
+ else if (typeof val.toString === 'function') {
24
29
  return Array.isArray(val)
25
30
  ? // Arrays have a weird custom toString that we need to replicate
26
- safeArrayToString(val, seenArrays ?? new WeakSet())
31
+ safeArrayToString(val, seenArrays)
27
32
  : String(val);
28
33
  }
29
34
  else {
@@ -85,8 +90,6 @@ function createPromiseCallback(cb) {
85
90
  },
86
91
  };
87
92
  }
88
- exports.createPromiseCallback = createPromiseCallback;
89
93
  function inOperator(k, o) {
90
94
  return k in o;
91
95
  }
92
- exports.inOperator = inOperator;
@@ -27,39 +27,40 @@ SOFTWARE.
27
27
 
28
28
  ************************************************************************************ */
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.ParameterError = exports.validate = exports.isInteger = exports.isObject = exports.isString = exports.isEmptyString = exports.isDate = exports.isNonEmptyString = void 0;
30
+ exports.ParameterError = void 0;
31
+ exports.isNonEmptyString = isNonEmptyString;
32
+ exports.isDate = isDate;
33
+ exports.isEmptyString = isEmptyString;
34
+ exports.isString = isString;
35
+ exports.isObject = isObject;
36
+ exports.isInteger = isInteger;
37
+ exports.validate = validate;
31
38
  const utils_1 = require("./utils");
32
39
  /* Validation functions copied from check-types package - https://www.npmjs.com/package/check-types */
33
40
  /** Determines whether the argument is a non-empty string. */
34
41
  function isNonEmptyString(data) {
35
42
  return isString(data) && data !== '';
36
43
  }
37
- exports.isNonEmptyString = isNonEmptyString;
38
44
  /** Determines whether the argument is a *valid* Date. */
39
45
  function isDate(data) {
40
46
  return data instanceof Date && isInteger(data.getTime());
41
47
  }
42
- exports.isDate = isDate;
43
48
  /** Determines whether the argument is the empty string. */
44
49
  function isEmptyString(data) {
45
50
  return data === '' || (data instanceof String && data.toString() === '');
46
51
  }
47
- exports.isEmptyString = isEmptyString;
48
52
  /** Determines whether the argument is a string. */
49
53
  function isString(data) {
50
54
  return typeof data === 'string' || data instanceof String;
51
55
  }
52
- exports.isString = isString;
53
56
  /** Determines whether the string representation of the argument is "[object Object]". */
54
57
  function isObject(data) {
55
58
  return (0, utils_1.objectToString)(data) === '[object Object]';
56
59
  }
57
- exports.isObject = isObject;
58
60
  /** Determines whether the argument is an integer. */
59
61
  function isInteger(data) {
60
62
  return typeof data === 'number' && data % 1 === 0;
61
63
  }
62
- exports.isInteger = isInteger;
63
64
  /* -- End validation functions -- */
64
65
  /**
65
66
  * When the first argument is false, an error is created with the given message. If a callback is
@@ -80,7 +81,6 @@ function validate(bool, cbOrMessage, message) {
80
81
  else
81
82
  throw err;
82
83
  }
83
- exports.validate = validate;
84
84
  /**
85
85
  * Represents a validation error.
86
86
  * @public
package/dist/version.js CHANGED
@@ -5,4 +5,4 @@ exports.version = void 0;
5
5
  * The version of `tough-cookie`
6
6
  * @public
7
7
  */
8
- exports.version = '5.0.0-rc.2';
8
+ exports.version = '5.0.0-rc.4';
package/package.json CHANGED
@@ -52,6 +52,14 @@
52
52
  {
53
53
  "name": "Sam Thompson",
54
54
  "website": "https://github.com/sambthompson"
55
+ },
56
+ {
57
+ "name": "Colin Casey",
58
+ "website": "https://github.com/colincasey"
59
+ },
60
+ {
61
+ "name": "Will Harney",
62
+ "website": "https://github.com/wjhsf"
55
63
  }
56
64
  ],
57
65
  "license": "BSD-3-Clause",
@@ -67,7 +75,7 @@
67
75
  "RFC6265",
68
76
  "RFC2965"
69
77
  ],
70
- "version": "5.0.0-rc.2",
78
+ "version": "5.0.0-rc.4",
71
79
  "homepage": "https://github.com/salesforce/tough-cookie",
72
80
  "repository": {
73
81
  "type": "git",
@@ -100,34 +108,31 @@
100
108
  "prettier": "prettier '**/*.{json,ts,yaml,md}'",
101
109
  "format": "npm run eslint -- --fix"
102
110
  },
111
+ "//": "We only support node 18+, but v16 still works. We won't block v16 until it becomes a burden.",
103
112
  "engines": {
104
113
  "node": ">=16"
105
114
  },
106
115
  "devDependencies": {
107
- "@eslint/js": "^8.57.0",
108
- "@microsoft/api-documenter": "^7.23.37",
109
- "@microsoft/api-extractor": "^7.42.3",
116
+ "@eslint/js": "^9.7.0",
117
+ "@microsoft/api-documenter": "^7.25.7",
118
+ "@microsoft/api-extractor": "^7.47.2",
110
119
  "@types/jest": "^29.5.12",
111
- "@types/node": "^14.18.63",
112
- "@types/punycode": "^2.1.4",
113
- "@types/url-parse": "^1.4.11",
120
+ "@types/node": "^16.18.101",
114
121
  "async": "3.2.5",
115
122
  "eslint": "^8.57.0",
116
123
  "eslint-config-prettier": "^9.1.0",
117
- "eslint-plugin-prettier": "^5.1.3",
124
+ "eslint-plugin-prettier": "^5.2.1",
118
125
  "genversion": "^3.2.0",
119
- "globals": "^14.0.0",
126
+ "globals": "^15.8.0",
120
127
  "jest": "^29.7.0",
121
- "prettier": "^3.2.5",
122
- "ts-jest": "^29.1.2",
128
+ "prettier": "^3.3.3",
129
+ "ts-jest": "^29.2.2",
123
130
  "ts-node": "^10.9.2",
124
- "typescript": "4.9.5",
125
- "typescript-eslint": "^7.3.1",
131
+ "typescript": "5.5.3",
132
+ "typescript-eslint": "^7.16.1",
126
133
  "vows": "^0.8.3"
127
134
  },
128
135
  "dependencies": {
129
- "punycode": "^2.3.1",
130
- "tldts": "^6.1.14",
131
- "url-parse": "^1.5.10"
136
+ "tldts": "^6.1.32"
132
137
  }
133
138
  }