tangerine 1.4.0 → 1.4.1

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.
Files changed (2) hide show
  1. package/index.js +10 -10
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -455,7 +455,7 @@ class Tangerine extends dns.promises.Resolver {
455
455
 
456
456
  // if options is an integer, it must be 4 or 6
457
457
  if (typeof options === 'number') {
458
- if (options !== 4 && options !== 6) {
458
+ if (options !== 0 && options !== 4 && options !== 6) {
459
459
  const err = new TypeError(
460
460
  `The argument 'family' must be one of: 0, 4, 6. Received ${options}`
461
461
  );
@@ -479,6 +479,8 @@ class Tangerine extends dns.promises.Resolver {
479
479
  if (options?.family === 'IPv4') options.family = 4;
480
480
  else if (options?.family === 'IPv6') options.family = 6;
481
481
 
482
+ if (typeof options.family !== 'number') options.family = 0;
483
+
482
484
  // validate hints
483
485
  // eslint-disable-next-line no-bitwise
484
486
  if ((options?.hints & ~(dns.ADDRCONFIG | dns.ALL | dns.V4MAPPED)) !== 0) {
@@ -526,18 +528,16 @@ class Tangerine extends dns.promises.Resolver {
526
528
  let answers = [];
527
529
 
528
530
  try {
529
- // `any` or `all` is based off !options.family || options.family === 0
530
- // (according to official nodejs dns.lookup docs)
531
- answers = await Promise[
532
- typeof options.family === 'undefined' || options.family === 0
533
- ? 'all'
534
- : 'any'
535
- ]([
536
- // the only downside here is that if one succeeds the other won't be aborted (iff "any")
531
+ answers = await Promise.all([
537
532
  this.resolve4(name, { purgeCache, noThrowOnNODATA: true }),
538
533
  this.resolve6(name, { purgeCache, noThrowOnNODATA: true })
539
534
  ]);
540
- answers = answers.flat();
535
+ // default node behavior seems to return IPv4 by default always regardless
536
+ answers =
537
+ answers[0].length > 0 &&
538
+ (typeof options.family === 'undefined' || options.family === 0)
539
+ ? answers[0]
540
+ : answers.flat();
541
541
  } catch (_err) {
542
542
  debug(_err);
543
543
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tangerine",
3
3
  "description": "Tangerine is the best Node.js drop-in replacement for dns.promises.Resolver using DNS over HTTPS (\"DoH\") via undici with built-in retries, timeouts, smart server rotation, AbortControllers, and caching support for multiple backends (with TTL and purge support).",
4
- "version": "1.4.0",
4
+ "version": "1.4.1",
5
5
  "author": "Forward Email (https://forwardemail.net)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/forwardemail/tangerine/issues"