Skip to content

Commit f061c15

Browse files
shanthoshpOlha Virolainen
authored andcommitted
Webhook should include additional information in the call (#19)
* update sailor logger * refactor to es6 * Add CHANGELOG.md * Add eslint * Refactor unit test * circleCI test * Update dependencies * Fix eslint * Update readme * Update logging
1 parent 2e75ff4 commit f061c15

19 files changed

+3730
-417
lines changed

.circleci/build_slug.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

.circleci/config.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: 2
2+
jobs:
3+
test:
4+
docker:
5+
- image: circleci/node:12-stretch
6+
steps:
7+
- checkout
8+
- restore_cache:
9+
key: dependency-cache-{{ checksum "package.json" }}
10+
- run:
11+
name: Installing Dependencies
12+
command: npm install
13+
- save_cache:
14+
key: dependency-cache-{{ checksum "package.json" }}
15+
paths:
16+
- node_modules
17+
- run:
18+
name: Running Mocha Tests
19+
command: npm test
20+
workflows:
21+
version: 2
22+
build_and_test:
23+
jobs:
24+
- test

.eslintrc.js

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
'use strict';
2+
3+
const ERROR = 'error';
4+
const WARN = 'warn';
5+
const ALWAYS = 'always';
6+
const NEVER = 'never';
7+
const OFF = 'off';
8+
9+
module.exports = {
10+
'env': {
11+
es6: true,
12+
node: true,
13+
mocha: true
14+
},
15+
'parserOptions': {
16+
ecmaVersion: 2017
17+
},
18+
'extends': 'eslint:recommended',
19+
'plugins': [
20+
'mocha'
21+
],
22+
'rules': {
23+
'indent': [
24+
ERROR,
25+
4,
26+
{
27+
SwitchCase: 1
28+
}
29+
],
30+
'linebreak-style': ERROR,
31+
'quotes': [
32+
WARN,
33+
'single',
34+
{
35+
avoidEscape: true,
36+
allowTemplateLiterals: true
37+
}
38+
],
39+
'semi': [
40+
ERROR,
41+
ALWAYS
42+
],
43+
'func-names': WARN,
44+
'no-empty': ERROR,
45+
'no-empty-function': ERROR,
46+
'brace-style': [
47+
ERROR,
48+
'1tbs',
49+
{ allowSingleLine: true }
50+
],
51+
'no-multiple-empty-lines': ERROR,
52+
'no-multi-spaces': ERROR,
53+
'one-var': [
54+
ERROR,
55+
NEVER
56+
],
57+
'quote-props': [
58+
WARN,
59+
'consistent-as-needed'
60+
],
61+
'key-spacing': ERROR,
62+
'space-unary-ops': [
63+
ERROR,
64+
{
65+
words: true,
66+
nonwords: false
67+
}
68+
],
69+
'no-spaced-func': ERROR,
70+
'space-before-function-paren': [
71+
ERROR,
72+
{
73+
anonymous: ALWAYS,
74+
named: NEVER
75+
}
76+
],
77+
'arrow-body-style': [
78+
WARN,
79+
'as-needed'
80+
],
81+
'array-bracket-spacing': ERROR,
82+
'space-in-parens': ERROR,
83+
'comma-dangle': WARN,
84+
'no-trailing-spaces': ERROR,
85+
'yoda': ERROR,
86+
'max-len': [
87+
ERROR,
88+
120
89+
],
90+
'camelcase': [
91+
ERROR,
92+
{
93+
properties: 'never'
94+
}
95+
],
96+
'new-cap': [
97+
WARN,
98+
{
99+
capIsNewExceptions: ['Q']
100+
}
101+
],
102+
'comma-style': ERROR,
103+
'curly': ERROR,
104+
'object-curly-spacing': [
105+
WARN,
106+
ALWAYS
107+
],
108+
'object-curly-newline': [
109+
OFF
110+
],
111+
'object-property-newline': OFF,
112+
'template-curly-spacing': ERROR,
113+
'dot-notation': ERROR,
114+
'dot-location': [
115+
ERROR,
116+
'property'
117+
],
118+
'func-style': [
119+
ERROR,
120+
'declaration',
121+
{
122+
allowArrowFunctions: true
123+
}
124+
],
125+
'eol-last': ERROR,
126+
'space-infix-ops': ERROR,
127+
'keyword-spacing': ERROR,
128+
'space-before-blocks': ERROR,
129+
'no-invalid-this': ERROR,
130+
'consistent-this': ERROR,
131+
'no-this-before-super': ERROR,
132+
'no-unreachable': ERROR,
133+
'no-sparse-arrays': ERROR,
134+
'array-callback-return': ERROR,
135+
'strict': [
136+
OFF,
137+
'global'
138+
],
139+
'eqeqeq': ERROR,
140+
'no-use-before-define': WARN,
141+
'no-undef': ERROR,
142+
'no-unused-vars': WARN,
143+
'no-mixed-spaces-and-tabs': ERROR,
144+
'operator-linebreak': [
145+
ERROR,
146+
'before'
147+
],
148+
'no-console': [
149+
WARN,
150+
{
151+
'allow': [
152+
'warn',
153+
'error'
154+
]
155+
}
156+
],
157+
'mocha/no-exclusive-tests': ERROR,
158+
'mocha/no-skipped-tests': ERROR
159+
}
160+
};

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## 1.1.0 (July 29, 2019)
2+
3+
* Migrate to es6
4+
* Refactor unit tests and component structure
5+
* Add additional information to the webhook call
6+
7+
## 1.0.0 (March 23, 2016)
8+
9+
* Initial release

README.md

Lines changed: 61 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
# webhook-component
2+
## Table of Contents
3+
4+
* [General information](#general-information)
5+
* [Description](#description)
6+
* [Purpose](#purpose)
7+
* [Credentials](#credentials)
8+
* [Triggers](#triggers)
9+
* [Receive](#receive)
10+
* [Actions](#actions)
11+
* [Send data](#send-data)
12+
* [Known Limitations](#known-limitations)
213

314
## Description
15+
### Purpose
416
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").
517

6-
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.
7-
818
## Credentials
919
Webhook component supports the following authorisation types:
1020
* **No Auth** - use this method to work with any open REST API
@@ -15,44 +25,62 @@ Webhook component supports the following authorisation types:
1525
![Webhook Credentials](https://user-images.githubusercontent.com/8449044/61962330-ec5c2c00-afd1-11e9-8e5f-6a1c89126034.png)
1626

1727
## Triggers
18-
### Receive
19-
Simple webhook trigger which receives data as an input and starts the flow execution after this.
20-
21-
Receive trigger has 1 field: sample data field to define your incoming message.
28+
### Receive
29+
Simple webhook trigger which receives data as an input and starts the flow execution after this.
2230

23-
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.
24-
You are able to input your desired data structure either as JSON data, XML or as List of properties.
25-
26-
#### Sending JSON
27-
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.
28-
```json
31+
#### Expected output metadata
32+
[Output schema](lib/schemas/base64.out.json)
33+
34+
Example:
35+
```metadata json
2936
{
30-
"foo" : "bar",
31-
"myJSON" : "is the best!"
32-
}
37+
"recievedBody": "recievedBody",
38+
"_query": {},
39+
"_headers": {
40+
"content-type": "application/json",
41+
"accept": "*/*",
42+
"accept-encoding": "gzip, deflate"
43+
},
44+
"_method": "POST",
45+
"_url": "/hook/5d691738cb5a286adc1e68e2"
46+
}
3347
```
3448

35-
#### Receive. Config fields
36-
* **[required]** Payload. This is the place you define your incoming data.
37-
Renders an input text area field to define a payload metadata for the WebHook component.
38-
39-
## Actions
40-
### Send Data
41-
Simply sends data it receives as an input to a URL provided.
42-
43-
WebHook action can also be used to troubleshoot many processes to see the outcome.
44-
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.
49+
## Actions
50+
### Send data
51+
Simply sends data it receives as an input to a URL provided.
52+
53+
WebHook action can also be used to troubleshoot many processes to see the outcome.
54+
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.
4555

46-
#### Send Data. Config fields
47-
* **[required]** **HTTP Verb**
48-
* **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.
49-
* **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.
50-
* **[required]** **URI**. This is the address to send WebHook.
51-
* **[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.
56+
#### List of Expected Config fields
57+
* **[required]** **HTTP Verb**
58+
* **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.
59+
* **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.
60+
* **[required]** **URI**. This is the address to send WebHook.
61+
* **[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.
62+
63+
![Send Data config fields](https://user-images.githubusercontent.com/8449044/61964168-eff1b200-afd5-11e9-8928-2890c3360d13.png)
5264

53-
![Send Data config fields](https://user-images.githubusercontent.com/8449044/61964168-eff1b200-afd5-11e9-8928-2890c3360d13.png)
65+
#### Expected output metadata
66+
[Output schema](lib/schemas/base64.out.json)
67+
68+
Example:
69+
```metadata json
70+
{
71+
"recievedBody": "recievedBody",
72+
"_query": {},
73+
"_headers": {
74+
"content-type": "application/json",
75+
"accept": "*/*",
76+
"accept-encoding": "gzip, deflate"
77+
},
78+
"_method": "POST",
79+
"_url": "/hook/5d691738cb5a286adc1e68e2"
80+
}
81+
```
5482

55-
## Known Limitations
83+
## Known limitations
5684

5785
1. Maximal possible size for an attachment is 10 MB.
5886
2. Attachments mechanism does not work with [Local Agent Installation](https://support.elastic.io/support/solutions/articles/14000076461-announcing-the-local-agent-)

circle.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

component.json

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,18 @@
1515
"triggers": {
1616
"receive": {
1717
"title": "Receive",
18-
"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.",
19-
"main": "./receive.js",
20-
"fields": {
21-
"payload": {
22-
"viewClass": "WebHookPayloadView",
23-
"label": "Sample data",
24-
"required": true,
25-
"placeholder": "{ \"foo\" : \"bar\" }"
26-
}
27-
},
18+
"description": "Simple webhook trigger which receives data as an input and starts the flow execution after this.",
19+
"main": "./lib/triggers/receive.js",
2820
"metadata": {
29-
"out": {}
21+
"in": {},
22+
"out": "./lib/schemas/metadata.out.json"
3023
}
3124
}
3225
},
3326
"actions": {
3427
"post": {
3528
"title": "Send data",
36-
"main": "./send.js",
29+
"main": "./lib/actions/send.js",
3730
"fields": {
3831
"method": {
3932
"viewClass": "SelectView",
@@ -54,15 +47,12 @@
5447
"viewClass": "TextFieldView",
5548
"label": "Secret",
5649
"required": false
57-
},
58-
"outputSample":{
59-
"viewClass":"OutMetadataView",
60-
"label":"Output JSON Sample",
61-
"required":true,
62-
"default" : "{ \"response\": \"ok\" }",
63-
"placeholder" : "{ \"message\" : \"hello world\" }"
6450
}
65-
}
51+
},
52+
"metadata": {
53+
"in": {},
54+
"out": "./lib/schemas/metadata.out.json"
55+
}
6656
}
6757
}
6858
}

get.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)