@xmpp/resolve
Advanced tools
+3
-5
@@ -1,9 +0,7 @@ | ||
| 'use strict' | ||
| "use strict"; | ||
| const resolve = require('./resolve') | ||
| const resolve = require("./resolve"); | ||
| // For you | ||
| // const resolve = require('@xmpp/resolve') | ||
| resolve('jabberfr.org') | ||
| .then(console.log) | ||
| .catch(console.error) | ||
| resolve("jabberfr.org").then(console.log).catch(console.error); |
+37
-38
@@ -1,5 +0,5 @@ | ||
| 'use strict' | ||
| "use strict"; | ||
| const resolve = require('./resolve') | ||
| const {promise} = require('@xmpp/events') | ||
| const resolve = require("./resolve"); | ||
| const { promise } = require("@xmpp/events"); | ||
@@ -14,18 +14,18 @@ async function fetchURIs(domain) { | ||
| { | ||
| service: 'xmpps-client', | ||
| protocol: 'tcp', | ||
| service: "xmpps-client", | ||
| protocol: "tcp", | ||
| }, | ||
| { | ||
| service: 'xmpp-client', | ||
| protocol: 'tcp', | ||
| service: "xmpp-client", | ||
| protocol: "tcp", | ||
| }, | ||
| ], | ||
| }) | ||
| ).map(record => record.uri) | ||
| ).map((record) => record.uri), | ||
| ), | ||
| ] | ||
| ]; | ||
| } | ||
| function filterSupportedURIs(entity, uris) { | ||
| return uris.filter(uri => entity._findTransport(uri)) | ||
| return uris.filter((uri) => entity._findTransport(uri)); | ||
| } | ||
@@ -35,52 +35,51 @@ | ||
| if (uris.length === 0) { | ||
| throw new Error("Couldn't connect") | ||
| throw new Error("Couldn't connect"); | ||
| } | ||
| const uri = uris.shift() | ||
| const Transport = entity._findTransport(uri) | ||
| const uri = uris.shift(); | ||
| const Transport = entity._findTransport(uri); | ||
| if (!Transport) { | ||
| return fallbackConnect(entity, uris) | ||
| return fallbackConnect(entity, uris); | ||
| } | ||
| entity._status('connecting', uri) | ||
| const params = Transport.prototype.socketParameters(uri) | ||
| const socket = new Transport.prototype.Socket() | ||
| entity._status("connecting", uri); | ||
| const params = Transport.prototype.socketParameters(uri); | ||
| const socket = new Transport.prototype.Socket(); | ||
| try { | ||
| socket.connect(params) | ||
| await promise(socket, 'connect') | ||
| // eslint-disable-next-line no-unused-vars | ||
| } catch (err) { | ||
| return fallbackConnect(entity, uris) | ||
| socket.connect(params); | ||
| await promise(socket, "connect"); | ||
| } catch { | ||
| return fallbackConnect(entity, uris); | ||
| } | ||
| entity._attachSocket(socket) | ||
| socket.emit('connect') | ||
| entity.Transport = Transport | ||
| entity.Socket = Transport.prototype.Socket | ||
| entity.Parser = Transport.prototype.Parser | ||
| entity._attachSocket(socket); | ||
| socket.emit("connect"); | ||
| entity.Transport = Transport; | ||
| entity.Socket = Transport.prototype.Socket; | ||
| entity.Parser = Transport.prototype.Parser; | ||
| } | ||
| module.exports = function({entity}) { | ||
| const _connect = entity.connect | ||
| module.exports = function resolve({ entity }) { | ||
| const _connect = entity.connect; | ||
| entity.connect = async function connect(service) { | ||
| if (!service || service.match(/:\/\//)) { | ||
| return _connect.call(this, service) | ||
| return _connect.call(this, service); | ||
| } | ||
| const uris = filterSupportedURIs(entity, await fetchURIs(service)) | ||
| const uris = filterSupportedURIs(entity, await fetchURIs(service)); | ||
| if (uris.length === 0) { | ||
| throw new Error('No compatible transport found.') | ||
| throw new Error("No compatible transport found."); | ||
| } | ||
| try { | ||
| await fallbackConnect(entity, uris) | ||
| await fallbackConnect(entity, uris); | ||
| } catch (err) { | ||
| entity._reset() | ||
| entity._status('disconnect') | ||
| throw err | ||
| entity._reset(); | ||
| entity._status("disconnect"); | ||
| throw err; | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| }; |
+25
-25
@@ -1,45 +0,45 @@ | ||
| 'use strict' | ||
| "use strict"; | ||
| function isSecure(uri) { | ||
| return uri.startsWith('https') || uri.startsWith('wss') | ||
| return uri.startsWith("https") || uri.startsWith("wss"); | ||
| } | ||
| module.exports.compare = function compare(a, b) { | ||
| let secure | ||
| let secure; | ||
| if (isSecure(a.uri) && !isSecure(b.uri)) { | ||
| secure = -1 | ||
| secure = -1; | ||
| } else if (!isSecure(a.uri) && isSecure(b.uri)) { | ||
| secure = 1 | ||
| secure = 1; | ||
| } else { | ||
| secure = 0 | ||
| secure = 0; | ||
| } | ||
| if (secure !== 0) { | ||
| return secure | ||
| return secure; | ||
| } | ||
| let method | ||
| let method; | ||
| if (a.method === b.method) { | ||
| method = 0 | ||
| } else if (a.method === 'websocket') { | ||
| method = -1 | ||
| } else if (b.method === 'websocket') { | ||
| method = 1 | ||
| } else if (a.method === 'xbosh') { | ||
| method = -1 | ||
| } else if (b.method === 'xbosh') { | ||
| method = 1 | ||
| } else if (a.method === 'httppoll') { | ||
| method = -1 | ||
| } else if (b.method === 'httppoll') { | ||
| method = 1 | ||
| method = 0; | ||
| } else if (a.method === "websocket") { | ||
| method = -1; | ||
| } else if (b.method === "websocket") { | ||
| method = 1; | ||
| } else if (a.method === "xbosh") { | ||
| method = -1; | ||
| } else if (b.method === "xbosh") { | ||
| method = 1; | ||
| } else if (a.method === "httppoll") { | ||
| method = -1; | ||
| } else if (b.method === "httppoll") { | ||
| method = 1; | ||
| } else { | ||
| method = 0 | ||
| method = 0; | ||
| } | ||
| if (method !== 0) { | ||
| return method | ||
| return method; | ||
| } | ||
| return 0 | ||
| } | ||
| return 0; | ||
| }; |
+96
-95
@@ -1,19 +0,20 @@ | ||
| 'use strict' | ||
| "use strict"; | ||
| const dns = require('dns') | ||
| const compareAltConnections = require('./alt-connections').compare | ||
| const dns = require("dns"); | ||
| const compareAltConnections = require("./alt-connections").compare; | ||
| const IGNORE_CODES = ['ENOTFOUND', 'ENODATA'] | ||
| // eslint-disable-next-line unicorn/prefer-set-has | ||
| const IGNORE_CODES = ["ENOTFOUND", "ENODATA"]; | ||
| function lookup(domain, options = {}) { | ||
| options.all = true | ||
| options.all = true; | ||
| return new Promise((resolve, reject) => { | ||
| dns.lookup(domain, options, (err, addresses) => { | ||
| if (err) { | ||
| return reject(err) | ||
| return reject(err); | ||
| } | ||
| const result = [] | ||
| addresses.forEach(({family, address}) => { | ||
| const uri = `://${family === 4 ? address : '[' + address + ']'}:` | ||
| const result = []; | ||
| addresses.forEach(({ family, address }) => { | ||
| const uri = `://${family === 4 ? address : "[" + address + "]"}:`; | ||
| result.push( | ||
@@ -23,3 +24,3 @@ { | ||
| address, | ||
| uri: 'xmpps' + uri + '5223', | ||
| uri: "xmpps" + uri + "5223", | ||
| }, | ||
@@ -29,53 +30,53 @@ { | ||
| address, | ||
| uri: 'xmpp' + uri + '5222', | ||
| } | ||
| ) | ||
| }) | ||
| resolve(result) | ||
| }) | ||
| }) | ||
| uri: "xmpp" + uri + "5222", | ||
| }, | ||
| ); | ||
| }); | ||
| resolve(result); | ||
| }); | ||
| }); | ||
| } | ||
| function resolveTxt(domain, {owner = '_xmppconnect'}) { | ||
| function resolveTxt(domain, { owner = "_xmppconnect" }) { | ||
| return new Promise((resolve, reject) => { | ||
| dns.resolveTxt(`${owner}.${domain}`, (err, records) => { | ||
| if (err && IGNORE_CODES.includes(err.code)) { | ||
| resolve([]) | ||
| resolve([]); | ||
| } else if (err) { | ||
| reject(err) | ||
| reject(err); | ||
| } else { | ||
| resolve( | ||
| records | ||
| .map(record => { | ||
| const [attribute, value] = record[0].split('=') | ||
| .map((record) => { | ||
| const [attribute, value] = record[0].split("="); | ||
| return { | ||
| attribute, | ||
| value, | ||
| method: attribute.split('-').pop(), | ||
| method: attribute.split("-").pop(), | ||
| uri: value, | ||
| } | ||
| }; | ||
| }) | ||
| .sort(compareAltConnections) | ||
| ) | ||
| .sort(compareAltConnections), | ||
| ); | ||
| } | ||
| }) | ||
| }) | ||
| }); | ||
| }); | ||
| } | ||
| function resolveSrv(domain, {service, protocol}) { | ||
| function resolveSrv(domain, { service, protocol }) { | ||
| return new Promise((resolve, reject) => { | ||
| dns.resolveSrv(`_${service}._${protocol}.${domain}`, (err, records) => { | ||
| if (err && IGNORE_CODES.includes(err.code)) { | ||
| resolve([]) | ||
| resolve([]); | ||
| } else if (err) { | ||
| reject(err) | ||
| reject(err); | ||
| } else { | ||
| resolve( | ||
| records.map(record => { | ||
| return Object.assign(record, {service, protocol}) | ||
| }) | ||
| ) | ||
| records.map((record) => { | ||
| return Object.assign(record, { service, protocol }); | ||
| }), | ||
| ); | ||
| } | ||
| }) | ||
| }) | ||
| }); | ||
| }); | ||
| } | ||
@@ -85,34 +86,34 @@ | ||
| return records.sort((a, b) => { | ||
| const priority = a.priority - b.priority | ||
| const priority = a.priority - b.priority; | ||
| if (priority !== 0) { | ||
| return priority | ||
| return priority; | ||
| } | ||
| const weight = b.weight - a.weight | ||
| const weight = b.weight - a.weight; | ||
| if (weight !== 0) { | ||
| return weight | ||
| return weight; | ||
| } | ||
| return 0 | ||
| }) | ||
| return 0; | ||
| }); | ||
| } | ||
| function lookupSrvs(srvs, options) { | ||
| const addresses = [] | ||
| const addresses = []; | ||
| return Promise.all( | ||
| srvs.map(async srv => { | ||
| const srvAddresses = await lookup(srv.name, options) | ||
| srvAddresses.forEach(address => { | ||
| const {port, service} = srv | ||
| const addr = address.address | ||
| srvs.map(async (srv) => { | ||
| const srvAddresses = await lookup(srv.name, options); | ||
| srvAddresses.forEach((address) => { | ||
| const { port, service } = srv; | ||
| const addr = address.address; | ||
| addresses.push({ | ||
| ...address, | ||
| ...srv, | ||
| uri: `${service.split('-')[0]}://${ | ||
| address.family === 6 ? '[' + addr + ']' : addr | ||
| uri: `${service.split("-")[0]}://${ | ||
| address.family === 6 ? "[" + addr + "]" : addr | ||
| }:${port}`, | ||
| }) | ||
| }) | ||
| }) | ||
| ).then(() => addresses) | ||
| }); | ||
| }); | ||
| }), | ||
| ).then(() => addresses); | ||
| } | ||
@@ -124,66 +125,66 @@ | ||
| { | ||
| service: 'xmpps-client', | ||
| protocol: 'tcp', | ||
| service: "xmpps-client", | ||
| protocol: "tcp", | ||
| }, | ||
| { | ||
| service: 'xmpp-client', | ||
| protocol: 'tcp', | ||
| service: "xmpp-client", | ||
| protocol: "tcp", | ||
| }, | ||
| { | ||
| service: 'xmpps-server', | ||
| protocol: 'tcp', | ||
| service: "xmpps-server", | ||
| protocol: "tcp", | ||
| }, | ||
| { | ||
| service: 'xmpp-server', | ||
| protocol: 'tcp', | ||
| service: "xmpp-server", | ||
| protocol: "tcp", | ||
| }, | ||
| { | ||
| service: 'stun', | ||
| protocol: 'tcp', | ||
| service: "stun", | ||
| protocol: "tcp", | ||
| }, | ||
| { | ||
| service: 'stun', | ||
| protocol: 'udp', | ||
| service: "stun", | ||
| protocol: "udp", | ||
| }, | ||
| { | ||
| service: 'stuns ', | ||
| protcol: 'tcp', | ||
| service: "stuns ", | ||
| protcol: "tcp", | ||
| }, | ||
| { | ||
| service: 'turn', | ||
| protocol: 'tcp', | ||
| service: "turn", | ||
| protocol: "tcp", | ||
| }, | ||
| { | ||
| service: 'turn', | ||
| protocol: 'udp', | ||
| service: "turn", | ||
| protocol: "udp", | ||
| }, | ||
| { | ||
| service: 'turns', | ||
| protcol: 'tcp', | ||
| service: "turns", | ||
| protcol: "tcp", | ||
| }, | ||
| ] | ||
| ]; | ||
| } | ||
| const family = {options} | ||
| return lookup(domain, options).then(addresses => { | ||
| const family = { options }; | ||
| return lookup(domain, options).then((addresses) => { | ||
| return Promise.all( | ||
| options.srv.map(srv => { | ||
| return resolveSrv(domain, {...srv, family}).then(records => { | ||
| return lookupSrvs(records, options) | ||
| }) | ||
| }) | ||
| options.srv.map((srv) => { | ||
| return resolveSrv(domain, { ...srv, family }).then((records) => { | ||
| return lookupSrvs(records, options); | ||
| }); | ||
| }), | ||
| ) | ||
| .then(srvs => sortSrv([].concat(...srvs)).concat(addresses)) | ||
| .then(records => { | ||
| return resolveTxt(domain, options).then(txtRecords => { | ||
| return records.concat(txtRecords) | ||
| }) | ||
| }) | ||
| }) | ||
| .then((srvs) => sortSrv([].concat(...srvs)).concat(addresses)) | ||
| .then((records) => { | ||
| return resolveTxt(domain, options).then((txtRecords) => { | ||
| return records.concat(txtRecords); | ||
| }); | ||
| }); | ||
| }); | ||
| } | ||
| module.exports.lookup = lookup | ||
| module.exports.resolveSrv = resolveSrv | ||
| module.exports.lookupSrvs = lookupSrvs | ||
| module.exports.resolve = resolve | ||
| module.exports.sortSrv = sortSrv | ||
| module.exports.lookup = lookup; | ||
| module.exports.resolveSrv = resolveSrv; | ||
| module.exports.lookupSrvs = lookupSrvs; | ||
| module.exports.resolve = resolve; | ||
| module.exports.sortSrv = sortSrv; |
+18
-18
@@ -1,33 +0,33 @@ | ||
| 'use strict' | ||
| "use strict"; | ||
| const fetch = global.fetch || require('node-fetch') | ||
| const parse = require('@xmpp/xml/lib/parse') | ||
| const compareAltConnections = require('./alt-connections').compare | ||
| const fetch = global.fetch || require("node-fetch"); | ||
| const parse = require("@xmpp/xml/lib/parse"); | ||
| const compareAltConnections = require("./alt-connections").compare; | ||
| function resolve(domain) { | ||
| return fetch(`https://${domain}/.well-known/host-meta`) | ||
| .then(res => res.text()) | ||
| .then(res => { | ||
| .then((res) => res.text()) | ||
| .then((res) => { | ||
| return parse(res) | ||
| .getChildren('Link') | ||
| .filter(link => | ||
| .getChildren("Link") | ||
| .filter((link) => | ||
| [ | ||
| 'urn:xmpp:alt-connections:websocket', | ||
| 'urn:xmpp:alt-connections:httppoll', | ||
| 'urn:xmpp:alt-connections:xbosh', | ||
| ].includes(link.attrs.rel) | ||
| "urn:xmpp:alt-connections:websocket", | ||
| "urn:xmpp:alt-connections:httppoll", | ||
| "urn:xmpp:alt-connections:xbosh", | ||
| ].includes(link.attrs.rel), | ||
| ) | ||
| .map(({attrs}) => ({ | ||
| .map(({ attrs }) => ({ | ||
| rel: attrs.rel, | ||
| href: attrs.href, | ||
| method: attrs.rel.split(':').pop(), | ||
| method: attrs.rel.split(":").pop(), | ||
| uri: attrs.href, | ||
| })) | ||
| .sort(compareAltConnections) | ||
| .sort(compareAltConnections); | ||
| }) | ||
| .catch(() => { | ||
| return [] | ||
| }) | ||
| return []; | ||
| }); | ||
| } | ||
| module.exports.resolve = resolve | ||
| module.exports.resolve = resolve; |
+6
-6
@@ -7,3 +7,3 @@ { | ||
| "bugs": "http://github.com/xmppjs/xmpp.js/issues", | ||
| "version": "0.11.0", | ||
| "version": "0.12.0", | ||
| "license": "ISC", | ||
@@ -25,8 +25,8 @@ "keywords": [ | ||
| "dependencies": { | ||
| "@xmpp/events": "^0.11.0", | ||
| "@xmpp/xml": "^0.11.0", | ||
| "node-fetch": "^2.6.0" | ||
| "@xmpp/events": "^0.12.0", | ||
| "@xmpp/xml": "^0.12.0", | ||
| "node-fetch": "^2.6.1" | ||
| }, | ||
| "engines": { | ||
| "node": ">= 10.0.0", | ||
| "node": ">= 12.4.0", | ||
| "yarn": ">= 1.0.0" | ||
@@ -37,3 +37,3 @@ }, | ||
| }, | ||
| "gitHead": "c0548a598826ae55cf195f296058b344064af7fd" | ||
| "gitHead": "75f7bdf7805dced03f616b66dc16e2a067b46480" | ||
| } |
+17
-19
@@ -16,22 +16,20 @@ # resolve | ||
| ```javascript | ||
| const resolve = require('@xmpp/resolve') | ||
| const resolve = require("@xmpp/resolve"); | ||
| // optional | ||
| const options = { | ||
| srv: [{service: 'xmpp-client', protocol: 'tcp'}], // SRV records | ||
| srv: [{ service: "xmpp-client", protocol: "tcp" }], // SRV records | ||
| family: undefined, // IP version; 4, 6 or undefined for both | ||
| owner: '_xmppconnect', // TXT owner | ||
| } | ||
| owner: "_xmppconnect", // TXT owner | ||
| }; | ||
| resolve('xmppjs.org', options) | ||
| .then(console.log) | ||
| .catch(console.error) | ||
| resolve("xmppjs.org", options).then(console.log).catch(console.error); | ||
| ``` | ||
| ```javascript | ||
| ;[ | ||
| [ | ||
| { | ||
| address: '93.113.206.189', | ||
| address: "93.113.206.189", | ||
| family: 4, | ||
| name: 'xmppjs.org', | ||
| name: "xmppjs.org", | ||
| port: 5222, | ||
@@ -42,5 +40,5 @@ priority: 5, | ||
| { | ||
| address: '2a03:75c0:39:3458::1', | ||
| address: "2a03:75c0:39:3458::1", | ||
| family: 6, | ||
| name: 'xmppjs.org', | ||
| name: "xmppjs.org", | ||
| port: 5222, | ||
@@ -50,13 +48,13 @@ priority: 5, | ||
| }, | ||
| {address: '93.113.206.189', family: 4}, | ||
| {address: '2a03:75c0:39:3458::1', family: 6}, | ||
| { address: "93.113.206.189", family: 4 }, | ||
| { address: "2a03:75c0:39:3458::1", family: 6 }, | ||
| { | ||
| attribute: '_xmpp-client-websocket', | ||
| uri: 'wss://xmppjs.org:443/websocket', | ||
| attribute: "_xmpp-client-websocket", | ||
| uri: "wss://xmppjs.org:443/websocket", | ||
| }, | ||
| { | ||
| attribute: '_xmpp-client-xbosh', | ||
| uri: 'https://xmppjs.org:443/bosh', | ||
| attribute: "_xmpp-client-xbosh", | ||
| uri: "https://xmppjs.org:443/bosh", | ||
| }, | ||
| ] | ||
| ]; | ||
| ``` | ||
@@ -63,0 +61,0 @@ |
+7
-7
@@ -1,5 +0,5 @@ | ||
| 'use strict' | ||
| "use strict"; | ||
| const dns = require('./lib/dns') | ||
| const http = require('./lib/http') | ||
| const dns = require("./lib/dns"); | ||
| const http = require("./lib/http"); | ||
@@ -10,9 +10,9 @@ module.exports = function resolve(...args) { | ||
| http.resolve(...args), | ||
| ]).then(([records, endpoints]) => records.concat(endpoints)) | ||
| } | ||
| ]).then(([records, endpoints]) => records.concat(endpoints)); | ||
| }; | ||
| if (dns.resolve) { | ||
| module.exports.dns = dns | ||
| module.exports.dns = dns; | ||
| } | ||
| module.exports.http = http | ||
| module.exports.http = http; |
@@ -1,43 +0,43 @@ | ||
| 'use strict' | ||
| "use strict"; | ||
| const test = require('ava') | ||
| const {compare} = require('../lib/alt-connections') | ||
| const test = require("ava"); | ||
| const { compare } = require("../lib/alt-connections"); | ||
| test('by security', t => { | ||
| test("by security", (t) => { | ||
| t.deepEqual( | ||
| [ | ||
| {uri: 'http://web.example.org:5280/bosh', method: 'xbosh'}, | ||
| {uri: 'https://web.example.org:5280/bosh', method: 'xbosh'}, | ||
| { uri: "http://web.example.org:5280/bosh", method: "xbosh" }, | ||
| { uri: "https://web.example.org:5280/bosh", method: "xbosh" }, | ||
| ].sort(compare), | ||
| [ | ||
| {uri: 'https://web.example.org:5280/bosh', method: 'xbosh'}, | ||
| {uri: 'http://web.example.org:5280/bosh', method: 'xbosh'}, | ||
| ] | ||
| ) | ||
| { uri: "https://web.example.org:5280/bosh", method: "xbosh" }, | ||
| { uri: "http://web.example.org:5280/bosh", method: "xbosh" }, | ||
| ], | ||
| ); | ||
| t.deepEqual( | ||
| [ | ||
| {uri: 'ws://web.example.com:80/ws', method: 'websocket'}, | ||
| {uri: 'https://web.example.org:5280/bosh', method: 'xbosh'}, | ||
| { uri: "ws://web.example.com:80/ws", method: "websocket" }, | ||
| { uri: "https://web.example.org:5280/bosh", method: "xbosh" }, | ||
| ].sort(compare), | ||
| [ | ||
| {uri: 'https://web.example.org:5280/bosh', method: 'xbosh'}, | ||
| {uri: 'ws://web.example.com:80/ws', method: 'websocket'}, | ||
| ] | ||
| ) | ||
| }) | ||
| { uri: "https://web.example.org:5280/bosh", method: "xbosh" }, | ||
| { uri: "ws://web.example.com:80/ws", method: "websocket" }, | ||
| ], | ||
| ); | ||
| }); | ||
| test('by method', t => { | ||
| test("by method", (t) => { | ||
| t.deepEqual( | ||
| [ | ||
| {uri: 'https://web.example.org:5280/http-poll', method: 'httppoll'}, | ||
| {uri: 'wss://web.example.com:443/ws', method: 'websocket'}, | ||
| {uri: 'https://web.example.org:5280/bosh', method: 'xbosh'}, | ||
| { uri: "https://web.example.org:5280/http-poll", method: "httppoll" }, | ||
| { uri: "wss://web.example.com:443/ws", method: "websocket" }, | ||
| { uri: "https://web.example.org:5280/bosh", method: "xbosh" }, | ||
| ].sort(compare), | ||
| [ | ||
| {uri: 'wss://web.example.com:443/ws', method: 'websocket'}, | ||
| {uri: 'https://web.example.org:5280/bosh', method: 'xbosh'}, | ||
| {uri: 'https://web.example.org:5280/http-poll', method: 'httppoll'}, | ||
| ] | ||
| ) | ||
| }) | ||
| { uri: "wss://web.example.com:443/ws", method: "websocket" }, | ||
| { uri: "https://web.example.org:5280/bosh", method: "xbosh" }, | ||
| { uri: "https://web.example.org:5280/http-poll", method: "httppoll" }, | ||
| ], | ||
| ); | ||
| }); |
+24
-24
@@ -1,9 +0,9 @@ | ||
| 'use strict' | ||
| "use strict"; | ||
| const test = require('ava') | ||
| const test = require("ava"); | ||
| const domain = 'example.com' | ||
| global.fetch = url => { | ||
| const domain = "example.com"; | ||
| global.fetch = (url) => { | ||
| if (url !== `https://${domain}/.well-known/host-meta`) { | ||
| throw new Error('Fetch URL incorrect') | ||
| throw new Error("Fetch URL incorrect"); | ||
| } | ||
@@ -18,30 +18,30 @@ | ||
| <Link rel='urn:xmpp:alt-connections:httppoll' href='http://example.com/http-poll' /> | ||
| </XRD>` | ||
| </XRD>`; | ||
| }, | ||
| }) | ||
| } | ||
| }); | ||
| }; | ||
| const {resolve} = require('../lib/http') | ||
| const { resolve } = require("../lib/http"); | ||
| test('parse', async t => { | ||
| test("parse", async (t) => { | ||
| t.deepEqual(await resolve(domain), [ | ||
| { | ||
| rel: 'urn:xmpp:alt-connections:websocket', | ||
| href: 'wss://example.com/ws', | ||
| method: 'websocket', | ||
| uri: 'wss://example.com/ws', | ||
| rel: "urn:xmpp:alt-connections:websocket", | ||
| href: "wss://example.com/ws", | ||
| method: "websocket", | ||
| uri: "wss://example.com/ws", | ||
| }, | ||
| { | ||
| rel: 'urn:xmpp:alt-connections:xbosh', | ||
| href: 'http://example.com/bosh', | ||
| method: 'xbosh', | ||
| uri: 'http://example.com/bosh', | ||
| rel: "urn:xmpp:alt-connections:xbosh", | ||
| href: "http://example.com/bosh", | ||
| method: "xbosh", | ||
| uri: "http://example.com/bosh", | ||
| }, | ||
| { | ||
| rel: 'urn:xmpp:alt-connections:httppoll', | ||
| href: 'http://example.com/http-poll', | ||
| method: 'httppoll', | ||
| uri: 'http://example.com/http-poll', | ||
| rel: "urn:xmpp:alt-connections:httppoll", | ||
| href: "http://example.com/http-poll", | ||
| method: "httppoll", | ||
| uri: "http://example.com/http-poll", | ||
| }, | ||
| ]) | ||
| }) | ||
| ]); | ||
| }); |
+31
-31
@@ -1,52 +0,52 @@ | ||
| 'use strict' | ||
| "use strict"; | ||
| const test = require('ava') | ||
| const sort = require('../lib/dns').sortSrv | ||
| const test = require("ava"); | ||
| const sort = require("../lib/dns").sortSrv; | ||
| test('by priority', t => { | ||
| test("by priority", (t) => { | ||
| t.deepEqual( | ||
| sort([ | ||
| {priority: 2, weight: 0}, | ||
| {priority: 1, weight: 0}, | ||
| { priority: 2, weight: 0 }, | ||
| { priority: 1, weight: 0 }, | ||
| ]), | ||
| [ | ||
| {priority: 1, weight: 0}, | ||
| {priority: 2, weight: 0}, | ||
| ] | ||
| ) | ||
| { priority: 1, weight: 0 }, | ||
| { priority: 2, weight: 0 }, | ||
| ], | ||
| ); | ||
| t.deepEqual( | ||
| sort([ | ||
| {priority: 2, weight: 1}, | ||
| {priority: 1, weight: 0}, | ||
| { priority: 2, weight: 1 }, | ||
| { priority: 1, weight: 0 }, | ||
| ]), | ||
| [ | ||
| {priority: 1, weight: 0}, | ||
| {priority: 2, weight: 1}, | ||
| ] | ||
| ) | ||
| }) | ||
| { priority: 1, weight: 0 }, | ||
| { priority: 2, weight: 1 }, | ||
| ], | ||
| ); | ||
| }); | ||
| test('by weight', t => { | ||
| test("by weight", (t) => { | ||
| t.deepEqual( | ||
| sort([ | ||
| {weight: 1, priority: 0}, | ||
| {weight: 2, priority: 0}, | ||
| { weight: 1, priority: 0 }, | ||
| { weight: 2, priority: 0 }, | ||
| ]), | ||
| [ | ||
| {weight: 2, priority: 0}, | ||
| {weight: 1, priority: 0}, | ||
| ] | ||
| ) | ||
| { weight: 2, priority: 0 }, | ||
| { weight: 1, priority: 0 }, | ||
| ], | ||
| ); | ||
| t.deepEqual( | ||
| sort([ | ||
| {weight: 2, priority: 0}, | ||
| {weight: 1, priority: 0}, | ||
| { weight: 2, priority: 0 }, | ||
| { weight: 1, priority: 0 }, | ||
| ]), | ||
| [ | ||
| {weight: 2, priority: 0}, | ||
| {weight: 1, priority: 0}, | ||
| ] | ||
| ) | ||
| }) | ||
| { weight: 2, priority: 0 }, | ||
| { weight: 1, priority: 0 }, | ||
| ], | ||
| ); | ||
| }); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
15319
1.92%457
-0.44%67
-2.9%7
16.67%+ Added
+ Added
- Removed
- Removed
Updated
Updated
Updated