From 2911f084d499cdbd123ec1cba91e996f9cd48270 Mon Sep 17 00:00:00 2001
From: Dmitriy Voeykov <dmitriyv@pushok.com>
Date: Tue, 23 Aug 2016 21:05:07 +0300
Subject: [PATCH 1/5] Change behavior for receive params through restapi from
 plain object to stringified object

---
 index.js | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/index.js b/index.js
index 8c2c457..c043ccd 100644
--- a/index.js
+++ b/index.js
@@ -120,11 +120,11 @@ module.exports.restapi = function () {
 				if (!ctx.api[req.params.module][req.params.target])
 					throw new Error("No function available");
 
-				var params = (req.method == 'POST')?req.body:req.query;
-
+				var params = req.method == 'POST'?req.body:req.query;
+				if(params._t_jsonq)
+					params = JSON.parse(params._t_jsonq)
 				if (params._t_son=='in' || params._t_son=='both')
 					params = ctx.api.tson.decode(params);
-
 				ctx.api[req.params.module][req.params.target](req.params.token, params, safe.sure(next, function (result) {
 					if (params._t_son=='out' || params._t_son=='both')
 						result = ctx.api.tson.encode(result);
-- 
GitLab


From 2714f445263a6a8f4f977c643fdc55b2543e3a0e Mon Sep 17 00:00:00 2001
From: Dmitriy Voeykov <dmitriyv@pushok.com>
Date: Tue, 23 Aug 2016 21:06:00 +0300
Subject: [PATCH 2/5] hotfix for missing var

---
 index.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/index.js b/index.js
index c043ccd..3c58e93 100644
--- a/index.js
+++ b/index.js
@@ -390,7 +390,7 @@ module.exports.mongocache = function () {
 	var safeKey = function (key) {
 		var sKey = key.toString();
 		if (sKey.length>512) {
-			md5sum = crypto.createHash('md5');
+			var md5sum = crypto.createHash('md5');
 			md5sum.update(sKey);
 			sKey = md5sum.digest('hex');
 		}
-- 
GitLab


From 4903a4388f0f70a345324f789b72dc13004976aa Mon Sep 17 00:00:00 2001
From: Alexander Fediakin <alexf@pushok.com>
Date: Mon, 26 Sep 2016 18:41:24 +0300
Subject: [PATCH 3/5] adds obac.getRegistered function to fetch list of
 registered actions

---
 index.js | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/index.js b/index.js
index 3c58e93..3d27020 100644
--- a/index.js
+++ b/index.js
@@ -334,6 +334,9 @@ module.exports.obac = function () {
 						_.each(actions, function (a) {
 							_acl.push({m:module, f:face, r:new RegExp(a.replace("*",".*"))});
 						});
+					},
+					getRegistered:function(t, p, cb){
+						cb(null, _.cloneDeep(_acl));
 					}
 				}
 			});
-- 
GitLab


From 866bb973aad8742e1de00f9ad5a63e211f434b1f Mon Sep 17 00:00:00 2001
From: Sergey Korotkov <sergey@pushok.com>
Date: Mon, 3 Oct 2016 09:54:43 -0300
Subject: [PATCH 4/5] Move express instrumentation to each specific module
 leverl

---
 index.js | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/index.js b/index.js
index 3c58e93..df89e78 100644
--- a/index.js
+++ b/index.js
@@ -50,17 +50,21 @@ module.exports.createApp = function (cfg, cb) {
 		req.setMaxListeners(20);
 		next();
 	});
-	app.use(require("compression")());
-	app.use(cookieParser());
-	app.use(bodyParser.json({ limit: cfg.config.app.postLimit || "20mb" }));
-	app.use(bodyParser.raw({ limit: cfg.config.app.postLimit || "50mb" })); // to parse getsentry "application/octet-stream" requests
-	app.use(bodyParser.urlencoded({ extended: true, limit: cfg.config.app.postLimit || "20mb"}));
-	app.use(multer());
+	function instrumentExpress(app) {
+		app.use(require("compression")());
+		app.use(cookieParser());
+		app.use(bodyParser.json({ limit: cfg.config.app.postLimit || "20mb" }));
+		app.use(bodyParser.text({ limit: cfg.config.app.postLimit || "20mb" }));
+		app.use(bodyParser.raw({ limit: cfg.config.app.postLimit || "50mb" })); // to parse getsentry "application/octet-stream" requests
+		app.use(bodyParser.urlencoded({ extended: true, limit: cfg.config.app.postLimit || "20mb"}));
+		app.use(multer());
+	};
 	var api = {};
 	var locals = {};
 	var auto = {};
 	var registered = {};
 	var requested = {};
+	var defaults = cfg.defaults || {};
 
 	_.each(cfg.modules, function (module) {
 		registered[module.name]=1;
@@ -78,11 +82,15 @@ module.exports.createApp = function (cfg, cb) {
 		_.each(args, function (m) {
 			requested[m]=1;
 		});
+		var reqs = _.defaults(mod.reqs || {}, ((cfg.defaults || {}).module || {}).reqs || {}, {router:false, globalUse:false});
 		args.push(function (cb) {
 			var router = null;
-			if (!mod.reqs || mod.reqs.router!==false) {
+			if (reqs.router) {
 				router = express.Router();
 				app.use("/"+module.name,router);
+				if (reqs.globalUse) {
+					instrumentExpress(router);
+				}
 			}
 			var dt = new Date();
 			mod.init({api:api,locals:locals,cfg:cfg.config,app:this,express:app,router:router}, safe.sure(cb, function (mobj) {
-- 
GitLab


From 1733337bd6ae25da5dea6347425bcf2bfab5d939 Mon Sep 17 00:00:00 2001
From: Dmitriy Voeykov <dmitriyv@pushok.com>
Date: Thu, 3 Nov 2016 21:21:29 +0300
Subject: [PATCH 5/5] transplante Fixed for safe v4

---
 index.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/index.js b/index.js
index cbb2146..4391006 100644
--- a/index.js
+++ b/index.js
@@ -294,7 +294,7 @@ module.exports.obac = function () {
 					},
 					getPermissions:function (t, p, cb) {
 						var result = {};
-						safe.forEachOf(p.rules, function (rule, cb) {
+						safe.eachOf(p.rules, function (rule, key, cb) {
 							var acl = _.filter(_acl, function (a) {
 								return a.r.test(rule.action);
 							});
-- 
GitLab