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

@victorenator/service-fetch

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@victorenator/service-fetch - npm Package Compare versions

Comparing version 0.1.0 to 1.0.0

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.0",
"type": "module",
"module": "index.js",
"description": "Fetch API",
"license": "MIT",
"homepage": "https://gitlab.com/victorenator/node-service-fetch",

@@ -10,15 +13,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');
```

Sorry, the diff of this file is not supported yet

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