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
2
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 3.0.2 to 3.0.3

2

dist/index.min.js
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.DnsOverHttpResolver = factory()}(typeof self !== 'undefined' ? self : this, function () {
"use strict";var DnsOverHttpResolver=(()=>{var V=Object.create;var E=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.getPrototypeOf,re=Object.prototype.hasOwnProperty;var T=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),se=(r,t)=>{for(var e in t)E(r,e,{get:t[e],enumerable:!0})},R=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of ee(t))!re.call(r,i)&&i!==e&&E(r,i,{get:()=>t[i],enumerable:!(n=Y(t,i))||n.enumerable});return r};var z=(r,t,e)=>(e=r!=null?V(te(r)):{},R(t||!r||!r.__esModule?E(e,"default",{value:r,enumerable:!0}):e,r)),ne=r=>R(E({},"__esModule",{value:!0}),r);var L=T((Ae,K)=>{var b=1e3,v=b*60,F=v*60,w=F*24,oe=w*7,ie=w*365.25;K.exports=function(r,t){t=t||{};var e=typeof r;if(e==="string"&&r.length>0)return ae(r);if(e==="number"&&isFinite(r))return t.long?le(r):ce(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function ae(r){if(r=String(r),!(r.length>100)){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(r);if(t){var e=parseFloat(t[1]),n=(t[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return e*ie;case"weeks":case"week":case"w":return e*oe;case"days":case"day":case"d":return e*w;case"hours":case"hour":case"hrs":case"hr":case"h":return e*F;case"minutes":case"minute":case"mins":case"min":case"m":return e*v;case"seconds":case"second":case"secs":case"sec":case"s":return e*b;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return e;default:return}}}}function ce(r){var t=Math.abs(r);return t>=w?Math.round(r/w)+"d":t>=F?Math.round(r/F)+"h":t>=v?Math.round(r/v)+"m":t>=b?Math.round(r/b)+"s":r+"ms"}function le(r){var t=Math.abs(r);return t>=w?$(r,t,w,"day"):t>=F?$(r,t,F,"hour"):t>=v?$(r,t,v,"minute"):t>=b?$(r,t,b,"second"):r+" ms"}function $(r,t,e,n){var i=t>=e*1.5;return Math.round(r/e)+" "+n+(i?"s":"")}});var J=T((Ee,X)=>{function ue(r){e.debug=e,e.default=e,e.coerce=d,e.disable=f,e.enable=i,e.enabled=l,e.humanize=L(),e.destroy=m,Object.keys(r).forEach(s=>{e[s]=r[s]}),e.names=[],e.skips=[],e.formatters={};function t(s){let o=0;for(let c=0;c<s.length;c++)o=(o<<5)-o+s.charCodeAt(c),o|=0;return e.colors[Math.abs(o)%e.colors.length]}e.selectColor=t;function e(s){let o,c=null,_,N;function C(...h){if(!C.enabled)return;let g=C,x=Number(new Date),H=x-(o||x);g.diff=H,g.prev=o,g.curr=x,o=x,h[0]=e.coerce(h[0]),typeof h[0]!="string"&&h.unshift("%O");let A=0;h[0]=h[0].replace(/%([a-zA-Z%])/g,(S,W)=>{if(S==="%%")return"%";A++;let I=e.formatters[W];if(typeof I=="function"){let Q=h[A];S=I.call(g,Q),h.splice(A,1),A--}return S}),e.formatArgs.call(g,h),(g.log||e.log).apply(g,h)}return C.namespace=s,C.useColors=e.useColors(),C.color=e.selectColor(s),C.extend=n,C.destroy=e.destroy,Object.defineProperty(C,"enabled",{enumerable:!0,configurable:!1,get:()=>c!==null?c:(_!==e.namespaces&&(_=e.namespaces,N=e.enabled(s)),N),set:h=>{c=h}}),typeof e.init=="function"&&e.init(C),C}function n(s,o){let c=e(this.namespace+(typeof o>"u"?":":o)+s);return c.log=this.log,c}function i(s){e.save(s),e.namespaces=s,e.names=[],e.skips=[];let o,c=(typeof s=="string"?s:"").split(/[\s,]+/),_=c.length;for(o=0;o<_;o++)c[o]&&(s=c[o].replace(/\*/g,".*?"),s[0]==="-"?e.skips.push(new RegExp("^"+s.slice(1)+"$")):e.names.push(new RegExp("^"+s+"$")))}function f(){let s=[...e.names.map(a),...e.skips.map(a).map(o=>"-"+o)].join(",");return e.enable(""),s}function l(s){if(s[s.length-1]==="*")return!0;let o,c;for(o=0,c=e.skips.length;o<c;o++)if(e.skips[o].test(s))return!1;for(o=0,c=e.names.length;o<c;o++)if(e.names[o].test(s))return!0;return!1}function a(s){return s.toString().substring(2,s.toString().length-2).replace(/\.\*\?$/,"*")}function d(s){return s instanceof Error?s.stack||s.message:s}function m(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return e.enable(e.load()),e}X.exports=ue});var P=T((u,k)=>{u.formatArgs=fe;u.save=de;u.load=Ce;u.useColors=he;u.storage=pe();u.destroy=(()=>{let r=!1;return()=>{r||(r=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();u.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"];function he(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function fe(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+k.exports.humanize(this.diff),!this.useColors)return;let t="color: "+this.color;r.splice(1,0,t,"color: inherit");let e=0,n=0;r[0].replace(/%[a-zA-Z%]/g,i=>{i!=="%%"&&(e++,i==="%c"&&(n=e))}),r.splice(n,0,t)}u.log=console.debug||console.log||(()=>{});function de(r){try{r?u.storage.setItem("debug",r):u.storage.removeItem("debug")}catch{}}function Ce(){let r;try{r=u.storage.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function pe(){try{return localStorage}catch{}}k.exports=J()(u);var{formatters:me}=k.exports;me.j=function(r){try{return JSON.stringify(r)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}});var B=T((Te,Z)=>{"use strict";Z.exports=U;var ge=L(),p=U.prototype,we=new Date%1e9;function ye(){return(Math.random()*1e9>>>0)+we++}function U(r){r=r||{},this.id=r.id||ye(),this.max=r.max||1/0,this.items=r.items||[],this._lookup={},this.size=this.items.length,this.lastModified=new Date(r.lastModified||new Date);for(var t,e,n=this.items.length;n--;)t=this.items[n],e=new Date(t.expires)-new Date,this._lookup[t.key]=t,e>0?this.expire(t.key,e):e<=0&&this.delete(t.key)}p.has=function(r){return r in this._lookup};p.get=function(r){if(!this.has(r))return null;var t=this._lookup[r];return t.refresh&&this.expire(r,t.refresh),this.items.splice(this.items.indexOf(t),1),this.items.push(t),t.value};p.meta=function(r){if(!this.has(r))return null;var t=this._lookup[r];return"meta"in t?t.meta:null};p.set=function(r,t,e){var n=this._lookup[r],i=this._lookup[r]={key:r,value:t};return this.lastModified=new Date,n?(clearTimeout(n.timeout),this.items.splice(this.items.indexOf(n),1,i)):(this.size>=this.max&&this.delete(this.items[0].key),this.items.push(i),this.size++),e&&("ttl"in e&&this.expire(r,e.ttl),"meta"in e&&(i.meta=e.meta),e.refresh&&(i.refresh=e.ttl)),this};p.delete=function(r){var t=this._lookup[r];return t?(this.lastModified=new Date,this.items.splice(this.items.indexOf(t),1),clearTimeout(t.timeout),delete this._lookup[r],this.size--,this):!1};p.expire=function(r,t){var e=t||0,n=this._lookup[r];if(!n)return this;if(typeof e=="string"&&(e=ge(t)),typeof e!="number")throw new TypeError("Expiration time must be a string or number.");return clearTimeout(n.timeout),n.timeout=setTimeout(this.delete.bind(this,n.key),e),n.expires=Number(new Date)+e,this};p.clear=function(){for(var r=this.items.length;r--;)this.delete(this.items[r].key);return this};p.toJSON=function(){for(var r=new Array(this.items.length),t,e=r.length;e--;)t=this.items[e],r[e]={key:t.key,meta:t.meta,value:t.value,expires:t.expires,refresh:t.refresh};return{id:this.id,max:isFinite(this.max)?this.max:void 0,lastModified:this.lastModified,items:r}}});var Fe={};se(Fe,{default:()=>ve});var q=z(P(),1),O=z(B(),1);function M(r,t,e){return`${r}?name=${t}&type=${e}`}async function G(r,t){return await(await fetch(r,{headers:new Headers({accept:"application/dns-json"}),signal:t})).json()}function y(r,t){return`${t}_${r}`}var D=Object.assign((0,q.default)("dns-over-http-resolver"),{error:(0,q.default)("dns-over-http-resolver:error")}),j=class{_cache;_TXTcache;_servers;_request;_abortControllers;constructor(t={}){this._cache=new O.default({max:t?.maxCache??100}),this._TXTcache=new O.default({max:t?.maxCache??100}),this._servers=["https://cloudflare-dns.com/dns-query","https://dns.google/resolve"],this._request=t.request??G,this._abortControllers=[]}cancel(){this._abortControllers.forEach(t=>{t.abort()})}getServers(){return this._servers}_getShuffledServers(){let t=[...this._servers];for(let e=t.length-1;e>0;e--){let n=Math.floor(Math.random()*e),i=t[e];t[e]=t[n],t[n]=i}return t}setServers(t){this._servers=t}async resolve(t,e="A"){switch(e){case"A":return this.resolve4(t);case"AAAA":return this.resolve6(t);case"TXT":return this.resolveTxt(t);default:throw new Error(`${e} is not supported`)}}async resolve4(t){let e="A",n=this._cache.get(y(t,e));if(n!=null)return n;let i=!1;for(let f of this._getShuffledServers()){let l=new AbortController;this._abortControllers.push(l);try{let a=await this._request(M(f,t,e),l.signal),d=a.Answer.map(s=>s.data),m=Math.min(...a.Answer.map(s=>s.TTL));return this._cache.set(y(t,e),d,{ttl:m}),d}catch{l.signal.aborted&&(i=!0),D.error(`${f} could not resolve ${t} record ${e}`)}finally{this._abortControllers=this._abortControllers.filter(a=>a!==l)}}throw i?Object.assign(new Error("queryA ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${t} record ${e}`)}async resolve6(t){let e="AAAA",n=this._cache.get(y(t,e));if(n!=null)return n;let i=!1;for(let f of this._getShuffledServers()){let l=new AbortController;this._abortControllers.push(l);try{let a=await this._request(M(f,t,e),l.signal),d=a.Answer.map(s=>s.data),m=Math.min(...a.Answer.map(s=>s.TTL));return this._cache.set(y(t,e),d,{ttl:m}),d}catch{l.signal.aborted&&(i=!0),D.error(`${f} could not resolve ${t} record ${e}`)}finally{this._abortControllers=this._abortControllers.filter(a=>a!==l)}}throw i?Object.assign(new Error("queryAaaa ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${t} record ${e}`)}async resolveTxt(t){let e="TXT",n=this._TXTcache.get(y(t,e));if(n!=null)return n;let i=!1;for(let f of this._getShuffledServers()){let l=new AbortController;this._abortControllers.push(l);try{let a=await this._request(M(f,t,e),l.signal),d=a.Answer.map(s=>[s.data.replace(/['"]+/g,"")]),m=Math.min(...a.Answer.map(s=>s.TTL));return this._TXTcache.set(y(t,e),d,{ttl:m}),d}catch{l.signal.aborted&&(i=!0),D.error(`${f} could not resolve ${t} record ${e}`)}finally{this._abortControllers=this._abortControllers.filter(a=>a!==l)}}throw i?Object.assign(new Error("queryTxt ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${t} record ${e}`)}clearCache(){this._cache.clear(),this._TXTcache.clear()}},ve=j;return ne(Fe);})();
"use strict";var DnsOverHttpResolver=(()=>{var _=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var K=Object.prototype.hasOwnProperty;var R=(r,e)=>{for(var t in e)_(r,t,{get:e[t],enumerable:!0})},X=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of k(e))!K.call(r,o)&&o!==t&&_(r,o,{get:()=>e[o],enumerable:!(s=D(e,o))||s.enumerable});return r};var P=r=>X(_({},"__esModule",{value:!0}),r);var oe={};R(oe,{default:()=>ne});var m=class extends Map{#s=0;#e=new Map;#t=new Map;#n;#i;#o;constructor(e={}){if(super(),!(e.maxSize&&e.maxSize>0))throw new TypeError("`maxSize` must be a number greater than 0");if(typeof e.maxAge=="number"&&e.maxAge===0)throw new TypeError("`maxAge` must be a number greater than 0");this.#n=e.maxSize,this.#i=e.maxAge||Number.POSITIVE_INFINITY,this.#o=e.onEviction}get __oldCache(){return this.#t}#c(e){if(typeof this.#o=="function")for(let[t,s]of e)this.#o(t,s.value)}#r(e,t){return typeof t.expiry=="number"&&t.expiry<=Date.now()?(typeof this.#o=="function"&&this.#o(e,t.value),this.delete(e)):!1}#f(e,t){if(this.#r(e,t)===!1)return t.value}#a(e,t){return t.expiry?this.#f(e,t):t.value}#l(e,t){let s=t.get(e);return this.#a(e,s)}#u(e,t){this.#e.set(e,t),this.#s++,this.#s>=this.#n&&(this.#s=0,this.#c(this.#t),this.#t=this.#e,this.#e=new Map)}#d(e,t){this.#t.delete(e),this.#u(e,t)}*#h(){for(let e of this.#t){let[t,s]=e;this.#e.has(t)||this.#r(t,s)===!1&&(yield e)}for(let e of this.#e){let[t,s]=e;this.#r(t,s)===!1&&(yield e)}}get(e){if(this.#e.has(e)){let t=this.#e.get(e);return this.#a(e,t)}if(this.#t.has(e)){let t=this.#t.get(e);if(this.#r(e,t)===!1)return this.#d(e,t),t.value}}set(e,t,{maxAge:s=this.#i}={}){let o=typeof s=="number"&&s!==Number.POSITIVE_INFINITY?Date.now()+s:void 0;return this.#e.has(e)?this.#e.set(e,{value:t,expiry:o}):this.#u(e,{value:t,expiry:o}),this}has(e){return this.#e.has(e)?!this.#r(e,this.#e.get(e)):this.#t.has(e)?!this.#r(e,this.#t.get(e)):!1}peek(e){if(this.#e.has(e))return this.#l(e,this.#e);if(this.#t.has(e))return this.#l(e,this.#t)}delete(e){let t=this.#e.delete(e);return t&&this.#s--,this.#t.delete(e)||t}clear(){this.#e.clear(),this.#t.clear(),this.#s=0}resize(e){if(!(e&&e>0))throw new TypeError("`maxSize` must be a number greater than 0");let t=[...this.#h()],s=t.length-e;s<0?(this.#e=new Map(t),this.#t=new Map,this.#s=t.length):(s>0&&this.#c(t.slice(0,s)),this.#t=new Map(t.slice(s)),this.#e=new Map,this.#s=0),this.#n=e}*keys(){for(let[e]of this)yield e}*values(){for(let[,e]of this)yield e}*[Symbol.iterator](){for(let e of this.#e){let[t,s]=e;this.#r(t,s)===!1&&(yield[t,s.value])}for(let e of this.#t){let[t,s]=e;this.#e.has(t)||this.#r(t,s)===!1&&(yield[t,s.value])}}*entriesDescending(){let e=[...this.#e];for(let t=e.length-1;t>=0;--t){let s=e[t],[o,u]=s;this.#r(o,u)===!1&&(yield[o,u.value])}e=[...this.#t];for(let t=e.length-1;t>=0;--t){let s=e[t],[o,u]=s;this.#e.has(o)||this.#r(o,u)===!1&&(yield[o,u.value])}}*entriesAscending(){for(let[e,t]of this.#h())yield[e,t.value]}get size(){if(!this.#s)return this.#t.size;let e=0;for(let t of this.#t.keys())this.#e.has(t)||e++;return Math.min(this.#s+e,this.#n)}get maxSize(){return this.#n}entries(){return this.entriesAscending()}forEach(e,t=this){for(let[s,o]of this.entriesAscending())e.call(t,o,s,this)}get[Symbol.toStringTag](){return JSON.stringify([...this.entriesAscending()])}};function V(r,e){try{if(typeof r=="string"&&r.length>0)return J(r);if(typeof r=="number"&&isFinite(r))return e?.long?Y(r):U(r);throw new Error("Value is not a string or number.")}catch(t){let s=Z(t)?`${t.message}. value=${JSON.stringify(r)}`:"An unknown error has occured.";throw new Error(s)}}function J(r){if(r=String(r),r.length>100)throw new Error("Value exceeds the maximum length of 100 characters.");let e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(!e)return NaN;let t=parseFloat(e[1]),s=(e[2]||"ms").toLowerCase();switch(s){case"years":case"year":case"yrs":case"yr":case"y":return t*315576e5;case"weeks":case"week":case"w":return t*6048e5;case"days":case"day":case"d":return t*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return t*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return t*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return t*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:throw new Error(`The unit ${s} was matched, but no matching case exists.`)}}var v=V;function U(r){let e=Math.abs(r);return e>=864e5?`${Math.round(r/864e5)}d`:e>=36e5?`${Math.round(r/36e5)}h`:e>=6e4?`${Math.round(r/6e4)}m`:e>=1e3?`${Math.round(r/1e3)}s`:`${r}ms`}function Y(r){let e=Math.abs(r);return e>=864e5?F(r,e,864e5,"day"):e>=36e5?F(r,e,36e5,"hour"):e>=6e4?F(r,e,6e4,"minute"):e>=1e3?F(r,e,1e3,"second"):`${r} ms`}function F(r,e,t,s){let o=e>=t*1.5;return`${Math.round(r/t)} ${s}${o?"s":""}`}function Z(r){return typeof r=="object"&&r!==null&&"message"in r}function $(r){t.debug=t,t.default=t,t.coerce=f,t.disable=u,t.enable=o,t.enabled=l,t.humanize=v,t.destroy=C,Object.keys(r).forEach(n=>{t[n]=r[n]}),t.names=[],t.skips=[],t.formatters={};function e(n){let i=0;for(let a=0;a<n.length;a++)i=(i<<5)-i+n.charCodeAt(a),i|=0;return t.colors[Math.abs(i)%t.colors.length]}t.selectColor=e;function t(n){let i,a=null,w,L;function d(...h){if(!d.enabled)return;let g=d,y=Number(new Date),O=y-(i||y);g.diff=O,g.prev=i,g.curr=y,i=y,h[0]=t.coerce(h[0]),typeof h[0]!="string"&&h.unshift("%O");let b=0;h[0]=h[0].replace(/%([a-zA-Z%])/g,(E,j)=>{if(E==="%%")return"%";b++;let N=t.formatters[j];if(typeof N=="function"){let q=h[b];E=N.call(g,q),h.splice(b,1),b--}return E}),t.formatArgs.call(g,h),(g.log||t.log).apply(g,h)}return d.namespace=n,d.useColors=t.useColors(),d.color=t.selectColor(n),d.extend=s,d.destroy=t.destroy,Object.defineProperty(d,"enabled",{enumerable:!0,configurable:!1,get:()=>a!==null?a:(w!==t.namespaces&&(w=t.namespaces,L=t.enabled(n)),L),set:h=>{a=h}}),typeof t.init=="function"&&t.init(d),d}function s(n,i){let a=t(this.namespace+(typeof i>"u"?":":i)+n);return a.log=this.log,a}function o(n){t.save(n),t.namespaces=n,t.names=[],t.skips=[];let i,a=(typeof n=="string"?n:"").split(/[\s,]+/),w=a.length;for(i=0;i<w;i++)a[i]&&(n=a[i].replace(/\*/g,".*?"),n[0]==="-"?t.skips.push(new RegExp("^"+n.substr(1)+"$")):t.names.push(new RegExp("^"+n+"$")))}function u(){let n=[...t.names.map(c),...t.skips.map(c).map(i=>"-"+i)].join(",");return t.enable(""),n}function l(n){if(n[n.length-1]==="*")return!0;let i,a;for(i=0,a=t.skips.length;i<a;i++)if(t.skips[i].test(n))return!1;for(i=0,a=t.names.length;i<a;i++)if(t.names[i].test(n))return!0;return!1}function c(n){return n.toString().substring(2,n.toString().length-2).replace(/\.\*\?$/,"*")}function f(n){return n instanceof Error?n.stack??n.message:n}function C(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.setupFormatters(t.formatters),t.enable(t.load()),t}var A=te(),B=["#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"];function G(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function H(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+v(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,s=0;r[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(t++,o==="%c"&&(s=t))}),r.splice(s,0,e)}var W=console.debug??console.log??(()=>{});function Q(r){try{r?A?.setItem("debug",r):A?.removeItem("debug")}catch{}}function ee(){let r;try{r=A?.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function te(){try{return localStorage}catch{}}function re(r){r.j=function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}}var I=$({formatArgs:H,save:Q,load:ee,useColors:G,setupFormatters:re,colors:B,storage:A,log:W});var T=I;function x(r,e,t){return`${r}?name=${e}&type=${t}`}async function z(r,e){return await(await fetch(r,{headers:new Headers({accept:"application/dns-json"}),signal:e})).json()}function p(r,e){return`${e}_${r}`}var S=Object.assign(T("dns-over-http-resolver"),{error:T("dns-over-http-resolver:error")}),M=class{_cache;_TXTcache;_servers;_request;_abortControllers;constructor(e={}){this._cache=new m({maxSize:e?.maxCache??100}),this._TXTcache=new m({maxSize:e?.maxCache??100}),this._servers=["https://cloudflare-dns.com/dns-query","https://dns.google/resolve"],this._request=e.request??z,this._abortControllers=[]}cancel(){this._abortControllers.forEach(e=>{e.abort()})}getServers(){return this._servers}_getShuffledServers(){let e=[...this._servers];for(let t=e.length-1;t>0;t--){let s=Math.floor(Math.random()*t),o=e[t];e[t]=e[s],e[s]=o}return e}setServers(e){this._servers=e}async 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){let t="A",s=this._cache.get(p(e,t));if(s!=null)return s;let o=!1;for(let u of this._getShuffledServers()){let l=new AbortController;this._abortControllers.push(l);try{let c=await this._request(x(u,e,t),l.signal),f=c.Answer.map(n=>n.data),C=Math.min(...c.Answer.map(n=>n.TTL));return this._cache.set(p(e,t),f,{maxAge:C}),f}catch{l.signal.aborted&&(o=!0),S.error(`${u} could not resolve ${e} record ${t}`)}finally{this._abortControllers=this._abortControllers.filter(c=>c!==l)}}throw o?Object.assign(new Error("queryA ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${e} record ${t}`)}async resolve6(e){let t="AAAA",s=this._cache.get(p(e,t));if(s!=null)return s;let o=!1;for(let u of this._getShuffledServers()){let l=new AbortController;this._abortControllers.push(l);try{let c=await this._request(x(u,e,t),l.signal),f=c.Answer.map(n=>n.data),C=Math.min(...c.Answer.map(n=>n.TTL));return this._cache.set(p(e,t),f,{maxAge:C}),f}catch{l.signal.aborted&&(o=!0),S.error(`${u} could not resolve ${e} record ${t}`)}finally{this._abortControllers=this._abortControllers.filter(c=>c!==l)}}throw o?Object.assign(new Error("queryAaaa ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${e} record ${t}`)}async resolveTxt(e){let t="TXT",s=this._TXTcache.get(p(e,t));if(s!=null)return s;let o=!1;for(let u of this._getShuffledServers()){let l=new AbortController;this._abortControllers.push(l);try{let c=await this._request(x(u,e,t),l.signal),f=c.Answer.map(n=>[n.data.replace(/['"]+/g,"")]),C=Math.min(...c.Answer.map(n=>n.TTL));return this._TXTcache.set(p(e,t),f,{maxAge:C}),f}catch{l.signal.aborted&&(o=!0),S.error(`${u} could not resolve ${e} record ${t}`)}finally{this._abortControllers=this._abortControllers.filter(c=>c!==l)}}throw o?Object.assign(new Error("queryTxt ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${e} record ${t}`)}clearCache(){this._cache.clear(),this._TXTcache.clear()}},ne=M;return P(oe);})();
return DnsOverHttpResolver}));

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

import debug from 'debug';
import Receptacle from 'receptacle';
import QuickLRU from 'quick-lru';
import debug from 'weald';
import * as utils from './utils.js';

@@ -24,4 +24,4 @@ const log = Object.assign(debug('dns-over-http-resolver'), {

constructor(options = {}) {
this._cache = new Receptacle({ max: options?.maxCache ?? 100 });
this._TXTcache = new Receptacle({ max: options?.maxCache ?? 100 });
this._cache = new QuickLRU({ maxSize: options?.maxCache ?? 100 });
this._TXTcache = new QuickLRU({ maxSize: options?.maxCache ?? 100 });
this._servers = [

@@ -101,3 +101,3 @@ 'https://cloudflare-dns.com/dns-query',

const ttl = Math.min(...response.Answer.map(a => a.TTL));
this._cache.set(utils.getCacheKey(hostname, recordType), data, { ttl });
this._cache.set(utils.getCacheKey(hostname, recordType), data, { maxAge: ttl });
return data;

@@ -141,3 +141,3 @@ }

const ttl = Math.min(...response.Answer.map(a => a.TTL));
this._cache.set(utils.getCacheKey(hostname, recordType), data, { ttl });
this._cache.set(utils.getCacheKey(hostname, recordType), data, { maxAge: ttl });
return data;

@@ -181,3 +181,3 @@ }

const ttl = Math.min(...response.Answer.map(a => a.TTL));
this._TXTcache.set(utils.getCacheKey(hostname, recordType), data, { ttl });
this._TXTcache.set(utils.getCacheKey(hostname, recordType), data, { maxAge: ttl });
return data;

@@ -184,0 +184,0 @@ }

{
"name": "dns-over-http-resolver",
"version": "3.0.2",
"version": "3.0.3",
"description": "DNS over HTTP resolver",

@@ -138,11 +138,10 @@ "author": "Vasco Santos",

"dependencies": {
"debug": "^4.3.4",
"receptacle": "^1.3.2"
"quick-lru": "^7.0.0",
"weald": "^1.0.2"
},
"devDependencies": {
"@types/debug": "^4.1.7",
"@types/sinon": "^17.0.3",
"aegir": "^42.1.1",
"sinon": "^17.0.0"
"aegir": "^44.0.0",
"sinon": "^18.0.0"
}
}

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

import debug from 'debug'
import Receptacle from 'receptacle'
import QuickLRU from 'quick-lru'
import debug from 'weald'
import * as utils from './utils.js'

@@ -22,4 +22,4 @@ import type { DNSJSON } from './utils'

class Resolver {
private readonly _cache: Receptacle<string[]>
private readonly _TXTcache: Receptacle<string[][]>
private readonly _cache: QuickLRU<string, string[]>
private readonly _TXTcache: QuickLRU<string, string[][]>
private _servers: string[]

@@ -36,4 +36,4 @@ private readonly _request: Request

constructor (options: ResolverOptions = {}) {
this._cache = new Receptacle({ max: options?.maxCache ?? 100 })
this._TXTcache = new Receptacle({ max: options?.maxCache ?? 100 })
this._cache = new QuickLRU({ maxSize: options?.maxCache ?? 100 })
this._TXTcache = new QuickLRU({ maxSize: options?.maxCache ?? 100 })
this._servers = [

@@ -138,3 +138,3 @@ 'https://cloudflare-dns.com/dns-query',

this._cache.set(utils.getCacheKey(hostname, recordType), data, { ttl })
this._cache.set(utils.getCacheKey(hostname, recordType), data, { maxAge: ttl })

@@ -189,3 +189,3 @@ return data

this._cache.set(utils.getCacheKey(hostname, recordType), data, { ttl })
this._cache.set(utils.getCacheKey(hostname, recordType), data, { maxAge: ttl })

@@ -240,3 +240,3 @@ return data

this._TXTcache.set(utils.getCacheKey(hostname, recordType), data, { ttl })
this._TXTcache.set(utils.getCacheKey(hostname, recordType), data, { maxAge: ttl })

@@ -243,0 +243,0 @@ return data

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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