@victorenator/service-fetch
Advanced tools
Comparing version 0.1.0 to 1.0.2
91
index.js
@@ -1,52 +0,53 @@ | ||
"use strict"; | ||
import {resolveSrv} from 'node:dns/promises'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = _default; | ||
Object.defineProperty(exports, "Headers", { | ||
enumerable: true, | ||
get: function () { | ||
return _nodeFetch.Headers; | ||
} | ||
}); | ||
Object.defineProperty(exports, "Request", { | ||
enumerable: true, | ||
get: function () { | ||
return _nodeFetch.Request; | ||
} | ||
}); | ||
Object.defineProperty(exports, "Response", { | ||
enumerable: true, | ||
get: function () { | ||
return _nodeFetch.Response; | ||
} | ||
}); | ||
Object.defineProperty(exports, "FetchError", { | ||
enumerable: true, | ||
get: function () { | ||
return _nodeFetch.FetchError; | ||
} | ||
}); | ||
/** | ||
* @typedef {object} SRV | ||
* @property {string} name | ||
* @property {number} port | ||
* @property {number} priority | ||
* @property {number} weight | ||
*/ | ||
var _nodeFetch = _interopRequireDefault(require("node-fetch")); | ||
/** | ||
* @typedef {object} RequestService | ||
* @property {string} [domain] local. | ||
* @property {string} [type] _http._tcp | ||
*/ | ||
var _dns = _interopRequireDefault(require("dns")); | ||
/** | ||
* | ||
* @param {string|URL} input | ||
* @param {RequestInit & RequestService} init | ||
* @returns {Promise<Response>} | ||
*/ | ||
export default async function (input, init = {}) { | ||
const url = new URL(input); | ||
const domain = init.domain ?? 'local.'; | ||
const type = init.type ?? '_http._tcp'; | ||
/** @type {SRV[]} */ | ||
const services = await resolveSrv(`${url.hostname}.${type}.${domain}`); | ||
services.sort(compareServicesPriority); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
for (const service of services) { | ||
try { | ||
url.hostname = service.name; | ||
url.port = service.port; | ||
return await fetch(url, init); | ||
async function _default(url, requestInit = {}) { | ||
url = new URL(url); | ||
const domain = requestInit.domain || 'local.'; | ||
const type = requestInit.type || '_http._tcp'; | ||
const services = await _dns.default.promises.resolveSrv(`${url.hostname}.${type}.${domain}`); | ||
} catch { | ||
continue; | ||
} | ||
} | ||
if (services.length === 0) { | ||
throw new Error('Service not found'); | ||
} | ||
throw new Error('Service not available'); | ||
} | ||
const service = services[0]; | ||
url.hostname = service.name; | ||
url.port = service.port; | ||
return (0, _nodeFetch.default)(url, requestInit); | ||
} | ||
/** | ||
* Compares services by priority | ||
* @param {SRV} srv1 | ||
* @param {SRV} srv2 | ||
* @returns {number} | ||
*/ | ||
function compareServicesPriority(srv1, srv2) { | ||
return srv2.priority - srv1.priority; | ||
} |
{ | ||
"name": "@victorenator/service-fetch", | ||
"version": "0.1.0", | ||
"version": "1.0.2", | ||
"type": "module", | ||
"main": "index.js", | ||
"module": "index.js", | ||
"description": "Fetch API", | ||
"license": "MIT", | ||
"homepage": "https://gitlab.com/victorenator/node-service-fetch", | ||
@@ -10,15 +14,11 @@ "author": { | ||
}, | ||
"dependencies": { | ||
"node-fetch": "^2.6.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.5.5", | ||
"@babel/plugin-transform-modules-commonjs": "^7.5.0", | ||
"gulp": "^4.0.2", | ||
"gulp-babel": "^8.0.0", | ||
"gulp-eslint": "^6.0.0" | ||
"eslint": "^8.14.0" | ||
}, | ||
"keywords": [ | ||
"fetch" | ||
] | ||
], | ||
"engines": { | ||
"node": "18" | ||
} | ||
} |
@@ -17,3 +17,3 @@ # Feach API with dnssd services # | ||
await fetch('http://service-name/path); | ||
await fetch('http://service-name/path'); | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
1
0
1
Yes
3042
4
46
- Removednode-fetch@^2.6.0
- Removednode-fetch@2.7.0(transitive)
- Removedtr46@0.0.3(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)