New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

sparc-commons

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sparc-commons - npm Package Compare versions

Comparing version 0.2.19 to 0.2.20

38

libs/resources.js

@@ -5,19 +5,14 @@ /*jshint multistr: true */

var config = require('config')
var confResource = config.get('resource')
var resources = {},
confResource = config.get('resource');
var resources = _.reduce(confResource, (acc, v, k) => {
_.set(acc, k, _.omit(v, 'uri'))
_.forOwn(confResource, function(v, k) {
// uri field is treated as a container of services and their properties
resources[k] = _.omit(v, 'uri');
var uri = _.get(v, 'uri', {});
_.forOwn(uri, function(uriField, uriKey) {
_.forOwn(v.uri, function(uriField, uriKey) {
// TODO: if uriField is an object, it means that the service has a multiplicity of properties
_.set(resources, k + '.' + uriKey, uriField);
_.set(acc, `${k}.${uriKey}`, uriField);
});
return acc
}, {})
// TODO: add templating management
// TODO: add certificates to the picture. Both this and the latter properties imply reading files
});

@@ -47,4 +42,9 @@ var parseQuery = params => {

if (_.isUndefined(service)) {
throw new Error('Resource invoked with undefined service parameter for resource ' + target);
throw new Error(`Resource ${resource} invoked with undefined service parameter`)
}
if(!_.has(resources[target], service)){
throw Error(`Resource ${target} has no service ${service}`)
}
var options = opts || {}

@@ -62,2 +62,12 @@

var headers = {}
var requestOpts = _.get(opts, 'request', {})
if(requestOpts.header){
//request options headers have precedence over the ones specified in the
//configuration file
_.merge(headers, _.get(resource, 'headers', {}), requestOpts.headers)
} else {
_.set(requestOpts, 'headers', headers)
}
if (requestStream) {

@@ -78,3 +88,3 @@ // in this case all data options are brutally added to the url.

data,
_.get(opts, 'request', {}),
requestOpts,
function(err, resp) {

@@ -81,0 +91,0 @@ if (err) {

{
"name": "sparc-commons",
"version": "0.2.19",
"version": "0.2.20",
"description": "Library with all small time common stuff used across the SPARC echosystem",

@@ -10,4 +10,4 @@ "main": "index.js",

"scripts": {
"test:debug": "export NODE_CONFIG_DIR=./test/config && mocha --debug-brk",
"test": "export NODE_CONFIG_DIR=./test/config && mocha"
"test:debug": "export NODE_ENV=test && export NODE_CONFIG_DIR=./test/config && mocha --debug-brk",
"test": "export NODE_ENV=test && export NODE_CONFIG_DIR=./test/config && mocha"
},

@@ -14,0 +14,0 @@ "author": "Emanuele Francioni <emanuele@gosparc.com> (http://gosparc.com)",

{
"version": "0.2.4",
"external-resource-timeout": 6000,
"environment": "vm",
"logging": {

@@ -20,76 +16,3 @@ "appenders": [

"replaceConsole": false
},
"device_server": {
"port": 7001,
"cache": {
"target": "/tmp/routecache.db"
},
"dispatcher": {
"parking": "http://localhost:8000/parking"
}
},
"test_server": {
"port": 7002
},
"web_server": {
"port": 8080
},
"services": {
"route-tracker": {
"allowed-distance-on-start-km": 0.4
},
"route-correction": {
"enabled": true,
"interval-millis": 300000,
"max-batch-size": 20,
"route-point-batch-size": 10,
"max-routepoint-interval-millis": 1080000 //18 minutes of max interval between routepoints before splitting routes
}
},
//TODO: hook this up in a http making library
"resource": {
"default": {
"request": {
"timeout": 3000
}
},
"beestar": {
"method": "get",
"url": "http://hq.beestar.eu:8080",
"uri": {
"reverse-geocoding": "reverse.php"
}
},
"trackmatch": {
"method": "post",
"url": "http://test.roadmatching.com/rest",
"uri": {
"correction-service": "mapmatch/"
},
"api-params": {
"app_key": "67ea88d046968a417c87ead1dbaec738",
"app_id": "7a3946af"
}
},
"test_resource": {
"method": "get",
"url": "http://bogus.com",
"uri": {
"boguservice": "bellobell",
"boguservice2": "gallogall"
},
"api-params": {
"apikey": "asdfg"
}
}
}
}

@@ -14,4 +14,20 @@ {

}
},
"test_resource_header": {
"method": "get",
"headers": {
"Accept": "application/json",
"X-App-Token": "pippo"
},
"url": "http://bogus.com",
"uri": {
"boguservice": "bellobell",
"boguservice2": "gallogall"
},
"api-params": {
"apikey": "asdfg"
}
}
}
}

@@ -57,2 +57,31 @@ var nock = require('nock');

})
it("Test resource header", () => {
nock(
"http://bogus.com",
{
reqheaders: {
"Accept": "application/json",
"X-App-Token": "pippo"
}
})
.get("/bellobell")
.query({
apikey: "asdfg",
paperino: 'topolino'
})
.reply(200, "Hallo");
return requestResource("test_resource_header", "boguservice", {
query: {
pippo: 'pluto'
},
data: {
paperino: 'topolino'
}
})
.then(function(result){
assert.equal("Hallo", result);
});
})
})
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