Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dns-over-http-resolver

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dns-over-http-resolver - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

10

CHANGELOG.md

@@ -0,1 +1,11 @@

<a name="1.1.0"></a>
# [1.1.0](https://github.com/vasco-santos/dns-over-http-resolver/compare/v1.0.0...v1.1.0) (2020-11-05)
### Features
* cache ([2a2aa61](https://github.com/vasco-santos/dns-over-http-resolver/commit/2a2aa61))
<a name="1.0.0"></a>

@@ -2,0 +12,0 @@ # 1.0.0 (2020-10-13)

2

dist/index.min.js

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.DnsOverHttpResolver=t():e.DnsOverHttpResolver=t()}(window,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=4)}([function(e,t,r){"use strict";var n=r(13),o="function"==typeof Symbol&&"symbol"==typeof Symbol("foo"),s=Object.prototype.toString,c=Array.prototype.concat,i=Object.defineProperty,u=i&&function(){var e={};try{for(var t in i(e,"x",{enumerable:!1,value:e}),e)return!1;return e.x===e}catch(r){return!1}}(),a=function(e,t,r,n){var o;(!(t in e)||"function"==typeof(o=n)&&"[object Function]"===s.call(o)&&n())&&(u?i(e,t,{configurable:!0,enumerable:!1,value:r,writable:!0}):e[t]=r)},l=function(e,t){var r=arguments.length>2?arguments[2]:{},s=n(t);o&&(s=c.call(s,Object.getOwnPropertySymbols(t)));for(var i=0;i<s.length;i+=1)a(e,s[i],t[s[i]],r[s[i]])};l.supportsDescriptors=!!u,e.exports=l},function(e,t,r){"use strict";var n=Object.prototype.toString;e.exports=function(e){var t=n.call(e),r="[object Arguments]"===t;return r||(r="[object Array]"!==t&&null!==e&&"object"==typeof e&&"number"==typeof e.length&&e.length>=0&&"[object Function]"===n.call(e.callee)),r}},function(e,t,r){"use strict";"undefined"!=typeof self?e.exports=self:"undefined"!=typeof window?e.exports=window:e.exports=Function("return this")()},function(e,t,r){"use strict";(function(t){var n=r(2);e.exports=function(){return"object"==typeof t&&t&&t.Math===Math&&t.Array===Array?t:n}}).call(this,r(15))},function(e,t,r){e.exports=r(5)},function(e,t,r){"use strict";const n=r(6),o=n("dns-over-http-resolver");o.error=n("dns-over-http-resolver:error");const{buildResource:s,fetch:c}=r(10);class i{constructor(){this._servers=["https://cloudflare-dns.com/dns-query","https://dns.google/resolve"]}getServers(){return this._servers}setServers(e){this._servers=e}resolve(e,t="A"){switch(t){case"A":return this.resolve4(e);case"AAAA":return this.resolve6(e);case"TXT":return this.resolveTxt(e);default:throw new Error(t+" is not supported")}}async resolve4(e){for(const r of this._servers)try{const t=await c(s({serverResolver:r,hostname:e,recordType:"A"}));return(await t.json()).Answer.map(e=>e.data)}catch(t){o.error(`${r} could not resolve ${e} record A`)}throw new Error(`Could not resolve ${e} record A`)}async resolve6(e){for(const r of this._servers)try{const t=await c(s({serverResolver:r,hostname:e,recordType:"AAAA"}));return(await t.json()).Answer.map(e=>e.data)}catch(t){o.error(`${r} could not resolve ${e} record AAAA`)}throw new Error(`Could not resolve ${e} record AAAA`)}async resolveTxt(e){for(const r of this._servers)try{const t=await c(s({serverResolver:r,hostname:e,recordType:"TXT"}));return(await t.json()).Answer.map(e=>[e.data.replace(/['"]+/g,"")])}catch(t){o.error(`${r} could not resolve ${e} record TXT`)}throw new Error(`Could not resolve ${e} record TXT`)}}i.Resolver=i,e.exports=i},function(e,t,r){"use strict";(function(n){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const r="color: "+this.color;t.splice(1,0,r,"color: inherit");let n=0,o=0;t[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(n++,"%c"===e&&(o=n))}),t.splice(o,0,r)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(r){}},t.load=function(){let e;try{e=t.storage.getItem("debug")}catch(r){}!e&&void 0!==n&&"env"in n&&(e={NODE_ENV:"production"}.DEBUG);return e},t.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage=function(){try{return localStorage}catch(e){}}(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=r(8)(t);const{formatters:o}=e.exports;o.j=function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}}).call(this,r(7))},function(e,t,r){"use strict";var n,o,s=e.exports={};function c(){throw new Error("setTimeout has not been defined")}function i(){throw new Error("clearTimeout has not been defined")}function u(e){if(n===setTimeout)return setTimeout(e,0);if((n===c||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:c}catch(e){n=c}try{o="function"==typeof clearTimeout?clearTimeout:i}catch(e){o=i}}();var a,l=[],f=!1,p=-1;function d(){f&&a&&(f=!1,a.length?l=a.concat(l):p=-1,l.length&&h())}function h(){if(!f){var e=u(d);f=!0;for(var t=l.length;t;){for(a=l,l=[];++p<t;)a&&a[p].run();p=-1,t=l.length}a=null,f=!1,function(e){if(o===clearTimeout)return clearTimeout(e);if((o===i||!o)&&clearTimeout)return o=clearTimeout,clearTimeout(e);try{o(e)}catch(t){try{return o.call(null,e)}catch(t){return o.call(this,e)}}}(e)}}function y(e,t){this.fun=e,this.array=t}function C(){}s.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];l.push(new y(e,t)),1!==l.length||f||u(h)},y.prototype.run=function(){this.fun.apply(null,this.array)},s.title="browser",s.browser=!0,s.env={},s.argv=[],s.version="",s.versions={},s.on=C,s.addListener=C,s.once=C,s.off=C,s.removeListener=C,s.removeAllListeners=C,s.emit=C,s.prependListener=C,s.prependOnceListener=C,s.listeners=function(e){return[]},s.binding=function(e){throw new Error("process.binding is not supported")},s.cwd=function(){return"/"},s.chdir=function(e){throw new Error("process.chdir is not supported")},s.umask=function(){return 0}},function(e,t,r){"use strict";e.exports=function(e){function t(e){let r;function s(...e){if(!s.enabled)return;const n=s,o=Number(new Date),c=o-(r||o);n.diff=c,n.prev=r,n.curr=o,r=o,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let i=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(r,o)=>{if("%%"===r)return r;i++;const s=t.formatters[o];if("function"==typeof s){const t=e[i];r=s.call(n,t),e.splice(i,1),i--}return r}),t.formatArgs.call(n,e);(n.log||t.log).apply(n,e)}return s.namespace=e,s.enabled=t.enabled(e),s.useColors=t.useColors(),s.color=t.selectColor(e),s.destroy=n,s.extend=o,"function"==typeof t.init&&t.init(s),t.instances.push(s),s}function n(){const e=t.instances.indexOf(this);return-1!==e&&(t.instances.splice(e,1),!0)}function o(e,r){const n=t(this.namespace+(void 0===r?":":r)+e);return n.log=this.log,n}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return t.debug=t,t.default=t,t.coerce=function(e){if(e instanceof Error)return e.stack||e.message;return e},t.disable=function(){const e=[...t.names.map(s),...t.skips.map(s).map(e=>"-"+e)].join(",");return t.enable(""),e},t.enable=function(e){let r;t.save(e),t.names=[],t.skips=[];const n=("string"==typeof e?e:"").split(/[\s,]+/),o=n.length;for(r=0;r<o;r++)n[r]&&("-"===(e=n[r].replace(/\*/g,".*?"))[0]?t.skips.push(new RegExp("^"+e.substr(1)+"$")):t.names.push(new RegExp("^"+e+"$")));for(r=0;r<t.instances.length;r++){const e=t.instances[r];e.enabled=t.enabled(e.namespace)}},t.enabled=function(e){if("*"===e[e.length-1])return!0;let r,n;for(r=0,n=t.skips.length;r<n;r++)if(t.skips[r].test(e))return!1;for(r=0,n=t.names.length;r<n;r++)if(t.names[r].test(e))return!0;return!1},t.humanize=r(9),Object.keys(e).forEach(r=>{t[r]=e[r]}),t.instances=[],t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let r=0;for(let t=0;t<e.length;t++)r=(r<<5)-r+e.charCodeAt(t),r|=0;return t.colors[Math.abs(r)%t.colors.length]},t.enable(t.load()),t}},function(e,t,r){"use strict";var n=1e3,o=6e4,s=60*o,c=24*s;function i(e,t,r,n){var o=t>=1.5*r;return Math.round(e/r)+" "+n+(o?"s":"")}e.exports=function(e,t){t=t||{};var r=typeof e;if("string"===r&&e.length>0)return function(e){if((e=String(e)).length>100)return;var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(!t)return;var r=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*r;case"weeks":case"week":case"w":return 6048e5*r;case"days":case"day":case"d":return r*c;case"hours":case"hour":case"hrs":case"hr":case"h":return r*s;case"minutes":case"minute":case"mins":case"min":case"m":return r*o;case"seconds":case"second":case"secs":case"sec":case"s":return r*n;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}(e);if("number"===r&&isFinite(e))return t.long?function(e){var t=Math.abs(e);if(t>=c)return i(e,t,c,"day");if(t>=s)return i(e,t,s,"hour");if(t>=o)return i(e,t,o,"minute");if(t>=n)return i(e,t,n,"second");return e+" ms"}(e):function(e){var t=Math.abs(e);if(t>=c)return Math.round(e/c)+"d";if(t>=s)return Math.round(e/s)+"h";if(t>=o)return Math.round(e/o)+"m";if(t>=n)return Math.round(e/n)+"s";return e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},function(e,t,r){"use strict";const{default:n,Headers:o}=r(11);e.exports.buildResource=function({serverResolver:e,hostname:t,recordType:r}){return`${e}?name=${t}&type=${r}`},e.exports.fetch=function(e){return n(e,{headers:new o({accept:"application/dns-json"})})}},function(e,t,r){"use strict";const n=r(12)();n.fetch&&n.Headers&&n.Request&&n.Response?(e.exports=function(...e){return n.fetch(...e)},e.exports.Headers=n.Headers,e.exports.Request=n.Request,e.exports.Response=n.Response,e.exports.default=e.exports):e.exports=r(17)},function(e,t,r){"use strict";var n=r(0),o=r(2),s=r(3),c=r(16),i=s(),u=function(){return i};n(u,{getPolyfill:s,implementation:o,shim:c}),e.exports=u},function(e,t,r){"use strict";var n=Array.prototype.slice,o=r(1),s=Object.keys,c=s?function(e){return s(e)}:r(14),i=Object.keys;c.shim=function(){Object.keys?function(){var e=Object.keys(arguments);return e&&e.length===arguments.length}(1,2)||(Object.keys=function(e){return o(e)?i(n.call(e)):i(e)}):Object.keys=c;return Object.keys||c},e.exports=c},function(e,t,r){"use strict";var n;if(!Object.keys){var o=Object.prototype.hasOwnProperty,s=Object.prototype.toString,c=r(1),i=Object.prototype.propertyIsEnumerable,u=!i.call({toString:null},"toString"),a=i.call((function(){}),"prototype"),l=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],f=function(e){var t=e.constructor;return t&&t.prototype===e},p={$applicationCache:!0,$console:!0,$external:!0,$frame:!0,$frameElement:!0,$frames:!0,$innerHeight:!0,$innerWidth:!0,$onmozfullscreenchange:!0,$onmozfullscreenerror:!0,$outerHeight:!0,$outerWidth:!0,$pageXOffset:!0,$pageYOffset:!0,$parent:!0,$scrollLeft:!0,$scrollTop:!0,$scrollX:!0,$scrollY:!0,$self:!0,$webkitIndexedDB:!0,$webkitStorageInfo:!0,$window:!0},d=function(){if("undefined"==typeof window)return!1;for(var e in window)try{if(!p["$"+e]&&o.call(window,e)&&null!==window[e]&&"object"==typeof window[e])try{f(window[e])}catch(t){return!0}}catch(t){return!0}return!1}();n=function(e){var t=null!==e&&"object"==typeof e,r="[object Function]"===s.call(e),n=c(e),i=t&&"[object String]"===s.call(e),p=[];if(!t&&!r&&!n)throw new TypeError("Object.keys called on a non-object");var h=a&&r;if(i&&e.length>0&&!o.call(e,0))for(var y=0;y<e.length;++y)p.push(String(y));if(n&&e.length>0)for(var C=0;C<e.length;++C)p.push(String(C));else for(var g in e)h&&"prototype"===g||!o.call(e,g)||p.push(String(g));if(u)for(var m=function(e){if("undefined"==typeof window||!d)return f(e);try{return f(e)}catch(t){return!1}}(e),v=0;v<l.length;++v)m&&"constructor"===l[v]||!o.call(e,l[v])||p.push(l[v]);return p}}e.exports=n},function(e,t,r){"use strict";var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(o){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,r){"use strict";var n=r(0),o=r(3);e.exports=function(){var e=o();if(n.supportsDescriptors){var t=Object.getOwnPropertyDescriptor(e,"globalThis");(!t||t.configurable&&(t.enumerable||t.writable||globalThis!==e))&&Object.defineProperty(e,"globalThis",{configurable:!0,enumerable:!1,value:e,writable:!1})}else"object"==typeof globalThis&&globalThis===e||(e.globalThis=e);return e}},function(e,t,r){"use strict";var n=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==n)return n;throw new Error("unable to locate global object")}();e.exports=t=n.fetch,n.fetch&&(t.default=n.fetch.bind(n)),t.Headers=n.Headers,t.Request=n.Request,t.Response=n.Response}])}));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.DnsOverHttpResolver=t():e.DnsOverHttpResolver=t()}(window,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=5)}([function(e,t,r){"use strict";var n=1e3,o=6e4,s=60*o,i=24*s;function c(e,t,r,n){var o=t>=1.5*r;return Math.round(e/r)+" "+n+(o?"s":"")}e.exports=function(e,t){t=t||{};var r=typeof e;if("string"===r&&e.length>0)return function(e){if((e=String(e)).length>100)return;var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(!t)return;var r=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*r;case"weeks":case"week":case"w":return 6048e5*r;case"days":case"day":case"d":return r*i;case"hours":case"hour":case"hrs":case"hr":case"h":return r*s;case"minutes":case"minute":case"mins":case"min":case"m":return r*o;case"seconds":case"second":case"secs":case"sec":case"s":return r*n;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}(e);if("number"===r&&isFinite(e))return t.long?function(e){var t=Math.abs(e);if(t>=i)return c(e,t,i,"day");if(t>=s)return c(e,t,s,"hour");if(t>=o)return c(e,t,o,"minute");if(t>=n)return c(e,t,n,"second");return e+" ms"}(e):function(e){var t=Math.abs(e);if(t>=i)return Math.round(e/i)+"d";if(t>=s)return Math.round(e/s)+"h";if(t>=o)return Math.round(e/o)+"m";if(t>=n)return Math.round(e/n)+"s";return e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},function(e,t,r){"use strict";var n=r(14),o="function"==typeof Symbol&&"symbol"==typeof Symbol("foo"),s=Object.prototype.toString,i=Array.prototype.concat,c=Object.defineProperty,u=c&&function(){var e={};try{for(var t in c(e,"x",{enumerable:!1,value:e}),e)return!1;return e.x===e}catch(r){return!1}}(),a=function(e,t,r,n){var o;(!(t in e)||"function"==typeof(o=n)&&"[object Function]"===s.call(o)&&n())&&(u?c(e,t,{configurable:!0,enumerable:!1,value:r,writable:!0}):e[t]=r)},l=function(e,t){var r=arguments.length>2?arguments[2]:{},s=n(t);o&&(s=i.call(s,Object.getOwnPropertySymbols(t)));for(var c=0;c<s.length;c+=1)a(e,s[c],t[s[c]],r[s[c]])};l.supportsDescriptors=!!u,e.exports=l},function(e,t,r){"use strict";var n=Object.prototype.toString;e.exports=function(e){var t=n.call(e),r="[object Arguments]"===t;return r||(r="[object Array]"!==t&&null!==e&&"object"==typeof e&&"number"==typeof e.length&&e.length>=0&&"[object Function]"===n.call(e.callee)),r}},function(e,t,r){"use strict";"undefined"!=typeof self?e.exports=self:"undefined"!=typeof window?e.exports=window:e.exports=Function("return this")()},function(e,t,r){"use strict";(function(t){var n=r(3);e.exports=function(){return"object"==typeof t&&t&&t.Math===Math&&t.Array===Array?t:n}}).call(this,r(16))},function(e,t,r){e.exports=r(6)},function(e,t,r){"use strict";const n=r(7),o=n("dns-over-http-resolver");o.error=n("dns-over-http-resolver:error");const s=r(10),{buildResource:i,fetch:c,getCacheKey:u}=r(11);class a{constructor({maxCache:e=100}={}){this._cache=new s({max:e}),this._servers=["https://cloudflare-dns.com/dns-query","https://dns.google/resolve"]}getServers(){return this._servers}setServers(e){this._servers=e}resolve(e,t="A"){switch(t){case"A":return this.resolve4(e);case"AAAA":return this.resolve6(e);case"TXT":return this.resolveTxt(e);default:throw new Error(t+" is not supported")}}async resolve4(e){const t=this._cache.get(u(e,"A"));if(t)return t;for(const n of this._servers)try{const t=await c(i({serverResolver:n,hostname:e,recordType:"A"})),r=await t.json(),o=r.Answer.map(e=>e.data),s=Math.min(r.Answer.map(e=>e.TTL));return this._cache.set(u(e,"A"),o,{ttl:s}),o}catch(r){o.error(`${n} could not resolve ${e} record A`)}throw new Error(`Could not resolve ${e} record A`)}async resolve6(e){const t=this._cache.get(u(e,"AAAA"));if(t)return t;for(const n of this._servers)try{const t=await c(i({serverResolver:n,hostname:e,recordType:"AAAA"})),r=await t.json(),o=r.Answer.map(e=>e.data),s=Math.min(r.Answer.map(e=>e.TTL));return this._cache.set(u(e,"AAAA"),o,{ttl:s}),o}catch(r){o.error(`${n} could not resolve ${e} record AAAA`)}throw new Error(`Could not resolve ${e} record AAAA`)}async resolveTxt(e){const t=this._cache.get(u(e,"TXT"));if(t)return t;for(const n of this._servers)try{const t=await c(i({serverResolver:n,hostname:e,recordType:"TXT"})),r=await t.json(),o=r.Answer.map(e=>[e.data.replace(/['"]+/g,"")]),s=Math.min(r.Answer.map(e=>e.TTL));return this._cache.set(u(e,"TXT"),o,{ttl:s}),o}catch(r){o.error(`${n} could not resolve ${e} record TXT`)}throw new Error(`Could not resolve ${e} record TXT`)}}a.Resolver=a,e.exports=a},function(e,t,r){"use strict";(function(n){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const r="color: "+this.color;t.splice(1,0,r,"color: inherit");let n=0,o=0;t[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(n++,"%c"===e&&(o=n))}),t.splice(o,0,r)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(r){}},t.load=function(){let e;try{e=t.storage.getItem("debug")}catch(r){}!e&&void 0!==n&&"env"in n&&(e={NODE_ENV:"production"}.DEBUG);return e},t.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage=function(){try{return localStorage}catch(e){}}(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=r(9)(t);const{formatters:o}=e.exports;o.j=function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}}).call(this,r(8))},function(e,t,r){"use strict";var n,o,s=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function c(){throw new Error("clearTimeout has not been defined")}function u(e){if(n===setTimeout)return setTimeout(e,0);if((n===i||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:i}catch(e){n=i}try{o="function"==typeof clearTimeout?clearTimeout:c}catch(e){o=c}}();var a,l=[],f=!1,h=-1;function p(){f&&a&&(f=!1,a.length?l=a.concat(l):h=-1,l.length&&d())}function d(){if(!f){var e=u(p);f=!0;for(var t=l.length;t;){for(a=l,l=[];++h<t;)a&&a[h].run();h=-1,t=l.length}a=null,f=!1,function(e){if(o===clearTimeout)return clearTimeout(e);if((o===c||!o)&&clearTimeout)return o=clearTimeout,clearTimeout(e);try{o(e)}catch(t){try{return o.call(null,e)}catch(t){return o.call(this,e)}}}(e)}}function m(e,t){this.fun=e,this.array=t}function y(){}s.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];l.push(new m(e,t)),1!==l.length||f||u(d)},m.prototype.run=function(){this.fun.apply(null,this.array)},s.title="browser",s.browser=!0,s.env={},s.argv=[],s.version="",s.versions={},s.on=y,s.addListener=y,s.once=y,s.off=y,s.removeListener=y,s.removeAllListeners=y,s.emit=y,s.prependListener=y,s.prependOnceListener=y,s.listeners=function(e){return[]},s.binding=function(e){throw new Error("process.binding is not supported")},s.cwd=function(){return"/"},s.chdir=function(e){throw new Error("process.chdir is not supported")},s.umask=function(){return 0}},function(e,t,r){"use strict";e.exports=function(e){function t(e){let r;function s(...e){if(!s.enabled)return;const n=s,o=Number(new Date),i=o-(r||o);n.diff=i,n.prev=r,n.curr=o,r=o,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let c=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(r,o)=>{if("%%"===r)return r;c++;const s=t.formatters[o];if("function"==typeof s){const t=e[c];r=s.call(n,t),e.splice(c,1),c--}return r}),t.formatArgs.call(n,e);(n.log||t.log).apply(n,e)}return s.namespace=e,s.enabled=t.enabled(e),s.useColors=t.useColors(),s.color=t.selectColor(e),s.destroy=n,s.extend=o,"function"==typeof t.init&&t.init(s),t.instances.push(s),s}function n(){const e=t.instances.indexOf(this);return-1!==e&&(t.instances.splice(e,1),!0)}function o(e,r){const n=t(this.namespace+(void 0===r?":":r)+e);return n.log=this.log,n}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return t.debug=t,t.default=t,t.coerce=function(e){if(e instanceof Error)return e.stack||e.message;return e},t.disable=function(){const e=[...t.names.map(s),...t.skips.map(s).map(e=>"-"+e)].join(",");return t.enable(""),e},t.enable=function(e){let r;t.save(e),t.names=[],t.skips=[];const n=("string"==typeof e?e:"").split(/[\s,]+/),o=n.length;for(r=0;r<o;r++)n[r]&&("-"===(e=n[r].replace(/\*/g,".*?"))[0]?t.skips.push(new RegExp("^"+e.substr(1)+"$")):t.names.push(new RegExp("^"+e+"$")));for(r=0;r<t.instances.length;r++){const e=t.instances[r];e.enabled=t.enabled(e.namespace)}},t.enabled=function(e){if("*"===e[e.length-1])return!0;let r,n;for(r=0,n=t.skips.length;r<n;r++)if(t.skips[r].test(e))return!1;for(r=0,n=t.names.length;r<n;r++)if(t.names[r].test(e))return!0;return!1},t.humanize=r(0),Object.keys(e).forEach(r=>{t[r]=e[r]}),t.instances=[],t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let r=0;for(let t=0;t<e.length;t++)r=(r<<5)-r+e.charCodeAt(t),r|=0;return t.colors[Math.abs(r)%t.colors.length]},t.enable(t.load()),t}},function(e,t,r){"use strict";e.exports=i;var n=r(0),o=i.prototype,s=new Date%1e9;function i(e){e=e||{},this.id=e.id||(1e9*Math.random()>>>0)+s++,this.max=e.max||1/0,this.items=e.items||[],this._lookup={},this.size=this.items.length,this.lastModified=new Date(e.lastModified||new Date);for(var t,r,n=this.items.length;n--;)t=this.items[n],r=new Date(t.expires)-new Date,this._lookup[t.key]=t,r>0?this.expire(t.key,r):r<=0&&this.delete(t.key)}o.has=function(e){return e in this._lookup},o.get=function(e){if(!this.has(e))return null;var t=this._lookup[e];return t.refresh&&this.expire(e,t.refresh),this.items.splice(this.items.indexOf(t),1),this.items.push(t),t.value},o.meta=function(e){if(!this.has(e))return null;var t=this._lookup[e];return"meta"in t?t.meta:null},o.set=function(e,t,r){var n=this._lookup[e],o=this._lookup[e]={key:e,value:t};return this.lastModified=new Date,n?(clearTimeout(n.timeout),this.items.splice(this.items.indexOf(n),1,o)):(this.size>=this.max&&this.delete(this.items[0].key),this.items.push(o),this.size++),r&&("ttl"in r&&this.expire(e,r.ttl),"meta"in r&&(o.meta=r.meta),r.refresh&&(o.refresh=r.ttl)),this},o.delete=function(e){var t=this._lookup[e];return!!t&&(this.lastModified=new Date,this.items.splice(this.items.indexOf(t),1),clearTimeout(t.timeout),delete this._lookup[e],this.size--,this)},o.expire=function(e,t){var r=t||0,o=this._lookup[e];if(!o)return this;if("string"==typeof r&&(r=n(t)),"number"!=typeof r)throw new TypeError("Expiration time must be a string or number.");return clearTimeout(o.timeout),o.timeout=setTimeout(this.delete.bind(this,o.key),r),o.expires=Number(new Date)+r,this},o.clear=function(){for(var e=this.items.length;e--;)this.delete(this.items[e].key);return this},o.toJSON=function(){for(var e,t=new Array(this.items.length),r=t.length;r--;)e=this.items[r],t[r]={key:e.key,meta:e.meta,value:e.value,expires:e.expires,refresh:e.refresh};return{id:this.id,max:isFinite(this.max)?this.max:void 0,lastModified:this.lastModified,items:t}}},function(e,t,r){"use strict";const{default:n,Headers:o}=r(12);e.exports.buildResource=function({serverResolver:e,hostname:t,recordType:r}){return`${e}?name=${t}&type=${r}`},e.exports.fetch=function(e){return n(e,{headers:new o({accept:"application/dns-json"})})},e.exports.getCacheKey=function(e,t){return`${t}_${e}`}},function(e,t,r){"use strict";const n=r(13)();n.fetch&&n.Headers&&n.Request&&n.Response?(e.exports=function(...e){return n.fetch(...e)},e.exports.Headers=n.Headers,e.exports.Request=n.Request,e.exports.Response=n.Response,e.exports.default=e.exports):e.exports=r(18)},function(e,t,r){"use strict";var n=r(1),o=r(3),s=r(4),i=r(17),c=s(),u=function(){return c};n(u,{getPolyfill:s,implementation:o,shim:i}),e.exports=u},function(e,t,r){"use strict";var n=Array.prototype.slice,o=r(2),s=Object.keys,i=s?function(e){return s(e)}:r(15),c=Object.keys;i.shim=function(){Object.keys?function(){var e=Object.keys(arguments);return e&&e.length===arguments.length}(1,2)||(Object.keys=function(e){return o(e)?c(n.call(e)):c(e)}):Object.keys=i;return Object.keys||i},e.exports=i},function(e,t,r){"use strict";var n;if(!Object.keys){var o=Object.prototype.hasOwnProperty,s=Object.prototype.toString,i=r(2),c=Object.prototype.propertyIsEnumerable,u=!c.call({toString:null},"toString"),a=c.call((function(){}),"prototype"),l=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],f=function(e){var t=e.constructor;return t&&t.prototype===e},h={$applicationCache:!0,$console:!0,$external:!0,$frame:!0,$frameElement:!0,$frames:!0,$innerHeight:!0,$innerWidth:!0,$onmozfullscreenchange:!0,$onmozfullscreenerror:!0,$outerHeight:!0,$outerWidth:!0,$pageXOffset:!0,$pageYOffset:!0,$parent:!0,$scrollLeft:!0,$scrollTop:!0,$scrollX:!0,$scrollY:!0,$self:!0,$webkitIndexedDB:!0,$webkitStorageInfo:!0,$window:!0},p=function(){if("undefined"==typeof window)return!1;for(var e in window)try{if(!h["$"+e]&&o.call(window,e)&&null!==window[e]&&"object"==typeof window[e])try{f(window[e])}catch(t){return!0}}catch(t){return!0}return!1}();n=function(e){var t=null!==e&&"object"==typeof e,r="[object Function]"===s.call(e),n=i(e),c=t&&"[object String]"===s.call(e),h=[];if(!t&&!r&&!n)throw new TypeError("Object.keys called on a non-object");var d=a&&r;if(c&&e.length>0&&!o.call(e,0))for(var m=0;m<e.length;++m)h.push(String(m));if(n&&e.length>0)for(var y=0;y<e.length;++y)h.push(String(y));else for(var g in e)d&&"prototype"===g||!o.call(e,g)||h.push(String(g));if(u)for(var C=function(e){if("undefined"==typeof window||!p)return f(e);try{return f(e)}catch(t){return!1}}(e),v=0;v<l.length;++v)C&&"constructor"===l[v]||!o.call(e,l[v])||h.push(l[v]);return h}}e.exports=n},function(e,t,r){"use strict";var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(o){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,r){"use strict";var n=r(1),o=r(4);e.exports=function(){var e=o();if(n.supportsDescriptors){var t=Object.getOwnPropertyDescriptor(e,"globalThis");(!t||t.configurable&&(t.enumerable||t.writable||globalThis!==e))&&Object.defineProperty(e,"globalThis",{configurable:!0,enumerable:!1,value:e,writable:!1})}else"object"==typeof globalThis&&globalThis===e||(e.globalThis=e);return e}},function(e,t,r){"use strict";var n=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==n)return n;throw new Error("unable to locate global object")}();e.exports=t=n.fetch,n.fetch&&(t.default=n.fetch.bind(n)),t.Headers=n.Headers,t.Request=n.Request,t.Response=n.Response}])}));
{
"name": "dns-over-http-resolver",
"version": "1.0.0",
"version": "1.1.0",
"description": "DNS over HTTP resolver",

@@ -42,3 +42,4 @@ "main": "src/index.js",

"debug": "^4.2.0",
"native-fetch": "^2.0.1"
"native-fetch": "^2.0.1",
"receptacle": "^1.3.2"
},

@@ -45,0 +46,0 @@ "contributors": [

@@ -23,8 +23,18 @@ # dns-over-http-resolver

const DnsOverHttpResolver = require('dns-over-http-resolver')
const dohResolver = new DnsOverHttpResolver(options)
```
[Cloudflare](https://cloudflare-dns.com/dns-query) and [Google](https://dns.google/resolve) DNS servers are used by default. They can be replaced via the API.
You can also use `require('dns').promises` in Node.js in lieu of this module.
[Cloudflare](https://cloudflare-dns.com/dns-query) and [Google](https://dns.google/resolve) DNS servers are used by default. They can be replaced via the API.
### options
You can provide the following options for the DnsOverHttpResolver:
| Name | Type | Description | Default |
|------|------|-------------|---------|
| maxCache | `number` | maximum number of cached dns records | 100 |
## API

@@ -31,0 +41,0 @@

@@ -6,4 +6,10 @@ 'use strict'

const { buildResource, fetch } = require('./utils')
const Receptacle = require('receptacle')
const {
buildResource,
fetch,
getCacheKey
} = require('./utils')
/**

@@ -16,4 +22,7 @@ * DNS over HTTP resolver.

* @class
* @param {object} [properties]
* @param {number} [properties.maxCache = 100] - maximum number of cached dns records.
*/
constructor () {
constructor ({ maxCache = 100 } = {}) {
this._cache = new Receptacle({ max: maxCache })
this._servers = [

@@ -71,2 +80,8 @@ 'https://cloudflare-dns.com/dns-query',

async resolve4 (hostname) {
const recordType = 'A'
const cached = this._cache.get(getCacheKey(hostname, recordType))
if (cached) {
return cached
}
for (const server of this._servers) {

@@ -77,13 +92,18 @@ try {

hostname,
recordType: 'A'
recordType
}))
const d = await response.json()
return d.Answer.map(a => a.data)
const data = d.Answer.map(a => a.data)
const ttl = Math.min(d.Answer.map(a => a.TTL))
this._cache.set(getCacheKey(hostname, recordType), data, { ttl })
return data
} catch (err) {
log.error(`${server} could not resolve ${hostname} record A`)
log.error(`${server} could not resolve ${hostname} record ${recordType}`)
}
}
throw new Error(`Could not resolve ${hostname} record A`)
throw new Error(`Could not resolve ${hostname} record ${recordType}`)
}

@@ -98,2 +118,8 @@

async resolve6 (hostname) {
const recordType = 'AAAA'
const cached = this._cache.get(getCacheKey(hostname, recordType))
if (cached) {
return cached
}
for (const server of this._servers) {

@@ -104,13 +130,18 @@ try {

hostname,
recordType: 'AAAA'
recordType
}))
const d = await response.json()
return d.Answer.map(a => a.data)
const data = d.Answer.map(a => a.data)
const ttl = Math.min(d.Answer.map(a => a.TTL))
this._cache.set(getCacheKey(hostname, recordType), data, { ttl })
return data
} catch (err) {
log.error(`${server} could not resolve ${hostname} record AAAA`)
log.error(`${server} could not resolve ${hostname} record ${recordType}`)
}
}
throw new Error(`Could not resolve ${hostname} record AAAA`)
throw new Error(`Could not resolve ${hostname} record ${recordType}`)
}

@@ -125,2 +156,8 @@

async resolveTxt (hostname) {
const recordType = 'TXT'
const cached = this._cache.get(getCacheKey(hostname, recordType))
if (cached) {
return cached
}
for (const server of this._servers) {

@@ -131,14 +168,18 @@ try {

hostname,
recordType: 'TXT'
recordType
}))
const d = await response.json()
const data = d.Answer.map(a => [a.data.replace(/['"]+/g, '')])
const ttl = Math.min(d.Answer.map(a => a.TTL))
return d.Answer.map(a => [a.data.replace(/['"]+/g, '')])
this._cache.set(getCacheKey(hostname, recordType), data, { ttl })
return data
} catch (err) {
log.error(`${server} could not resolve ${hostname} record TXT`)
log.error(`${server} could not resolve ${hostname} record ${recordType}`)
}
}
throw new Error(`Could not resolve ${hostname} record TXT`)
throw new Error(`Could not resolve ${hostname} record ${recordType}`)
}

@@ -145,0 +186,0 @@ }

@@ -20,2 +20,8 @@ 'use strict'

/**
* Use fetch to find the record.
*
* @param {object} resource
* @returns {Promise}
*/
function fetch (resource) {

@@ -30,1 +36,14 @@ return nativeFetch(resource, {

module.exports.fetch = fetch
/**
* Creates cache key composed by recordType and hostname.
*
* @param {string} hostname
* @param {string} recordType
* @returns {string}
*/
function getCacheKey (hostname, recordType) {
return `${recordType}_${hostname}`
}
module.exports.getCacheKey = getCacheKey
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc