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

presentation-service-server

Package Overview
Dependencies
Maintainers
5
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

presentation-service-server - npm Package Compare versions

Comparing version 2.0.15 to 2.0.16

53

lib/hydrateString.js

@@ -5,3 +5,2 @@ "use strict";

var R = require("ramda");
var restify = require("restify");

@@ -14,2 +13,6 @@ var hydrateString = R.curry((db, local, string) => {

if (R.isEmpty(local)) {
local.globalDefault = refs[0].def;
}
if (refs.length === 0) return hl([splits.join("")]);

@@ -30,4 +33,13 @@

if (!R.isNil(obj.def)) push(null, R.assoc("value", obj.def, obj));
else if (!R.isNil(local.globalDefault)) {
push({
"type": "DefaultAsKeyNotFound",
"message": local.globalDefault
});
}
else {
push(null, R.assoc("value", null, obj));
push({
"type": "KeyNotFound",
"message": obj.key + ' not available'
});
}

@@ -45,11 +57,7 @@ }

.map(hydrateProps)
// if the value doesnt exist, throw. Otherwise make sure is stringified
.map(obj => {
if (R.isNil(obj.value)) throw new restify.ResourceNotFoundError([obj.key].concat(obj.props).reverse().join(' of ') + ' not available');
else {
const value = R.is(String, obj.value) ? obj.value : JSON.stringify(obj.value);
if (obj.key === value) return "${" + value + "}";
local[obj.key] = value;
return value;
}
const value = R.is(String, obj.value) ? obj.value : JSON.stringify(obj.value);
if (obj.key === value) return "${" + value + "}";
local[obj.key] = value;
return value;
})

@@ -65,8 +73,13 @@ .reduce(splits, populateArrayWithValues)

if (obj.props.length) {
try {
return R.assoc("value", R.path(obj.props, JSON.parse(obj.value)), obj);
} catch (e) {
return obj;
const getJsonValue = x => R.path(obj.props, JSON.parse(x));
var value = R.tryCatch(getJsonValue, () => obj.value)(obj.value);
if(R.isNil(value)) {
throw {
"type": "KeyPropNotFound",
"message": [obj.key].concat(obj.props).reverse().join(' of ') + ' not available'
};
}
} else {
else return R.assoc("value", value, obj);
}
else {
return obj;

@@ -94,3 +107,6 @@ }

if (i > 25) {
throw new restify.InternalServerError('cycle detected');
throw {
"type": "CycleDetected",
"message": "Cycle Detected in " + obj.key
};
}

@@ -102,7 +118,2 @@ else if (R.has(obj.key, local)) {

}
else if (local[obj.key] === {}) {
// if the key has ben tested previously and doesn't exist don't test again
if (R.isNil(obj.def)) throw new restify.ResourceNotFoundError(obj.key + ' not available');
return obj.def;
}
else {

@@ -109,0 +120,0 @@ return obj;

@@ -38,3 +38,21 @@ "use strict";

.errors(logStreamExceptions(req))
.stopOnError(next)
.stopOnError(e => {
switch(e.type) {
case "DefaultAsKeyNotFound":
res.write(e.message);
res.end();
break;
case "KeyNotFound":
next(new restify.ResourceNotFoundError(e));
break;
case "KeyPropNotFound":
next(new restify.ResourceNotFoundError(e));
break;
case "CycleDetected":
next(new restify.ConflictError(e));
break;
default:
next(e);
}
})
.each(output => {

@@ -41,0 +59,0 @@ res.write(output);

{
"name": "presentation-service-server",
"version": "2.0.15",
"version": "2.0.16",
"description": "Server component for the presentation service",

@@ -5,0 +5,0 @@ "main": "server.js",

@@ -72,2 +72,12 @@ "use strict";

it('should not 404 when a default value is given', (done) => {
set('/v1/hello/world/defaults', "redundant string ${non_existent_ref}")
.pull(() => {
request
.get('/v1/hello/world/defaults;null')
.expect(200, "null")
.end(done);
})
});
it('should get string data saved in redis', (done) => {

@@ -74,0 +84,0 @@ set("/v1/hello/world", "my value").pull(() => {

@@ -54,7 +54,5 @@ "use strict";

.flatMap(hydrateKey({}, '${key}'))
.pull((err, data) => {
assert.notOk(data);
assert.ok(err, 'there is an error');
assert.ok(err.body, err);
assert.equal(err.statusCode, 404, 'it is a 404');
.pull((err) => {
assert.equal(err.message, "key not available");
assert.equal(err.type, "KeyNotFound", 'it is a 404');
done()

@@ -88,2 +86,13 @@ })

it('should handle nested default values correctly', (done) => {
deleteAndSetDb("setKey", ["key", "asdf ${not_here}"])
.flatMap(db.delKey("area"))
.flatMap(hydrateKey({}, '${key;null}'))
.pull((err, res) => {
assert.equal(err.type, "DefaultAsKeyNotFound");
assert.equal(err.message, "null");
done();
})
});
it('should deep hydrate values which contain ${ref}', (done) => {

@@ -190,6 +199,4 @@ deleteAndSetDb("setKey", ["key", "welcome to ${area}"])

.pull((err, data) => {
assert.notOk(data);
assert.ok(err, 'there is an error');
assert.ok(err.body, err);
assert.equal(err.statusCode, 404, 'it is a 404');
assert.equal(err.message, "one of area not available");
assert.equal(err.type, "KeyPropNotFound", 'it is a 404');
done()

@@ -229,6 +236,4 @@ })

.pull((err, data) => {
assert.notOk(data);
assert.ok(err, 'there is an error');
assert.ok(err.body, 'it is a HttpError');
assert.notEqual(err.statusCode, 200, 'it is an error');
assert.equal(err.message, 'Cycle Detected in key');
assert.equal(err.type, "CycleDetected", 'it is an error');
done()

@@ -244,5 +249,4 @@ })

assert.notOk(data);
assert.ok(err, 'there is an error');
assert.ok(err.body, 'it is a HttpError');
assert.notEqual(err.statusCode, 200, 'it is an error');
assert.equal(err.message, 'Cycle Detected in key');
assert.equal(err.type, "CycleDetected", 'it is an error');
done()

@@ -249,0 +253,0 @@ })

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