@zenginehq/backend-webhooks
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -5,2 +5,12 @@ # Change Log | ||
<a name="1.2.0"></a> | ||
# 1.2.0 (2018-08-17) | ||
### Features | ||
* get validated multi config ID ([af44bc0](https://github.com/ZengineHQ/zn-backend-webhooks/commit/af44bc0)), closes [#1](https://github.com/ZengineHQ/zn-backend-webhooks/issues/1) | ||
<a name="1.1.1"></a> | ||
@@ -31,2 +41,7 @@ ## 1.1.1 (2018-07-17) | ||
<a name="1.1.1"></a> | ||
## 1.1.1 (2018-07-17) | ||
<a name="1.1.0"></a> | ||
@@ -52,2 +67,12 @@ # 1.1.0 (2018-06-29) | ||
<a name="1.1.0"></a> | ||
# 1.1.0 (2018-06-29) | ||
### Features | ||
* split up activity record checking into 2 functions ([7fc9fae](https://github.com/ZengineHQ/zn-backend-webhooks/commit/7fc9fae)) | ||
<a name="1.0.0"></a> | ||
@@ -60,1 +85,11 @@ # 1.0.0 (2018-06-28) | ||
* initial module with secret validation and activity folder checks ([679a949](https://github.com/ZengineHQ/zn-backend-webhooks/commit/679a949)) | ||
<a name="1.0.0"></a> | ||
# 1.0.0 (2018-06-28) | ||
### Features | ||
* initial module with secret validation and activity folder checks ([679a949](https://github.com/ZengineHQ/zn-backend-webhooks/commit/679a949)) |
16
index.js
@@ -44,2 +44,18 @@ 'use strict'; | ||
/** | ||
* Iterates over settings object keys and returns the key of the valid config | ||
* | ||
* @param {Object} settings settings from firebase | ||
* @param {Object} request The HTTP Request | ||
* | ||
* @returns {string|undefined} | ||
*/ | ||
module.exports.getValidatedMultiConfigId = function (settings, request) { | ||
var webhookKey = request.headers['x-zengine-webhook-key']; | ||
var webhookId = 'scheduled' in request.body ? request.body.scheduled.id : request.body.webhook.id; | ||
return settings && Object.keys(settings) | ||
.find(key => settings[key][keyField] === webhookKey && settings[key][idField] === webhookId); | ||
}; | ||
/** | ||
* Returns whether a record went into the specified folder. | ||
@@ -46,0 +62,0 @@ * |
{ | ||
"name": "@zenginehq/backend-webhooks", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "Helper library for working with Webhooks in Zengine backend plugins.", | ||
@@ -8,6 +8,6 @@ "main": "index.js", | ||
"test": "nyc mocha --reporter spec --no-colors --require test/_bootstrap.js", | ||
"lint": "jshint --config .jshintrc index.js || true", | ||
"lint": "jshint --config .jshintrc index.js", | ||
"docs": "jsdoc index.js README.md --destination docs", | ||
"cover": "nyc --reporter=lcov npm test && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js", | ||
"release": "jshint --config .jshintrc index.js && npm test && standard-version" | ||
"release": "npm run lint && npm test && standard-version" | ||
}, | ||
@@ -14,0 +14,0 @@ "repository": { |
@@ -5,3 +5,3 @@ # Backend Webhooks | ||
[![Coverage Status](https://coveralls.io/repos/github/ZengineHQ/zn-backend-webhooks/badge.svg?branch=master)](https://coveralls.io/github/ZengineHQ/zn-backend-webhooks?branch=master) | ||
[![Coverage Status](https://coveralls.io/repos/github/ZengineHQ/zn-backend-webhooks/badge.svg?branch=master)](https://coveralls.io/github/ZengineHQ/zn-backend-webhooks?branch=master) [![Build Status](https://circleci.com/gh/ZengineHQ/zn-backend-webhooks/tree/master.svg?style=shield)](https://circleci.com/gh/ZengineHQ/zn-backend-webhooks/tree/master) [![npm version](https://badge.fury.io/js/%40zenginehq%2Fbackend-webhooks.svg)](https://badge.fury.io/js/%40zenginehq%2Fbackend-webhooks) | ||
@@ -21,3 +21,3 @@ ## Installation | ||
var workspace; // from eventData | ||
var workspaceId; // from eventData | ||
var activity; // from eventData | ||
@@ -40,2 +40,3 @@ | ||
// Do something else. | ||
// $api.moveToFolder(approcvedfolder); | ||
} | ||
@@ -58,3 +59,3 @@ }); | ||
Returns whether the given activity is a move to the specified folder (ie: record moved from a folder this this one) | ||
Returns whether the given activity is a move to the specified folder (ie: record moved from a folder into this one) | ||
@@ -61,0 +62,0 @@ #### activityFromFolder(activity, toFolder) |
@@ -23,5 +23,12 @@ 'use strict'; | ||
const multiConfigSettings = { | ||
crazyKeyString: { | ||
webhookId: 123, | ||
webhookKey: 456, | ||
} | ||
} | ||
const activity = { | ||
changes: { | ||
to : { | ||
to: { | ||
folder: { | ||
@@ -44,4 +51,33 @@ id: 123 | ||
expect($webhook.validateSecret({ webhookId: 125 }, request)).to.be.false; | ||
expect($webhook.validateSecret(multiConfigSettings.crazyKeyString, request)).to.be.true; | ||
}); | ||
it('returns only valid configId from multi configs', function () { | ||
expect($webhook.getValidatedMultiConfigId(multiConfigSettings, request)).to.equal('crazyKeyString'); | ||
const reqWithBadHeader = { | ||
headers: {}, | ||
body: { | ||
webhook: { | ||
id: 123 | ||
} | ||
} | ||
}; | ||
expect($webhook.getValidatedMultiConfigId(multiConfigSettings, reqWithBadHeader)).to.be.undefined; | ||
const reqWithBadId = { | ||
headers: { | ||
'x-zengine-webhook-key': 456 | ||
}, | ||
body: { | ||
webhook: { | ||
id: 987 | ||
} | ||
} | ||
}; | ||
expect($webhook.getValidatedMultiConfigId(multiConfigSettings, reqWithBadId)).to.equal(undefined); | ||
}); | ||
it('checks whether a record moved into a folder', function () { | ||
@@ -48,0 +84,0 @@ expect($webhook.activityToFolder(activity, 123)).to.be.true; |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1113845
56
1271
65
0