Skip to content

Commit

Permalink
Webhook should include additional information in the call (#19)
Browse files Browse the repository at this point in the history
* update sailor logger

* refactor to es6

* Add CHANGELOG.md

* Add eslint

* Refactor unit test

* circleCI test

* Update dependencies

* Fix eslint

* Update readme

* Update logging
  • Loading branch information
shanthoshp authored and Olha Virolainen committed Sep 2, 2019
1 parent 2e75ff4 commit f061c15
Show file tree
Hide file tree
Showing 19 changed files with 3,730 additions and 417 deletions.
10 changes: 0 additions & 10 deletions .circleci/build_slug.sh

This file was deleted.

24 changes: 24 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: 2
jobs:
test:
docker:
- image: circleci/node:12-stretch
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run:
name: Installing Dependencies
command: npm install
- save_cache:
key: dependency-cache-{{ checksum "package.json" }}
paths:
- node_modules
- run:
name: Running Mocha Tests
command: npm test
workflows:
version: 2
build_and_test:
jobs:
- test
160 changes: 160 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
'use strict';

const ERROR = 'error';
const WARN = 'warn';
const ALWAYS = 'always';
const NEVER = 'never';
const OFF = 'off';

module.exports = {
'env': {
es6: true,
node: true,
mocha: true
},
'parserOptions': {
ecmaVersion: 2017
},
'extends': 'eslint:recommended',
'plugins': [
'mocha'
],
'rules': {
'indent': [
ERROR,
4,
{
SwitchCase: 1
}
],
'linebreak-style': ERROR,
'quotes': [
WARN,
'single',
{
avoidEscape: true,
allowTemplateLiterals: true
}
],
'semi': [
ERROR,
ALWAYS
],
'func-names': WARN,
'no-empty': ERROR,
'no-empty-function': ERROR,
'brace-style': [
ERROR,
'1tbs',
{ allowSingleLine: true }
],
'no-multiple-empty-lines': ERROR,
'no-multi-spaces': ERROR,
'one-var': [
ERROR,
NEVER
],
'quote-props': [
WARN,
'consistent-as-needed'
],
'key-spacing': ERROR,
'space-unary-ops': [
ERROR,
{
words: true,
nonwords: false
}
],
'no-spaced-func': ERROR,
'space-before-function-paren': [
ERROR,
{
anonymous: ALWAYS,
named: NEVER
}
],
'arrow-body-style': [
WARN,
'as-needed'
],
'array-bracket-spacing': ERROR,
'space-in-parens': ERROR,
'comma-dangle': WARN,
'no-trailing-spaces': ERROR,
'yoda': ERROR,
'max-len': [
ERROR,
120
],
'camelcase': [
ERROR,
{
properties: 'never'
}
],
'new-cap': [
WARN,
{
capIsNewExceptions: ['Q']
}
],
'comma-style': ERROR,
'curly': ERROR,
'object-curly-spacing': [
WARN,
ALWAYS
],
'object-curly-newline': [
OFF
],
'object-property-newline': OFF,
'template-curly-spacing': ERROR,
'dot-notation': ERROR,
'dot-location': [
ERROR,
'property'
],
'func-style': [
ERROR,
'declaration',
{
allowArrowFunctions: true
}
],
'eol-last': ERROR,
'space-infix-ops': ERROR,
'keyword-spacing': ERROR,
'space-before-blocks': ERROR,
'no-invalid-this': ERROR,
'consistent-this': ERROR,
'no-this-before-super': ERROR,
'no-unreachable': ERROR,
'no-sparse-arrays': ERROR,
'array-callback-return': ERROR,
'strict': [
OFF,
'global'
],
'eqeqeq': ERROR,
'no-use-before-define': WARN,
'no-undef': ERROR,
'no-unused-vars': WARN,
'no-mixed-spaces-and-tabs': ERROR,
'operator-linebreak': [
ERROR,
'before'
],
'no-console': [
WARN,
{
'allow': [
'warn',
'error'
]
}
],
'mocha/no-exclusive-tests': ERROR,
'mocha/no-skipped-tests': ERROR
}
};
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## 1.1.0 (July 29, 2019)

* Migrate to es6
* Refactor unit tests and component structure
* Add additional information to the webhook call

## 1.0.0 (March 23, 2016)

* Initial release
94 changes: 61 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
# webhook-component
## Table of Contents

* [General information](#general-information)
* [Description](#description)
* [Purpose](#purpose)
* [Credentials](#credentials)
* [Triggers](#triggers)
* [Receive](#receive)
* [Actions](#actions)
* [Send data](#send-data)
* [Known Limitations](#known-limitations)

## Description
### Purpose
An open source component for sending and receiving [WebHooks](https://en.wikipedia.org/wiki/Webhook) on [elastic.io platform](https://www.elastic.io "elastic.io platform").

Before you can deploy any code into our system **you must be a registered elastic.io platform user**. Please see our home page at [https://www.elastic.io](https://www.elastic.io) to learn how.

## Credentials
Webhook component supports the following authorisation types:
* **No Auth** - use this method to work with any open REST API
Expand All @@ -15,44 +25,62 @@ Webhook component supports the following authorisation types:
![Webhook Credentials](https://user-images.githubusercontent.com/8449044/61962330-ec5c2c00-afd1-11e9-8e5f-6a1c89126034.png)

## Triggers
### Receive
Simple webhook trigger which receives data as an input and starts the flow execution after this.

Receive trigger has 1 field: sample data field to define your incoming message.
### Receive
Simple webhook trigger which receives data as an input and starts the flow execution after this.

To use the Receive trigger for WebHook at elastic.io you would need to define the sample structure which would be used to send your data.
You are able to input your desired data structure either as JSON data, XML or as List of properties.

#### Sending JSON
Send WebHook using JSON data and Content-Type of `application/json` - in this case you just paste a sample of such JSON payload in the WebHook configuration window.
```json
#### Expected output metadata
[Output schema](lib/schemas/base64.out.json)

Example:
```metadata json
{
"foo" : "bar",
"myJSON" : "is the best!"
}
"recievedBody": "recievedBody",
"_query": {},
"_headers": {
"content-type": "application/json",
"accept": "*/*",
"accept-encoding": "gzip, deflate"
},
"_method": "POST",
"_url": "/hook/5d691738cb5a286adc1e68e2"
}
```

#### Receive. Config fields
* **[required]** Payload. This is the place you define your incoming data.
Renders an input text area field to define a payload metadata for the WebHook component.

## Actions
### Send Data
Simply sends data it receives as an input to a URL provided.

WebHook action can also be used to troubleshoot many processes to see the outcome.
For example one could create Invoices (in Salesforce) to Webhook flow and configure the Webhook with a url created in https://webhook.site or with any similar services.
## Actions
### Send data
Simply sends data it receives as an input to a URL provided.

WebHook action can also be used to troubleshoot many processes to see the outcome.
For example one could create Invoices (in Salesforce) to Webhook flow and configure the Webhook with a url created in https://webhook.site or with any similar services.

#### Send Data. Config fields
* **[required]** **HTTP Verb**
* **POST**. The WebHook component can POST information to preconfigured WebHook address. This action could be used for different purposes. For example WebHook can be used to inform your custom connector about an event which it waits to work.
* **PUT**. The WebHook component can also PUT a specific preconfigured JSON into specific address where the process will not be handled by the server. For this reason the "Output JSON Sample" field can be used.
* **[required]** **URI**. This is the address to send WebHook.
* **[not required]** **Secret**. This is an optional field to authenticate WebHook POST. There maybe cases when a special password or a secret might be required. For example the WebHook address was generated explicitly with a password so that to prevent any third parties to use it. This could be your specific WebHook address that you use to send your Wordpress posts into your server.
#### List of Expected Config fields
* **[required]** **HTTP Verb**
* **POST**. The WebHook component can POST information to preconfigured WebHook address. This action could be used for different purposes. For example WebHook can be used to inform your custom connector about an event which it waits to work.
* **PUT**. The WebHook component can also PUT a specific preconfigured JSON into specific address where the process will not be handled by the server. For this reason the "Output JSON Sample" field can be used.
* **[required]** **URI**. This is the address to send WebHook.
* **[not required]** **Secret**. This is an optional field to authenticate WebHook POST. There maybe cases when a special password or a secret might be required. For example the WebHook address was generated explicitly with a password so that to prevent any third parties to use it. This could be your specific WebHook address that you use to send your Wordpress posts into your server.

![Send Data config fields](https://user-images.githubusercontent.com/8449044/61964168-eff1b200-afd5-11e9-8928-2890c3360d13.png)

![Send Data config fields](https://user-images.githubusercontent.com/8449044/61964168-eff1b200-afd5-11e9-8928-2890c3360d13.png)
#### Expected output metadata
[Output schema](lib/schemas/base64.out.json)

Example:
```metadata json
{
"recievedBody": "recievedBody",
"_query": {},
"_headers": {
"content-type": "application/json",
"accept": "*/*",
"accept-encoding": "gzip, deflate"
},
"_method": "POST",
"_url": "/hook/5d691738cb5a286adc1e68e2"
}
```

## Known Limitations
## Known limitations

1. Maximal possible size for an attachment is 10 MB.
2. Attachments mechanism does not work with [Local Agent Installation](https://support.elastic.io/support/solutions/articles/14000076461-announcing-the-local-agent-)
13 changes: 0 additions & 13 deletions circle.yml

This file was deleted.

30 changes: 10 additions & 20 deletions component.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,18 @@
"triggers": {
"receive": {
"title": "Receive",
"description": "Receive trigger has 3 fields: the WebHook URL to send your data, HMAC to secure your WebHook and sample data field to define your incoming message.",
"main": "./receive.js",
"fields": {
"payload": {
"viewClass": "WebHookPayloadView",
"label": "Sample data",
"required": true,
"placeholder": "{ \"foo\" : \"bar\" }"
}
},
"description": "Simple webhook trigger which receives data as an input and starts the flow execution after this.",
"main": "./lib/triggers/receive.js",
"metadata": {
"out": {}
"in": {},
"out": "./lib/schemas/metadata.out.json"
}
}
},
"actions": {
"post": {
"title": "Send data",
"main": "./send.js",
"main": "./lib/actions/send.js",
"fields": {
"method": {
"viewClass": "SelectView",
Expand All @@ -54,15 +47,12 @@
"viewClass": "TextFieldView",
"label": "Secret",
"required": false
},
"outputSample":{
"viewClass":"OutMetadataView",
"label":"Output JSON Sample",
"required":true,
"default" : "{ \"response\": \"ok\" }",
"placeholder" : "{ \"message\" : \"hello world\" }"
}
}
},
"metadata": {
"in": {},
"out": "./lib/schemas/metadata.out.json"
}
}
}
}
5 changes: 0 additions & 5 deletions get.js

This file was deleted.

0 comments on commit f061c15

Please sign in to comment.