Socket
Socket
Sign inDemoInstall

@condor-labs/ec-events-gateway

Package Overview
Dependencies
47
Maintainers
5
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.1.0

coverage/lcov-report/events/events.js.html

8

coverage/coverage-final.json

@@ -1,3 +0,7 @@

{"/Users/hjimenez/Projects/GitHub/ec-applications/ec-events-gateway-client/events/events.js": {"path":"/Users/hjimenez/Projects/GitHub/ec-applications/ec-events-gateway-client/events/events.js","statementMap":{"0":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}},"1":{"start":{"line":3,"column":14},"end":{"line":3,"column":30}},"2":{"start":{"line":4,"column":30},"end":{"line":4,"column":41}},"3":{"start":{"line":5,"column":21},"end":{"line":5,"column":42}},"4":{"start":{"line":7,"column":13},"end":{"line":21,"column":1}},"5":{"start":{"line":8,"column":2},"end":{"line":20,"column":3}},"6":{"start":{"line":9,"column":19},"end":{"line":9,"column":33}},"7":{"start":{"line":11,"column":4},"end":{"line":17,"column":5}},"8":{"start":{"line":12,"column":6},"end":{"line":12,"column":20}},"9":{"start":{"line":14,"column":6},"end":{"line":16,"column":9}},"10":{"start":{"line":19,"column":4},"end":{"line":19,"column":23}},"11":{"start":{"line":23,"column":0},"end":{"line":25,"column":2}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":7,"column":13},"end":{"line":7,"column":14}},"loc":{"start":{"line":7,"column":29},"end":{"line":21,"column":1}},"line":7}},"branchMap":{"0":{"loc":{"start":{"line":11,"column":4},"end":{"line":17,"column":5}},"type":"if","locations":[{"start":{"line":11,"column":4},"end":{"line":17,"column":5}},{"start":{"line":11,"column":4},"end":{"line":17,"column":5}}],"line":11}},"s":{"0":1,"1":1,"2":1,"3":1,"4":1,"5":2,"6":2,"7":2,"8":1,"9":1,"10":0,"11":1},"f":{"0":2},"b":{"0":[1,1]},"_coverageSchema":"43e27e138ebf9cfc5966b082cf9a028302ed4184","hash":"20df598defa97b386ec9a63630ae973c30bd832b"}
,"/Users/hjimenez/Projects/GitHub/ec-applications/ec-events-gateway-client/events/validate.js": {"path":"/Users/hjimenez/Projects/GitHub/ec-applications/ec-events-gateway-client/events/validate.js","statementMap":{"0":{"start":{"line":1,"column":12},"end":{"line":1,"column":26}},"1":{"start":{"line":3,"column":15},"end":{"line":29,"column":2}},"2":{"start":{"line":31,"column":17},"end":{"line":44,"column":1}},"3":{"start":{"line":32,"column":2},"end":{"line":41,"column":3}},"4":{"start":{"line":33,"column":20},"end":{"line":33,"column":40}},"5":{"start":{"line":34,"column":15},"end":{"line":34,"column":56}},"6":{"start":{"line":36,"column":4},"end":{"line":36,"column":60}},"7":{"start":{"line":36,"column":18},"end":{"line":36,"column":60}},"8":{"start":{"line":38,"column":23},"end":{"line":38,"column":49}},"9":{"start":{"line":40,"column":4},"end":{"line":40,"column":62}},"10":{"start":{"line":43,"column":2},"end":{"line":43,"column":46}},"11":{"start":{"line":46,"column":0},"end":{"line":48,"column":2}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":31,"column":17},"end":{"line":31,"column":18}},"loc":{"start":{"line":31,"column":33},"end":{"line":44,"column":1}},"line":31}},"branchMap":{"0":{"loc":{"start":{"line":32,"column":2},"end":{"line":41,"column":3}},"type":"if","locations":[{"start":{"line":32,"column":2},"end":{"line":41,"column":3}},{"start":{"line":32,"column":2},"end":{"line":41,"column":3}}],"line":32},"1":{"loc":{"start":{"line":36,"column":4},"end":{"line":36,"column":60}},"type":"if","locations":[{"start":{"line":36,"column":4},"end":{"line":36,"column":60}},{"start":{"line":36,"column":4},"end":{"line":36,"column":60}}],"line":36},"2":{"loc":{"start":{"line":40,"column":11},"end":{"line":40,"column":61}},"type":"cond-expr","locations":[{"start":{"line":40,"column":30},"end":{"line":40,"column":54}},{"start":{"line":40,"column":57},"end":{"line":40,"column":61}}],"line":40}},"s":{"0":2,"1":2,"2":2,"3":3,"4":2,"5":2,"6":2,"7":1,"8":1,"9":1,"10":1,"11":2},"f":{"0":3},"b":{"0":[2,1],"1":[1,1],"2":[0,1]},"_coverageSchema":"43e27e138ebf9cfc5966b082cf9a028302ed4184","hash":"b9928693409bfd5d00120640c581fe5b5718c137"}
{"/Users/hjimenez/Projects/GitHub/ec-applications/ec-events-gateway-client/src/events/events.js": {"path":"/Users/hjimenez/Projects/GitHub/ec-applications/ec-events-gateway-client/src/events/events.js","statementMap":{"0":{"start":{"line":1,"column":14},"end":{"line":1,"column":30}},"1":{"start":{"line":2,"column":17},"end":{"line":2,"column":48}},"2":{"start":{"line":3,"column":15},"end":{"line":3,"column":35}},"3":{"start":{"line":4,"column":16},"end":{"line":4,"column":35}},"4":{"start":{"line":5,"column":44},"end":{"line":5,"column":73}},"5":{"start":{"line":7,"column":13},"end":{"line":51,"column":1}},"6":{"start":{"line":15,"column":2},"end":{"line":50,"column":3}},"7":{"start":{"line":17,"column":17},"end":{"line":21,"column":5}},"8":{"start":{"line":23,"column":17},"end":{"line":23,"column":54}},"9":{"start":{"line":25,"column":4},"end":{"line":25,"column":30}},"10":{"start":{"line":25,"column":16},"end":{"line":25,"column":30}},"11":{"start":{"line":27,"column":28},"end":{"line":27,"column":65}},"12":{"start":{"line":29,"column":4},"end":{"line":29,"column":57}},"13":{"start":{"line":29,"column":26},"end":{"line":29,"column":57}},"14":{"start":{"line":30,"column":26},"end":{"line":30,"column":51}},"15":{"start":{"line":32,"column":4},"end":{"line":32,"column":50}},"16":{"start":{"line":34,"column":4},"end":{"line":34,"column":30}},"17":{"start":{"line":34,"column":16},"end":{"line":34,"column":30}},"18":{"start":{"line":36,"column":21},"end":{"line":38,"column":6}},"19":{"start":{"line":40,"column":4},"end":{"line":40,"column":20}},"20":{"start":{"line":42,"column":19},"end":{"line":42,"column":58}},"21":{"start":{"line":43,"column":4},"end":{"line":49,"column":6}},"22":{"start":{"line":53,"column":0},"end":{"line":55,"column":2}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":7,"column":13},"end":{"line":7,"column":14}},"loc":{"start":{"line":14,"column":6},"end":{"line":51,"column":1}},"line":14}},"branchMap":{"0":{"loc":{"start":{"line":11,"column":2},"end":{"line":11,"column":12}},"type":"default-arg","locations":[{"start":{"line":11,"column":8},"end":{"line":11,"column":12}}],"line":11},"1":{"loc":{"start":{"line":12,"column":2},"end":{"line":12,"column":14}},"type":"default-arg","locations":[{"start":{"line":12,"column":12},"end":{"line":12,"column":14}}],"line":12},"2":{"loc":{"start":{"line":13,"column":2},"end":{"line":13,"column":15}},"type":"default-arg","locations":[{"start":{"line":13,"column":11},"end":{"line":13,"column":15}}],"line":13},"3":{"loc":{"start":{"line":25,"column":4},"end":{"line":25,"column":30}},"type":"if","locations":[{"start":{"line":25,"column":4},"end":{"line":25,"column":30}},{"start":{"line":25,"column":4},"end":{"line":25,"column":30}}],"line":25},"4":{"loc":{"start":{"line":27,"column":28},"end":{"line":27,"column":65}},"type":"binary-expr","locations":[{"start":{"line":27,"column":28},"end":{"line":27,"column":58}},{"start":{"line":27,"column":62},"end":{"line":27,"column":65}}],"line":27},"5":{"loc":{"start":{"line":29,"column":4},"end":{"line":29,"column":57}},"type":"if","locations":[{"start":{"line":29,"column":4},"end":{"line":29,"column":57}},{"start":{"line":29,"column":4},"end":{"line":29,"column":57}}],"line":29},"6":{"loc":{"start":{"line":34,"column":4},"end":{"line":34,"column":30}},"type":"if","locations":[{"start":{"line":34,"column":4},"end":{"line":34,"column":30}},{"start":{"line":34,"column":4},"end":{"line":34,"column":30}}],"line":34}},"s":{"0":1,"1":1,"2":1,"3":1,"4":1,"5":1,"6":10,"7":10,"8":10,"9":8,"10":1,"11":7,"12":7,"13":1,"14":6,"15":6,"16":6,"17":1,"18":5,"19":5,"20":2,"21":2,"22":1},"f":{"0":10},"b":{"0":[8],"1":[10],"2":[10],"3":[1,7],"4":[7,1],"5":[1,6],"6":[1,5]},"_coverageSchema":"43e27e138ebf9cfc5966b082cf9a028302ed4184","hash":"7cdafa12ac4a0cccb4c0ef24f2c847bbba328c85"}
,"/Users/hjimenez/Projects/GitHub/ec-applications/ec-events-gateway-client/src/logger/index.js": {"path":"/Users/hjimenez/Projects/GitHub/ec-applications/ec-events-gateway-client/src/logger/index.js","statementMap":{"0":{"start":{"line":1,"column":15},"end":{"line":1,"column":34}},"1":{"start":{"line":2,"column":0},"end":{"line":2,"column":24}}},"fnMap":{},"branchMap":{},"s":{"0":2,"1":2},"f":{},"b":{},"_coverageSchema":"43e27e138ebf9cfc5966b082cf9a028302ed4184","hash":"c548245a26806ca0c971f8d46f92f9dd687d9963"}
,"/Users/hjimenez/Projects/GitHub/ec-applications/ec-events-gateway-client/src/logger/logger.js": {"path":"/Users/hjimenez/Projects/GitHub/ec-applications/ec-events-gateway-client/src/logger/logger.js","statementMap":{"0":{"start":{"line":1,"column":16},"end":{"line":1,"column":34}},"1":{"start":{"line":2,"column":11},"end":{"line":2,"column":24}},"2":{"start":{"line":4,"column":20},"end":{"line":24,"column":1}},"3":{"start":{"line":5,"column":2},"end":{"line":23,"column":3}},"4":{"start":{"line":6,"column":4},"end":{"line":6,"column":48}},"5":{"start":{"line":7,"column":19},"end":{"line":19,"column":6}},"6":{"start":{"line":20,"column":4},"end":{"line":20,"column":35}},"7":{"start":{"line":22,"column":4},"end":{"line":22,"column":33}},"8":{"start":{"line":26,"column":27},"end":{"line":35,"column":1}},"9":{"start":{"line":27,"column":2},"end":{"line":34,"column":3}},"10":{"start":{"line":28,"column":18},"end":{"line":28,"column":43}},"11":{"start":{"line":29,"column":4},"end":{"line":31,"column":5}},"12":{"start":{"line":30,"column":6},"end":{"line":30,"column":31}},"13":{"start":{"line":33,"column":4},"end":{"line":33,"column":33}},"14":{"start":{"line":37,"column":21},"end":{"line":37,"column":56}},"15":{"start":{"line":39,"column":0},"end":{"line":39,"column":30}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":4,"column":20},"end":{"line":4,"column":21}},"loc":{"start":{"line":4,"column":71},"end":{"line":24,"column":1}},"line":4},"1":{"name":"(anonymous_1)","decl":{"start":{"line":26,"column":27},"end":{"line":26,"column":28}},"loc":{"start":{"line":26,"column":41},"end":{"line":35,"column":1}},"line":26}},"branchMap":{"0":{"loc":{"start":{"line":11,"column":18},"end":{"line":18,"column":11}},"type":"cond-expr","locations":[{"start":{"line":12,"column":10},"end":{"line":12,"column":12}},{"start":{"line":13,"column":10},"end":{"line":18,"column":11}}],"line":11},"1":{"loc":{"start":{"line":29,"column":4},"end":{"line":31,"column":5}},"type":"if","locations":[{"start":{"line":29,"column":4},"end":{"line":31,"column":5}},{"start":{"line":29,"column":4},"end":{"line":31,"column":5}}],"line":29}},"s":{"0":2,"1":2,"2":2,"3":4,"4":4,"5":4,"6":3,"7":1,"8":2,"9":3,"10":3,"11":2,"12":2,"13":1,"14":2,"15":2},"f":{"0":4,"1":3},"b":{"0":[4,0],"1":[2,0]},"_coverageSchema":"43e27e138ebf9cfc5966b082cf9a028302ed4184","hash":"127534633fd215f520b09e42b7a3c12a02657c45"}
,"/Users/hjimenez/Projects/GitHub/ec-applications/ec-events-gateway-client/src/utils/constants.js": {"path":"/Users/hjimenez/Projects/GitHub/ec-applications/ec-events-gateway-client/src/utils/constants.js","statementMap":{"0":{"start":{"line":1,"column":0},"end":{"line":20,"column":2}},"1":{"start":{"line":12,"column":4},"end":{"line":12,"column":52}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":11,"column":18},"end":{"line":11,"column":19}},"loc":{"start":{"line":11,"column":29},"end":{"line":13,"column":3}},"line":11}},"branchMap":{},"s":{"0":3,"1":1},"f":{"0":1},"b":{},"_coverageSchema":"43e27e138ebf9cfc5966b082cf9a028302ed4184","hash":"f4d6b088e706d69e85152a0ba555cb90386f62dd"}
,"/Users/hjimenez/Projects/GitHub/ec-applications/ec-events-gateway-client/src/validate/index.js": {"path":"/Users/hjimenez/Projects/GitHub/ec-applications/ec-events-gateway-client/src/validate/index.js","statementMap":{"0":{"start":{"line":1,"column":17},"end":{"line":1,"column":38}},"1":{"start":{"line":2,"column":0},"end":{"line":2,"column":26}}},"fnMap":{},"branchMap":{},"s":{"0":2,"1":2},"f":{},"b":{},"_coverageSchema":"43e27e138ebf9cfc5966b082cf9a028302ed4184","hash":"4f66abd84ae8b634b510e69328eab5a485062a33"}
,"/Users/hjimenez/Projects/GitHub/ec-applications/ec-events-gateway-client/src/validate/validate.js": {"path":"/Users/hjimenez/Projects/GitHub/ec-applications/ec-events-gateway-client/src/validate/validate.js","statementMap":{"0":{"start":{"line":1,"column":12},"end":{"line":1,"column":32}},"1":{"start":{"line":2,"column":18},"end":{"line":2,"column":47}},"2":{"start":{"line":11,"column":4},"end":{"line":11,"column":13}},"3":{"start":{"line":13,"column":21},"end":{"line":34,"column":1}},"4":{"start":{"line":14,"column":2},"end":{"line":33,"column":3}},"5":{"start":{"line":15,"column":20},"end":{"line":15,"column":40}},"6":{"start":{"line":16,"column":15},"end":{"line":16,"column":56}},"7":{"start":{"line":18,"column":4},"end":{"line":23,"column":5}},"8":{"start":{"line":19,"column":6},"end":{"line":22,"column":8}},"9":{"start":{"line":24,"column":4},"end":{"line":27,"column":6}},"10":{"start":{"line":29,"column":4},"end":{"line":32,"column":6}},"11":{"start":{"line":36,"column":17},"end":{"line":51,"column":1}},"12":{"start":{"line":37,"column":2},"end":{"line":50,"column":3}},"13":{"start":{"line":38,"column":4},"end":{"line":38,"column":30}},"14":{"start":{"line":38,"column":17},"end":{"line":38,"column":30}},"15":{"start":{"line":40,"column":17},"end":{"line":40,"column":36}},"16":{"start":{"line":41,"column":4},"end":{"line":41,"column":40}},"17":{"start":{"line":41,"column":27},"end":{"line":41,"column":40}},"18":{"start":{"line":43,"column":16},"end":{"line":43,"column":23}},"19":{"start":{"line":44,"column":4},"end":{"line":44,"column":54}},"20":{"start":{"line":44,"column":41},"end":{"line":44,"column":54}},"21":{"start":{"line":45,"column":4},"end":{"line":45,"column":41}},"22":{"start":{"line":45,"column":28},"end":{"line":45,"column":41}},"23":{"start":{"line":47,"column":4},"end":{"line":47,"column":16}},"24":{"start":{"line":49,"column":4},"end":{"line":49,"column":17}},"25":{"start":{"line":53,"column":23},"end":{"line":63,"column":1}},"26":{"start":{"line":54,"column":2},"end":{"line":62,"column":3}},"27":{"start":{"line":55,"column":20},"end":{"line":55,"column":57}},"28":{"start":{"line":56,"column":4},"end":{"line":58,"column":5}},"29":{"start":{"line":57,"column":6},"end":{"line":57,"column":39}},"30":{"start":{"line":59,"column":4},"end":{"line":59,"column":19}},"31":{"start":{"line":61,"column":4},"end":{"line":61,"column":51}},"32":{"start":{"line":65,"column":23},"end":{"line":96,"column":1}},"33":{"start":{"line":66,"column":2},"end":{"line":95,"column":3}},"34":{"start":{"line":67,"column":4},"end":{"line":67,"column":50}},"35":{"start":{"line":67,"column":15},"end":{"line":67,"column":50}},"36":{"start":{"line":69,"column":17},"end":{"line":73,"column":5}},"37":{"start":{"line":75,"column":4},"end":{"line":88,"column":5}},"38":{"start":{"line":76,"column":21},"end":{"line":76,"column":64}},"39":{"start":{"line":77,"column":6},"end":{"line":77,"column":48}},"40":{"start":{"line":77,"column":34},"end":{"line":77,"column":48}},"41":{"start":{"line":79,"column":6},"end":{"line":87,"column":8}},"42":{"start":{"line":90,"column":23},"end":{"line":90,"column":68}},"43":{"start":{"line":92,"column":4},"end":{"line":92,"column":76}},"44":{"start":{"line":94,"column":4},"end":{"line":94,"column":51}},"45":{"start":{"line":98,"column":21},"end":{"line":123,"column":1}},"46":{"start":{"line":99,"column":2},"end":{"line":122,"column":3}},"47":{"start":{"line":100,"column":19},"end":{"line":110,"column":5}},"48":{"start":{"line":112,"column":4},"end":{"line":112,"column":50}},"49":{"start":{"line":112,"column":15},"end":{"line":112,"column":50}},"50":{"start":{"line":113,"column":19},"end":{"line":113,"column":52}},"51":{"start":{"line":115,"column":4},"end":{"line":115,"column":65}},"52":{"start":{"line":115,"column":32},"end":{"line":115,"column":65}},"53":{"start":{"line":117,"column":23},"end":{"line":117,"column":68}},"54":{"start":{"line":119,"column":4},"end":{"line":119,"column":76}},"55":{"start":{"line":121,"column":4},"end":{"line":121,"column":51}},"56":{"start":{"line":125,"column":19},"end":{"line":133,"column":1}},"57":{"start":{"line":126,"column":18},"end":{"line":130,"column":3}},"58":{"start":{"line":132,"column":2},"end":{"line":132,"column":17}},"59":{"start":{"line":135,"column":23},"end":{"line":142,"column":1}},"60":{"start":{"line":144,"column":0},"end":{"line":144,"column":32}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":13,"column":21},"end":{"line":13,"column":22}},"loc":{"start":{"line":13,"column":29},"end":{"line":34,"column":1}},"line":13},"1":{"name":"(anonymous_1)","decl":{"start":{"line":36,"column":17},"end":{"line":36,"column":18}},"loc":{"start":{"line":36,"column":27},"end":{"line":51,"column":1}},"line":36},"2":{"name":"(anonymous_2)","decl":{"start":{"line":53,"column":23},"end":{"line":53,"column":24}},"loc":{"start":{"line":53,"column":39},"end":{"line":63,"column":1}},"line":53},"3":{"name":"(anonymous_3)","decl":{"start":{"line":65,"column":23},"end":{"line":65,"column":24}},"loc":{"start":{"line":65,"column":54},"end":{"line":96,"column":1}},"line":65},"4":{"name":"(anonymous_4)","decl":{"start":{"line":98,"column":21},"end":{"line":98,"column":22}},"loc":{"start":{"line":98,"column":29},"end":{"line":123,"column":1}},"line":98},"5":{"name":"(anonymous_5)","decl":{"start":{"line":125,"column":19},"end":{"line":125,"column":20}},"loc":{"start":{"line":125,"column":27},"end":{"line":133,"column":1}},"line":125}},"branchMap":{"0":{"loc":{"start":{"line":18,"column":4},"end":{"line":23,"column":5}},"type":"if","locations":[{"start":{"line":18,"column":4},"end":{"line":23,"column":5}},{"start":{"line":18,"column":4},"end":{"line":23,"column":5}}],"line":18},"1":{"loc":{"start":{"line":38,"column":4},"end":{"line":38,"column":30}},"type":"if","locations":[{"start":{"line":38,"column":4},"end":{"line":38,"column":30}},{"start":{"line":38,"column":4},"end":{"line":38,"column":30}}],"line":38},"2":{"loc":{"start":{"line":41,"column":4},"end":{"line":41,"column":40}},"type":"if","locations":[{"start":{"line":41,"column":4},"end":{"line":41,"column":40}},{"start":{"line":41,"column":4},"end":{"line":41,"column":40}}],"line":41},"3":{"loc":{"start":{"line":44,"column":4},"end":{"line":44,"column":54}},"type":"if","locations":[{"start":{"line":44,"column":4},"end":{"line":44,"column":54}},{"start":{"line":44,"column":4},"end":{"line":44,"column":54}}],"line":44},"4":{"loc":{"start":{"line":45,"column":4},"end":{"line":45,"column":41}},"type":"if","locations":[{"start":{"line":45,"column":4},"end":{"line":45,"column":41}},{"start":{"line":45,"column":4},"end":{"line":45,"column":41}}],"line":45},"5":{"loc":{"start":{"line":56,"column":4},"end":{"line":58,"column":5}},"type":"if","locations":[{"start":{"line":56,"column":4},"end":{"line":58,"column":5}},{"start":{"line":56,"column":4},"end":{"line":58,"column":5}}],"line":56},"6":{"loc":{"start":{"line":65,"column":30},"end":{"line":65,"column":49}},"type":"default-arg","locations":[{"start":{"line":65,"column":45},"end":{"line":65,"column":49}}],"line":65},"7":{"loc":{"start":{"line":67,"column":4},"end":{"line":67,"column":50}},"type":"if","locations":[{"start":{"line":67,"column":4},"end":{"line":67,"column":50}},{"start":{"line":67,"column":4},"end":{"line":67,"column":50}}],"line":67},"8":{"loc":{"start":{"line":75,"column":4},"end":{"line":88,"column":5}},"type":"if","locations":[{"start":{"line":75,"column":4},"end":{"line":88,"column":5}},{"start":{"line":75,"column":4},"end":{"line":88,"column":5}}],"line":75},"9":{"loc":{"start":{"line":77,"column":6},"end":{"line":77,"column":48}},"type":"if","locations":[{"start":{"line":77,"column":6},"end":{"line":77,"column":48}},{"start":{"line":77,"column":6},"end":{"line":77,"column":48}}],"line":77},"10":{"loc":{"start":{"line":77,"column":10},"end":{"line":77,"column":32}},"type":"binary-expr","locations":[{"start":{"line":77,"column":10},"end":{"line":77,"column":16}},{"start":{"line":77,"column":20},"end":{"line":77,"column":32}}],"line":77},"11":{"loc":{"start":{"line":92,"column":11},"end":{"line":92,"column":75}},"type":"cond-expr","locations":[{"start":{"line":92,"column":44},"end":{"line":92,"column":68}},{"start":{"line":92,"column":71},"end":{"line":92,"column":75}}],"line":92},"12":{"loc":{"start":{"line":92,"column":11},"end":{"line":92,"column":41}},"type":"binary-expr","locations":[{"start":{"line":92,"column":11},"end":{"line":92,"column":21}},{"start":{"line":92,"column":25},"end":{"line":92,"column":41}}],"line":92},"13":{"loc":{"start":{"line":112,"column":4},"end":{"line":112,"column":50}},"type":"if","locations":[{"start":{"line":112,"column":4},"end":{"line":112,"column":50}},{"start":{"line":112,"column":4},"end":{"line":112,"column":50}}],"line":112},"14":{"loc":{"start":{"line":115,"column":4},"end":{"line":115,"column":65}},"type":"if","locations":[{"start":{"line":115,"column":4},"end":{"line":115,"column":65}},{"start":{"line":115,"column":4},"end":{"line":115,"column":65}}],"line":115},"15":{"loc":{"start":{"line":115,"column":8},"end":{"line":115,"column":30}},"type":"binary-expr","locations":[{"start":{"line":115,"column":8},"end":{"line":115,"column":14}},{"start":{"line":115,"column":18},"end":{"line":115,"column":30}}],"line":115},"16":{"loc":{"start":{"line":119,"column":11},"end":{"line":119,"column":75}},"type":"cond-expr","locations":[{"start":{"line":119,"column":44},"end":{"line":119,"column":68}},{"start":{"line":119,"column":71},"end":{"line":119,"column":75}}],"line":119},"17":{"loc":{"start":{"line":119,"column":11},"end":{"line":119,"column":41}},"type":"binary-expr","locations":[{"start":{"line":119,"column":11},"end":{"line":119,"column":21}},{"start":{"line":119,"column":25},"end":{"line":119,"column":41}}],"line":119},"18":{"loc":{"start":{"line":127,"column":11},"end":{"line":127,"column":29}},"type":"binary-expr","locations":[{"start":{"line":127,"column":11},"end":{"line":127,"column":21}},{"start":{"line":127,"column":25},"end":{"line":127,"column":29}}],"line":127},"19":{"loc":{"start":{"line":128,"column":13},"end":{"line":128,"column":30}},"type":"binary-expr","locations":[{"start":{"line":128,"column":13},"end":{"line":128,"column":22}},{"start":{"line":128,"column":26},"end":{"line":128,"column":30}}],"line":128}},"s":{"0":2,"1":2,"2":2,"3":2,"4":5,"5":5,"6":5,"7":4,"8":1,"9":3,"10":1,"11":2,"12":7,"13":7,"14":1,"15":6,"16":5,"17":2,"18":3,"19":3,"20":1,"21":2,"22":1,"23":1,"24":1,"25":2,"26":4,"27":4,"28":3,"29":2,"30":1,"31":1,"32":2,"33":8,"34":8,"35":1,"36":7,"37":7,"38":3,"39":3,"40":1,"41":2,"42":6,"43":5,"44":1,"45":2,"46":7,"47":7,"48":7,"49":1,"50":6,"51":6,"52":1,"53":5,"54":4,"55":1,"56":2,"57":1,"58":1,"59":2,"60":2},"f":{"0":5,"1":7,"2":4,"3":8,"4":7,"5":1},"b":{"0":[1,3],"1":[1,6],"2":[2,3],"3":[1,2],"4":[1,1],"5":[2,1],"6":[5],"7":[1,7],"8":[3,4],"9":[1,2],"10":[3,1],"11":[1,4],"12":[5,2],"13":[1,6],"14":[1,5],"15":[6,2],"16":[1,3],"17":[4,2],"18":[1,0],"19":[1,0]},"_coverageSchema":"43e27e138ebf9cfc5966b082cf9a028302ed4184","hash":"d280458b874ee28a63378ee7b54b4e25cdd8092f"}
}
{
"name": "@condor-labs/ec-events-gateway",
"version": "1.0.0",
"version": "1.1.0",
"description": "Client to send events to events gateway API",

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

@@ -7,31 +7,30 @@ # Events Gateway Client

```npm install @condor-labs/events-gateway-client```
```npm install @condor-labs/ec-events-gateway```
Import the library
```const events = import('events-gateway-client');```
```const { events } = require('@condor-labs/ec-events-gateway');```
with ES6:
``` import { events } from '@condor-labs/ec-events-gateway': ```
### Enviroment variable
Define a variable in you **.env** file with the events gateway api URL with the following name:
```EVENT_GATEWAY_URL```
```EVENTS_GATEWAY_URL```
That's all you need to start to send data to the events gateway api.
As an alternative you can pass a events gateway api url as **second** parameter of function:
As an alternative you can pass a events gateway api url as parameter:
```events.save(data, 'http://localhost');```
```events.save({payload, type, topic, schema, headers, url: 'http://localhost'});```
### Request data
### Required data
To send events through the events gateway client you must send some required fields:
- type: string,
- timestamp: date (timestamp)
- data: object
- topic: string,
- payload: object
You need to pass a data message as a first parameter of function:
```events.save(data);```
### Client Schema

@@ -48,6 +47,14 @@ You could define a valid Joi schema to validate the events data you are sending to the events gateway service.

And then send this schema through the **save** function as **third** parameter.
And then send this schema through the **save** function as parameter.
```events.save(data, undefined, schema);```
```events.save({payload, type, topic, schema, headers, url: 'http://localhost'});```
### Headers:
You should define headers to pass the apikey to the amazon services:
```
headers: {
'x-api-key': 'value'
}
```
### Payload max size

@@ -54,0 +61,0 @@ Please, be sure the payload data is less than **250kb**

const axios = require('axios');
const { validate } = require('../validate/validate');
const validate = require('../validate/validate');
const logger = require('../logger');
const { format } = require('date-fns');
const dateFns = require('date-fns');
const { URL_REQUIRED, DATE_FORMAT, PATH } = require('../utils/constants');
const save = async (data, url = null, schema = null) => {
const save = async ({
type,
topic,
payload,
url = null,
headers = {},
schema = null
}) => {
try {
const errors = validate(data, schema);
const data = {
topic,
type,
data: payload
};
let errors = validate.validateParams(data, schema);
if (errors) return errors;
const eventGatewayUrl = process.env.EVENT_GATEWAY_URL || url;
const eventGatewayUrl = process.env.EVENTS_GATEWAY_URL || url;
if (!eventGatewayUrl) return { error: URL_REQUIRED };
const formattedData = validate.formatData(data);
const response = await axios.post(eventGatewayUrl, data);
errors = validate.validateData(formattedData);
if (errors) return errors;
const response = await axios.post(eventGatewayUrl, formattedData, {
headers
});
return response;
} catch (error) {
let filename = format(new Date(), DATE_FORMAT);
let filename = dateFns.format(new Date(), DATE_FORMAT);
logger.generateLog(
filename,
data.action,
type,
'error',

@@ -24,0 +47,0 @@ JSON.stringify(error.message),

require('dotenv').config();
const axios = require('axios');
const { validate } = require('../validate');
const sinon = require('sinon');
const { expect } = require('chai');
const dateFns = require('date-fns');
const logger = require('../logger');
const validate = require('../validate');
const events = require('./events');
const { URL_REQUIRED } = require('../utils/constants');
process.env.EVENT_GATEWAY_URL = 'http://localhost';
const {
URL_REQUIRED,
PAYLOAD_REQUIRED,
PATH,
DATE_FORMAT
} = require('../utils/constants');
const eventsGatewayUrl = process.env.EVENT_GATEWAY_URL;
jest.mock('axios');
jest.mock('../validate');
describe('Events module', () => {
describe('When save function is called', () => {
let validateParamsStub = {},
formatDataStub = {},
validateDataStub = {},
axiosStub = {},
formatDateStub = {},
createLoggerStub = {};
describe('events', () => {
it('When everything went smooth', async () => {
const data = {
type: 'ECAuditLogs',
timestamp: Date.now(),
data: {
message: 'Test Message'
}
beforeEach(() => {
validateParamsStub = sinon.stub(validate, 'validateParams');
formatDataStub = sinon.stub(validate, 'formatData');
validateDataStub = sinon.stub(validate, 'validateData');
axiosStub = sinon.stub(axios, 'post');
formatDateStub = sinon.stub(dateFns, 'format');
createLoggerStub = sinon.stub(logger, 'generateLog');
});
afterEach(() => {
validateParamsStub.restore();
formatDataStub.restore();
validateDataStub.restore();
axiosStub.restore();
formatDateStub.restore();
createLoggerStub.restore();
});
const fakeParams = {
type: 'AUDIT_LOGS',
payload: {},
topic: 'topicfake',
url: 'www.fake.com'
};
const response = {
data: {
message: {
ResponseMetadata: {
RequestId: 'aba71508-9d90-571a-aca9-4074285d0ccc'
},
MessageId: 'abe477dc-9a1c-58f7-9b27-22a02fd15321'
it('Should calls validateParams function once with the right params', async done => {
process.env.EVENTS_GATEWAY_URL = 'http://localhost';
const { topic, type, payload } = fakeParams;
const data = {
topic,
type,
data: payload
};
await events.save(fakeParams);
expect(validateParamsStub.calledOnce).to.be.true;
expect(validateParamsStub.calledWith(data, null)).to.be.true;
done();
});
it('Should returns errors when validateParams function returns any error', async done => {
const errors = { error: PAYLOAD_REQUIRED };
validateParamsStub.returns(errors);
const result = await events.save(fakeParams);
expect(result).to.be.deep.equal(errors);
done();
});
it(`Should returns an object with an error property with the message '${URL_REQUIRED}' when not url is provided via params or environment variable`, async done => {
delete process.env.EVENTS_GATEWAY_URL;
delete fakeParams.url;
const expectedError = { error: URL_REQUIRED };
const result = await events.save(fakeParams);
expect(result).to.be.deep.equal(expectedError);
done();
});
it('Should calls validate.formatData function once with the right params', async done => {
process.env.EVENTS_GATEWAY_URL = 'http://localhost';
const { topic, type, payload } = fakeParams;
const data = {
topic,
type,
data: payload
};
await events.save(fakeParams);
expect(formatDataStub.calledOnce).to.be.true;
expect(formatDataStub.calledWith(data)).to.be.true;
done();
});
it('Should calls validate.validateData function once with the right params', async done => {
const { topic, type, payload } = fakeParams;
const formattedData = {
topic,
message: payload,
messageAttributes: {
name: 'event',
dataType: 'String',
type
}
}
};
};
axios.post.mockResolvedValue(response);
formatDataStub.returns(formattedData);
const eventResponse = await events.save(data);
await events.save(fakeParams);
expect(validateDataStub.calledOnce).to.be.true;
expect(validateDataStub.calledWith(formattedData)).to.be.true;
done();
});
expect(eventResponse).toEqual(response);
expect(axios.post.mock.calls[0]).toEqual([
process.env.EVENT_GATEWAY_URL,
data
]);
});
it('Should returns an object with an error when some error returned from validateData function', async done => {
const expectedError = { error: 'some error' };
validateDataStub.returns(expectedError);
it('When everything went wrong', async () => {
const data = {
type: 'ECAuditLogs',
data: {
message: 'Test Message'
}
};
const result = await events.save(fakeParams);
const response = [
{
message: '"timestamp" is required',
path: ['timestamp'],
type: 'any.required',
context: { key: 'timestamp', label: 'timestamp' }
}
];
expect(result).to.be.deep.equal(expectedError);
done();
});
validate.mockReturnValue(response);
it('Should calls axios.post function once with the right params', async done => {
const { topic, type, payload } = fakeParams;
const formattedData = {
topic,
message: payload,
messageAttributes: {
name: 'event',
dataType: 'String',
type
}
};
const eventResponse = await events.save(data);
formatDataStub.returns(formattedData);
validateDataStub.returns(null);
expect(eventResponse).toEqual(response);
});
await events.save(fakeParams);
expect(axiosStub.calledOnce).to.be.true;
expect(
axiosStub.calledWith(process.env.EVENTS_GATEWAY_URL, formattedData, {
headers: {}
})
).to.be.true;
done();
});
it('When url is not provided', async () => {
delete process.env.EVENT_GATEWAY_URL;
const data = {
type: 'ECAuditLogs',
timestamp: Date.now(),
data: {
message: 'Test Message'
}
};
it('Should return the response from the request send by axios', async done => {
const { topic, type, payload } = fakeParams;
const formattedData = {
topic,
message: payload,
messageAttributes: {
name: 'event',
dataType: 'String',
type
}
};
const response = { error: URL_REQUIRED };
const expectedResponse = { statusCode: 200 };
const eventResponse = await events.save(data);
formatDataStub.returns(formattedData);
validateDataStub.returns(null);
axiosStub.returns(Promise.resolve(expectedResponse));
expect(eventResponse).toEqual(response);
process.env.EVENT_GATEWAY_URL = eventsGatewayUrl;
const response = await events.save(fakeParams);
expect(response).to.be.deep.equal(expectedResponse);
done();
});
it('Should calls dateFns.format function once with the right params when an error occurs', async done => {
const error = 'some error';
validateParamsStub.throws(new Error(error));
await events.save(fakeParams);
expect(formatDateStub.calledOnce).to.be.true;
expect(formatDateStub.calledWith(new Date(), DATE_FORMAT)).to.be.true;
done();
});
it('Should calls logger.generateLog function once with the right params when an error occurs', async done => {
const error = 'some error';
const filename = 'filename.log';
validateParamsStub.throws(new Error(error));
formatDateStub.returns(filename);
await events.save(fakeParams);
expect(createLoggerStub.calledOnce).to.be.true;
expect(
createLoggerStub.calledWith(
filename,
fakeParams.type,
'error',
JSON.stringify(error),
PATH
)
).to.be.true;
done();
});
});
});

@@ -6,3 +6,3 @@ const winston = require('winston');

try {
await findOrCreateFolder(path);
await loggerModule.findOrCreateFolder(path);
const logger = winston.createLogger({

@@ -12,8 +12,10 @@ level,

defaultMeta: { service },
transports: [
new winston.transports.File({
filename: `${filename}.log`,
dirname: path
})
]
transports: process.env.running_test
? []
: [
new winston.transports.File({
filename: `${filename}.log`,
dirname: path
})
]
});

@@ -26,8 +28,7 @@ logger.log({ message, level });

const findOrCreateFolder = async (path) => {
const findOrCreateFolder = async path => {
try {
const exist = await fs.existsSync(path);
if (!exist) {
await fs.mkdirSync(path)
await fs.mkdirSync(path);
}

@@ -39,2 +40,4 @@ } catch (error) {

module.exports = { generateLog, findOrCreateFolder };
const loggerModule = { generateLog, findOrCreateFolder };
module.exports = loggerModule;

@@ -1,40 +0,124 @@

const { stub, assert } = require('sinon');
const sinon = require('sinon');
const { expect } = require('chai');
const winston = require('winston');
const fs = require('fs');
const logger = require('./');
process.env.running_test = true;
describe('Logger testing', () => {
let createLoggerStub = {},
describe('When generateLog function is called', () => {
let findOrCreateFolderStub = {};
let createLoggerStub = {};
let logStub = {};
let consoleErrorStub = {};
existsSyncStub = {},
mkdirStub = {}
const filename = 'filename';
const service = 'service';
const level = 'level';
const message = 'message';
const path = 'some path';
const loggerResponse = {
log: () => {}
};
beforeEach(() => {
createLoggerStub = stub(winston, 'createLogger');
existsSyncStub = stub(fs, 'existsSync');
mkdirStub = stub(fs, 'mkdirSync')
findOrCreateFolderStub = sinon.stub(logger, 'findOrCreateFolder');
createLoggerStub = sinon
.stub(winston, 'createLogger')
.callsFake(() => {})
.returns(loggerResponse);
logStub = sinon.stub(loggerResponse, 'log');
consoleErrorStub = sinon.stub(console, 'error');
});
afterEach(() => {
createLoggerStub.restore();
existsSyncStub.restore();
mkdirStub.restore();
findOrCreateFolderStub.restore();
createLoggerStub.restore();
logStub.restore();
consoleErrorStub.restore();
});
it('call generateLog function and exists sync is true', async () => {
createLoggerStub.returns({
log: () => { },
});
existsSyncStub.returns(true)
await logger.generateLog('25-6-2019', 'TEST', 'error', 'An error has ocurred', 'C:\\');
assert.called(existsSyncStub);
it('Should calls findOrCreateFolder function once with the right params', async done => {
await logger.generateLog(
undefined,
undefined,
undefined,
undefined,
path
);
expect(findOrCreateFolderStub.calledOnce).to.be.true;
expect(findOrCreateFolderStub.calledWith(path)).to.be.true;
done();
});
it('call generateLog function and exists sync is false', async () => {
createLoggerStub.returns({
log: () => { },
});
existsSyncStub.returns(false)
mkdirStub.returns({ generateFile: true })
await logger.generateLog('25-6-2019', 'TEST', 'error', 'An error has ocurred', 'C:\\');
assert.called(existsSyncStub);
assert.called(mkdirStub);
it('Should calls createLogger function once', async done => {
await logger.generateLog(filename, service, level, undefined, path);
expect(createLoggerStub.calledOnce).to.be.true;
done();
});
})
it('Should calls logger.log function once with the right params', async done => {
await logger.generateLog(filename, service, level, message, path);
expect(logStub.calledOnce).to.be.true;
expect(logStub.calledWith({ message, level })).to.be.true;
done();
});
it('should handle en print error when they occur', async () => {
const error = 'this is an error message';
createLoggerStub.throws(new Error(error));
await logger.generateLog(filename, service, level, message, path);
expect(consoleErrorStub.calledOnce).to.be.true;
expect(consoleErrorStub.calledWith(error)).to.be.true;
});
});
describe('When findOrCreateFolder function is called', () => {
let existsSyncStub = {};
let mkdirSyncStub = {};
let consoleErrorStub = {};
beforeEach(done => {
existsSyncStub = sinon.stub(fs, 'existsSync').callsFake(() => {});
mkdirSyncStub = sinon.stub(fs, 'mkdirSync').callsFake(() => {});
consoleErrorStub = sinon.stub(console, 'error');
done();
});
afterEach(done => {
existsSyncStub.restore();
mkdirSyncStub.restore();
consoleErrorStub.restore();
done();
});
it('should calls existsSync with the right params', async () => {
const path = 'test';
await logger.findOrCreateFolder(path);
expect(existsSyncStub.calledOnce).to.be.true;
expect(existsSyncStub.calledWith(path)).to.be.true;
});
it('should call mkdirSync when file path does not exists', async () => {
existsSyncStub.returns(false);
const path = 'test';
await logger.findOrCreateFolder(path);
expect(mkdirSyncStub.calledOnce).to.be.true;
expect(mkdirSyncStub.calledWith(path)).to.be.true;
});
it('should handle errors when they occur', async () => {
const error = 'this is an error message';
existsSyncStub.throws(new Error(error));
await logger.findOrCreateFolder();
expect(consoleErrorStub.calledOnce).to.be.true;
expect(consoleErrorStub.calledWith(error)).to.be.true;
});
});
});

@@ -9,2 +9,4 @@ module.exports = {

MAX_PAYLOAD_SIZE: 250,
TOPIC_REQUIRED: 'Topic is required',
TYPE_REQUIRED: "Type is required",
unhandledError: message => {

@@ -14,3 +16,7 @@ return { error: `unhandled error: ${message}` };

DATE_FORMAT: 'MM-DD-YYYY',
PATH: '/home/zcebjobs/ec-audit-logs'
PATH: '/home/zcebjobs/ec-audit-logs',
MESSAGE_ATTRIBUTES: {
name: "event",
dataType: "String"
}
};
const Joi = require('@hapi/joi');
const constants = require('../utils/constants');
const {

@@ -9,13 +10,5 @@ PAYLOAD_LARGE,

PAYLOAD_VALID,
unhandledError
} = require('../utils/constants');
MESSAGE_ATTRIBUTES
} = constants;
let schema = {
type: Joi.string().required(),
timestamp: Joi.date()
.timestamp()
.required(),
data: Joi.object().required()
};
const validateSize = data => {

@@ -32,4 +25,6 @@ try {

}
return { error: false, message: PAYLOAD_VALID };
return {
error: false,
message: PAYLOAD_VALID
};
} catch (error) {

@@ -43,39 +38,110 @@ return {

const validateSchema = (schema, clientSchema) => {
const isSchema = schema => {
try {
const isValidSchema =
Joi.object().keys(clientSchema) instanceof Joi.constructor;
if (!schema) return false;
if (!isValidSchema) return { error: INVALID_SCHEMA };
const keys = Object.keys(schema);
if (keys.length === 0) return false;
return;
const key = keys[0];
if (typeof schema[key] !== 'object') return false;
if (!schema[key].isJoi) return false;
return true;
} catch (error) {
return unhandledError(error.message);
return false;
}
};
const validate = (data, clientSchema = null) => {
const validateSchema = clientSchema => {
try {
const isValid = validateModule.isSchema(clientSchema);
if (!isValid) {
return { error: INVALID_SCHEMA };
}
return isValid;
} catch (error) {
return constants.unhandledError(error.message);
}
};
const validateParams = (data, clientSchema = null) => {
try {
if (!data) return { error: PAYLOAD_REQUIRED };
const { error, message } = validateSize(data);
if (error) return { error: message };
let schema = {
type: Joi.string().required(),
topic: Joi.string().required(),
data: Joi.object().required()
};
if (clientSchema) {
const result = validateSchema(schema, clientSchema);
const result = validateModule.validateSchema(clientSchema);
if (result && result.error) return result;
Object.assign(schema, clientSchema);
schema = {
type: Joi.string().required(),
topic: Joi.string().required(),
data: Joi.object()
.keys({
...clientSchema
})
.required()
};
}
const validation = Joi.validate(data, Joi.object().keys(schema));
return validation.error ? validation.error.details : null;
return validation && validation.error ? validation.error.details : null;
} catch (error) {
return unhandledError(error.message);
return constants.unhandledError(error.message);
}
};
module.exports = {
validate
const validateData = data => {
try {
const schema = {
topic: Joi.string().required(),
message: Joi.object().required(),
messageAttributes: Joi.object()
.keys({
name: Joi.string().required(),
type: Joi.string().required(),
dataType: Joi.string().required()
})
.required()
};
if (!data) return { error: PAYLOAD_REQUIRED };
const result = validateModule.validateSize(data);
if (result && result.error) return { error: result.message };
const validation = Joi.validate(data, Joi.object().keys(schema));
return validation && validation.error ? validation.error.details : null;
} catch (error) {
return constants.unhandledError(error.message);
}
};
const formatData = data => {
const newData = {
topic: data.topic || null,
message: data.data || null,
messageAttributes: { ...MESSAGE_ATTRIBUTES, type: data.type }
};
return newData;
};
const validateModule = {
isSchema,
formatData,
validateData,
validateSize,
validateParams,
validateSchema
};
module.exports = validateModule;
const Joi = require('@hapi/joi');
const { validate } = require('../validate');
const { expect } = require('chai');
const sinon = require('sinon');
const validate = require('../validate');
const constants = require('../utils/constants');
const {
PAYLOAD_LARGE,
PAYLOAD_REQUIRED
} = require('../utils/constants');
PAYLOAD_REQUIRED,
PAYLOAD_VALID,
BAD_PAYLOAD,
INVALID_SCHEMA,
MESSAGE_ATTRIBUTES
} = constants;
describe('validate', () => {
it('Should return an error if payload is too large', () => {
const data = {
type: 'ECAuditLogs',
timestamp: Date.now(),
data: {
message: 'Test Message'
}
describe('Validate module', () => {
describe('When validateSize function is called', () => {
let stringifyStub = {};
let byteLengthStub = {};
const payload = {
someKey: 'some value'
};
const kilobytes = 100000000;
beforeEach(done => {
stringifyStub = sinon.stub(JSON, 'stringify').returns(payload);
byteLengthStub = sinon.stub(Buffer, 'byteLength');
done();
});
afterEach(done => {
stringifyStub.restore();
byteLengthStub.restore();
done();
});
it('Should calls JSON.stringify function once with the right params', done => {
validate.validateSize(payload);
expect(stringifyStub.calledOnce).to.be.true;
expect(stringifyStub.calledWith(payload)).to.be.true;
done();
});
it('Should calls Buffer.byteLength function once with the right params', done => {
validate.validateSize(payload);
expect(byteLengthStub.calledOnce).to.be.true;
expect(byteLengthStub.calledWith(payload, 'utf8')).to.be.true;
done();
});
it('Should return an object with the right properties when kilobytes exceed the maximum allowed', done => {
constants.MAX_PAYLOAD_SIZE = 100;
byteLengthStub.returns(kilobytes);
const expectedResult = {
error: true,
message: PAYLOAD_LARGE
};
const result = validate.validateSize(payload);
expect(typeof result).to.be.equal('object');
expect(result).to.be.deep.equal(expectedResult);
expect(Array.isArray(result)).to.be.false;
done();
});
it('Should return an object with the right properties when kilobytes exceed the maximum allowed', done => {
constants.MAX_PAYLOAD_SIZE = 100;
byteLengthStub.returns(100);
const expectedResult = {
error: false,
message: PAYLOAD_VALID
};
const result = validate.validateSize(payload);
expect(typeof result).to.be.equal('object');
expect(result).to.be.deep.equal(expectedResult);
expect(Array.isArray(result)).to.be.false;
done();
});
it('Should return an object with the right properties when kilobytes exceed the maximum allowed', done => {
constants.MAX_PAYLOAD_SIZE = 100;
byteLengthStub.throws(new Error('some error'));
const expectedResult = {
error: true,
message: BAD_PAYLOAD
};
const result = validate.validateSize(payload);
expect(typeof result).to.be.equal('object');
expect(result).to.be.deep.equal(expectedResult);
expect(Array.isArray(result)).to.be.false;
done();
});
});
const response = { error: PAYLOAD_LARGE };
describe('When isSchema function is called', () => {
let keysStub = {};
const temp = Buffer.byteLength;
Buffer.byteLength = jest.fn().mockReturnValue(716800);
beforeEach(done => {
keysStub = sinon.stub(Object, 'keys').returns([]);
done();
});
const errors = validate(data);
afterEach(done => {
keysStub.restore();
done();
});
expect(errors).toEqual(response);
it('Should returns false when schema parameter is not defined', done => {
const result = validate.isSchema();
expect(result).to.be.false;
done();
});
expect(Buffer.byteLength.mock.calls[0]).toEqual([
JSON.stringify(data),
'utf8'
]);
it('Should calls Object.keys function once with the right param', done => {
const schema = { someKey: 'some value' };
validate.isSchema(schema);
Buffer.byteLength = temp;
expect(keysStub.calledOnce).to.be.true;
expect(keysStub.calledWith(schema)).to.be.true;
done();
});
it('Should returns false when the schema passed as param does not have any key', done => {
const schema = {};
const result = validate.isSchema(schema);
expect(result).to.be.false;
done();
});
it('Should returns false when the first key of the schema passed as param is not an object', done => {
const schema = { someKey: 'some value' };
keysStub.returns(['someKey']);
const result = validate.isSchema(schema);
expect(result).to.be.false;
done();
});
it('Should returns false when the schema passed as param is not a valid joi schema', done => {
const schema = {
someKey: {
child: true
}
};
keysStub.returns(['someKey']);
const result = validate.isSchema(schema);
expect(result).to.be.false;
done();
});
it('Should return true when the schema passed as parameter is a Joi valid schema', done => {
const schema = {
isJoi: true,
type: Joi.string().required(),
data: Joi.object(),
topic: Joi.string().required()
};
keysStub.returns(['type']);
const result = validate.isSchema(schema);
expect(result).to.be.true;
done();
});
it('Should return false when an error occurs', done => {
const schema = {
someKey: {
child: true
}
};
keysStub.throws(new Error('some error!'));
const result = validate.isSchema(schema);
expect(result).to.be.false;
done();
});
});
it('Should return an error if payload is undefined', () => {
const response = { error: PAYLOAD_REQUIRED };
describe('When validateSchema function is called', () => {
let isSchemaStub = {};
let unhandledErrorStub = {};
beforeEach(done => {
isSchemaStub = sinon.stub(validate, 'isSchema');
unhandledErrorStub = sinon.stub(constants, 'unhandledError');
done();
});
afterEach(done => {
isSchemaStub.restore();
unhandledErrorStub.restore();
done();
});
it('Should calls isSchema function once with the right params', done => {
const schema = {
type: 'Joi.string().required()'
};
validate.validateSchema(schema);
const errors = validate(undefined);
expect(isSchemaStub.calledOnce).to.be.true;
expect(isSchemaStub.calledWith(schema)).to.be.true;
done();
});
it(`Should returns an object with an error property and the message ${INVALID_SCHEMA} when schema param is not a valid object`, done => {
isSchemaStub.returns(false);
const expectedResult = { error: INVALID_SCHEMA };
const schema = {
type: 'Joi.string().required()'
};
const result = validate.validateSchema(schema);
expect(result).to.be.deep.equal(expectedResult);
done();
});
it(`Should returns true when schema param is a valid joi object`, done => {
isSchemaStub.returns(true);
const schema = {
type: Joi.string().required()
};
const result = validate.validateSchema(schema);
expect(result).to.be.true;
done();
});
it('Should calls unhandledError function once with the right param and returns an object with an error property', done => {
const error = new Error('an error occurred');
isSchemaStub.throws(error);
const schema = {
type: Joi.string().required()
};
validate.validateSchema(schema);
expect(unhandledErrorStub.calledOnce).to.be.true;
expect(unhandledErrorStub.calledWith(error.message)).to.be.true;
done();
});
});
expect(errors).toEqual(response);
describe('When validateParams function is called', () => {
let validateSchemaStub = {};
let joiValidateStub = {};
let unhandledErrorStub = {};
beforeEach(done => {
validateSchemaStub = sinon.stub(validate, 'validateSchema');
joiValidateStub = sinon.stub(Joi, 'validate');
unhandledErrorStub = sinon.stub(constants, 'unhandledError');
done();
});
afterEach(done => {
validateSchemaStub.restore();
joiValidateStub.restore();
unhandledErrorStub.restore();
done();
});
it(`Should return an object with an error propery and the message ${PAYLOAD_REQUIRED} when data parameter is not defined`, done => {
const expectedResult = { error: PAYLOAD_REQUIRED };
const result = validate.validateParams();
expect(result).to.be.deep.equal(expectedResult);
done();
});
it('Should calls validateSchema once with the right params when clientSchema is defined', done => {
const data = 'some data';
const clientSchema = { someKey: 'some value' };
validate.validateParams(data, clientSchema);
expect(validateSchemaStub.calledOnce).to.be.true;
expect(validateSchemaStub.calledWith(clientSchema)).to.be.true;
done();
});
it('Should return an object with an error property when validateSchema return any error', done => {
const error = { error: 'any error' };
validateSchemaStub.returns(error);
const data = 'some data';
const clientSchema = { someKey: 'some value' };
const result = validate.validateParams(data, clientSchema);
expect(result).to.be.deep.equal(error);
done();
});
it('Should calls Joi.validate function once with the right params when client schema is specified', done => {
const data = 'some data';
const clientSchema = {
destination: Joi.string().required()
};
const schema = {
type: Joi.string().required(),
topic: Joi.string().required(),
data: Joi.object()
.keys({
...clientSchema
})
.required()
};
validate.validateParams(data, clientSchema);
expect(joiValidateStub.calledOnce).to.be.true;
expect(joiValidateStub.calledWith(data, Joi.object().keys(schema))).to.be
.true;
done();
});
it('Should calls Joi.validate function once with the right params', done => {
const data = 'some data';
const schema = {
type: Joi.string().required(),
topic: Joi.string().required(),
data: Joi.object().required()
};
validate.validateParams(data);
expect(joiValidateStub.calledOnce).to.be.true;
expect(joiValidateStub.calledWith(data, Joi.object().keys(schema))).to.be
.true;
done();
});
it('Should return null when no error occurs validating parameters', done => {
joiValidateStub.returns({});
const data = 'some data';
const result = validate.validateParams(data);
expect(result).to.be.equal(null);
done();
});
it('Should return errors details when an error occurs validating parameters', done => {
const validation = {
error: {
details: 'some error occurs!'
}
};
joiValidateStub.returns(validation);
const data = 'some data';
const result = validate.validateParams(data);
expect(result).to.be.equal(validation.error.details);
done();
});
it('Should calls unhandledError function once with the right param and returns an object with an error property', done => {
const error = new Error('an error occurred');
joiValidateStub.throws(error);
const data = 'some data';
validate.validateParams(data);
expect(unhandledErrorStub.calledOnce).to.be.true;
expect(unhandledErrorStub.calledWith(error.message)).to.be.true;
done();
});
});
it('Should not return an error if the schema is valid', () => {
describe('When validateData function is called', () => {
let validateSizeStub = {};
let joiValidateStub = {};
let unhandledErrorStub = {};
const data = {
type: 'ECAuditLogs',
timestamp: Date.now(),
data: {
message: 'Test Message'
},
destination: {
hostname: 'ec-test-destination-machine',
application: 'ec-test-destination'
}
};
beforeEach(done => {
validateSizeStub = sinon.stub(validate, 'validateSize');
joiValidateStub = sinon.stub(Joi, 'validate');
unhandledErrorStub = sinon.stub(constants, 'unhandledError');
done();
});
const clientSchema = {
destination: {
hostname: Joi.string().required(),
application: Joi.string().required(),
props: Joi.string().uuid(),
Date: new Date()
}
};
afterEach(done => {
validateSizeStub.restore();
joiValidateStub.restore();
unhandledErrorStub.restore();
done();
});
const errors = validate(data, clientSchema);
it(`Should returns an object with an error property with the message ${PAYLOAD_REQUIRED} when data parameter is not defined`, done => {
const expectedResult = { error: PAYLOAD_REQUIRED };
const result = validate.validateData();
expect(result).to.be.deep.equal(expectedResult);
done();
});
expect(errors).toEqual(null);
it('Should calls validateSize function once with the right params when data parameter is specified', done => {
const data = 'some data';
validate.validateData(data);
expect(validateSizeStub.calledOnce).to.be.true;
expect(validateSizeStub.calledWith(data)).to.be.true;
done();
});
it('Should returns an object with an error property when validateSize returns an error', done => {
const validateSizeError = { error: true, message: 'some error' };
validateSizeStub.returns(validateSizeError);
const data = 'some data';
const result = validate.validateData(data);
expect(result).to.be.deep.equal({ error: validateSizeError.message });
done();
});
it('Should calls Joi.validate function once with the right params', done => {
validateSizeStub.returns({});
const data = 'some data';
const schema = {
topic: Joi.string().required(),
message: Joi.object().required(),
messageAttributes: Joi.object()
.keys({
name: Joi.string().required(),
type: Joi.string().required(),
dataType: Joi.string().required()
})
.required()
};
validate.validateData(data);
expect(joiValidateStub.calledOnce).to.be.true;
expect(joiValidateStub.calledWith(data, Joi.object().keys(schema))).to.be
.true;
done();
});
it('Should return null when no error occurs validating parameters', done => {
joiValidateStub.returns({});
const data = 'some data';
const result = validate.validateData(data);
expect(result).to.be.equal(null);
done();
});
it('Should return errors details when an error occurs validating parameters', done => {
const validation = {
error: {
details: 'some error occurs!'
}
};
joiValidateStub.returns(validation);
const data = 'some data';
const result = validate.validateData(data);
expect(result).to.be.equal(validation.error.details);
done();
});
it('Should calls unhandledError function once with the right param and returns an object with an error property', done => {
const error = new Error('an error occurred');
joiValidateStub.throws(error);
const data = 'some data';
validate.validateData(data);
expect(unhandledErrorStub.calledOnce).to.be.true;
expect(unhandledErrorStub.calledWith(error.message)).to.be.true;
done();
});
});
it('Should not return an error if data have a good format', () => {
const data = {
type: 'ECAuditLogs',
timestamp: Date.now(),
data: {
message: 'Test Message'
}
};
describe('When formatData is called', () => {
it('Should returns an object with the righ properties', done => {
const data = {
type: 'some type',
topic: 'some topic',
data: {
someKey: 'some value'
}
};
const errors = validate(data);
const expectedResult = {
topic: data.topic,
message: data.data,
messageAttributes: {
...MESSAGE_ATTRIBUTES,
type: data.type
}
};
expect(errors).toEqual(null);
const result = validate.formatData(data);
expect(typeof result === 'object').to.be.true;
expect(Array.isArray(result)).to.be.false;
expect(result).to.be.deep.equal(expectedResult);
done();
});
});
});

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc