X-Git-Url: http://git.squeep.com/?p=squeep-indieauth-helper;a=blobdiff_plain;f=lib%2Fcommunication.js;fp=lib%2Fcommunication.js;h=ce2bc4e25b8bc05b281b86f970cd1e152b30c35c;hp=2a69e34df0fe4f150f8b2548a131ae0ca2391ddd;hb=03cdf23c601ed191fb3d23f5d5bd7b3c7198e578;hpb=9d8e408337e21e37df7fb6fdea30e9dbd06104d1 diff --git a/lib/communication.js b/lib/communication.js index 2a69e34..ce2bc4e 100644 --- a/lib/communication.js +++ b/lib/communication.js @@ -11,7 +11,6 @@ const { promisify } = require('util'); const randomBytesAsync = promisify(randomBytes); const { Address4, Address6 } = require('ip-address'); const dns = require('dns'); -dns.lookupAsync = dns.lookupAsync || promisify(dns.lookup); const common = require('./common'); const Enum = require('./enum'); const { ValidationError } = require('./errors'); @@ -439,7 +438,7 @@ class Communication { if (!urlObj.hostname.endsWith('.')) { hostnames.push(urlObj.hostname + '.'); } - const settledResolutions = await Promise.allSettled(hostnames.map((hostname) => dns.lookupAsync(hostname, { + const settledResolutions = await Promise.allSettled(hostnames.map((hostname) => dns.promises.lookup(hostname, { all: true, verbatim: true, }))); @@ -519,7 +518,7 @@ class Communication { Communication._urlValidScheme(profile); Communication._urlPartsDisallowed(profile, ['hash', 'username', 'password', 'port']); Communication._urlPathNoDots(url); - Communication._urlNamedHost(profile, options.allowLoopback, options.resolveHostname); + await Communication._urlNamedHost(profile, options.allowLoopback, options.resolveHostname); } catch (e) { this.logger.debug(_scope, 'profile url not valid', { url, error: e }); throw new ValidationError(`${errorScope}: ${e.message}`); @@ -607,7 +606,7 @@ class Communication { let urlMatched = false; const itemType = item.type || []; if ((itemType.includes('h-app') || itemType.includes('h-x-app')) - && (item.properties && item.properties.url)) { + && (item?.properties?.url)) { item.properties.url.forEach((url) => { try { const hUrl = new URL(url); @@ -671,7 +670,7 @@ class Communication { // and populate profile fields with first-encountered card values. if (mfData && 'items' in mfData) { const hCards = mfData.items.filter((item) => - item.type && item.type.includes('h-card') && + item?.type?.includes('h-card') && item.properties && item.properties.url && item.properties.url.includes(urlObj.href)); hCards.forEach((hCard) => { Object.keys(profile).forEach((key) => { @@ -800,7 +799,7 @@ class Communication { * @returns {Object} */ async redeemProfileCode(urlObj, code, codeVerifier, clientId, redirectURI) { - return await this.redeemCode(urlObj, code, codeVerifier, clientId, redirectURI); + return this.redeemCode(urlObj, code, codeVerifier, clientId, redirectURI); }