Skip to content

Commit f9ed225

Browse files
Update Sailor to 2.6.7 (#34)
1 parent 972c385 commit f9ed225

File tree

11 files changed

+1411
-1070
lines changed

11 files changed

+1411
-1070
lines changed

.eslintrc.js

Lines changed: 3 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -1,160 +1,7 @@
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-
91
module.exports = {
2+
'extends': 'airbnb-base',
103
'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
4+
'mocha': true,
5+
'node': true,
1596
}
1607
};

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.2.2 (May 19, 2020)
2+
3+
* Update sailor version to 2.6.7
4+
* "Send data" Action become deprecated
5+
16
## 1.2.1 (March 26, 2020)
27
* Add help messages to the trigger and action
38

component.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"link": "/components/webhook/index.html#send-data"
3535
},
3636
"main": "./lib/actions/send.js",
37+
"deprecated": true,
3738
"fields": {
3839
"method": {
3940
"viewClass": "SelectView",

lib/actions/send.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const request = require('../helper/request.js');
2+
23
const DEFAULT_METHOD = 'POST';
34

45
// eslint-disable-next-line func-names
56
exports.process = function (msg, conf) {
6-
request.putOrPost.call(this, conf.method || DEFAULT_METHOD, msg, conf);
7+
request.putOrPost.call(this, conf.method || DEFAULT_METHOD, msg, conf);
78
};

lib/helper/get.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ const request = require('./request.js');
22

33
// eslint-disable-next-line func-names
44
exports.process = function (msg, conf) {
5-
request.get.call(this, msg, conf);
5+
request.get.call(this, msg, conf);
66
};

lib/helper/request.js

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,83 @@
1+
/* eslint-disable no-use-before-define */
12
const request = require('request');
23
const qs = require('querystring');
3-
const messages = require('elasticio-node').messages;
4+
const { messages } = require('elasticio-node');
45

56
exports.putOrPost = function putOrPost(method, msg, conf) {
6-
const uri = conf.uri;
7-
const body = msg.body;
7+
const { uri } = conf;
8+
const { body } = msg;
89

9-
this.logger.info('Request body: %j', body);
10+
this.logger.info('Request body: %j', body);
1011

11-
const requestSettings = buildRequestSettings(method, uri, conf.secret);
12-
requestSettings.body = JSON.stringify(body);
13-
requestSettings.headers['Content-Type'] = 'application/json;charset=UTF-8';
12+
const requestSettings = buildRequestSettings(method, uri, conf.secret);
13+
requestSettings.body = JSON.stringify(body);
14+
requestSettings.headers['Content-Type'] = 'application/json;charset=UTF-8';
1415

15-
request(requestSettings, callback.bind(this));
16+
request(requestSettings, callback.bind(this));
1617
};
1718

1819
exports.get = function get(msg, conf) {
19-
let uri = conf.uri;
20+
let { uri } = conf;
2021

21-
// Check if URI ends in ? If it doesn't add one.
22-
if (uri.charAt(uri.length - 1) !== '?') {
23-
uri += '?';
24-
}
22+
// Check if URI ends in ? If it doesn't add one.
23+
if (uri.charAt(uri.length - 1) !== '?') {
24+
uri += '?';
25+
}
2526

26-
uri += qs.stringify(msg.body);
27+
uri += qs.stringify(msg.body);
2728

28-
const requestSettings = buildRequestSettings('GET', uri, conf.secret);
29-
request(requestSettings, callback.bind(this));
29+
const requestSettings = buildRequestSettings('GET', uri, conf.secret);
30+
request(requestSettings, callback.bind(this));
3031
};
3132

3233
function buildRequestSettings(method, uri, secret) {
33-
const requestSettings = {
34-
uri: uri,
35-
method: method,
36-
headers: {}
37-
};
34+
const requestSettings = {
35+
uri,
36+
method,
37+
headers: {},
38+
};
3839

39-
if (secret) {
40-
requestSettings.headers['X-Api-Secret'] = secret;
41-
}
40+
if (secret) {
41+
requestSettings.headers['X-Api-Secret'] = secret;
42+
}
4243

43-
return requestSettings;
44+
return requestSettings;
4445
}
4546

4647

4748
function callback(err, response, body) {
48-
if (err) {
49-
this.emit('error', err);
50-
this.emit('end');
51-
return;
52-
}
53-
54-
const sc = response.statusCode;
55-
56-
if (sc >= 200 && sc <= 206) {
57-
this.emit('data', newMessage(response, body));
58-
} else {
59-
this.emit('error', new Error('Endpoint responds with ' + sc));
60-
}
49+
if (err) {
50+
this.emit('error', err);
6151
this.emit('end');
52+
return;
53+
}
54+
55+
const sc = response.statusCode;
56+
57+
if (sc >= 200 && sc <= 206) {
58+
this.emit('data', newMessage(response, body));
59+
} else {
60+
this.emit('error', new Error(`Endpoint responds with ${sc}`));
61+
}
62+
this.emit('end');
6263
}
6364

6465
function newMessage(response, body) {
65-
const headers = response.headers;
66-
const contentType = headers['content-type'];
67-
const msgBody = getJSONBody(contentType, body);
68-
const msg = messages.newMessageWithBody(msgBody);
69-
msg.headers = headers;
66+
const { headers } = response;
67+
const contentType = headers['content-type'];
68+
const msgBody = getJSONBody(contentType, body);
69+
const msg = messages.newMessageWithBody(msgBody);
70+
msg.headers = headers;
7071

71-
return msg;
72+
return msg;
7273
}
7374

7475
function getJSONBody(contentType, body) {
75-
if (contentType && contentType.indexOf('application/json') === 0) {
76-
return JSON.parse(body);
77-
}
76+
if (contentType && contentType.indexOf('application/json') === 0) {
77+
return JSON.parse(body);
78+
}
7879

79-
return {
80-
responseBody: body
81-
};
80+
return {
81+
responseBody: body,
82+
};
8283
}

lib/triggers/receive.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1+
/* eslint-disable no-underscore-dangle,no-param-reassign */
12
exports.process = async function receive(msg) {
2-
const msgId = msg.id;
3-
this.logger.info('Received new message:\n', JSON.stringify(msg));
3+
const msgId = msg.id;
4+
this.logger.info('Received new message:\n', JSON.stringify(msg));
45

5-
if (msg.body) {
6-
if (msg.query) {
7-
msg.body._query = msg.query;
8-
}
9-
10-
if (msg.headers) {
11-
msg.body._headers = msg.headers;
12-
}
13-
if (msg.method) {
14-
msg.body._method = msg.method;
15-
}
6+
if (msg.body) {
7+
if (msg.query) {
8+
msg.body._query = msg.query;
9+
}
1610

17-
if (msg.url) {
18-
msg.body._url = msg.url;
19-
}
11+
if (msg.headers) {
12+
msg.body._headers = msg.headers;
13+
}
14+
if (msg.method) {
15+
msg.body._method = msg.method;
16+
}
2017

21-
if (msg.additionalUrlPath) {
22-
msg.body._additionalUrlPath = msg.additionalUrlPath;
23-
}
18+
if (msg.url) {
19+
msg.body._url = msg.url;
20+
}
2421

25-
this.logger.info('Updated body: \n', JSON.stringify(msg.body));
22+
if (msg.additionalUrlPath) {
23+
msg.body._additionalUrlPath = msg.additionalUrlPath;
2624
}
2725

28-
this.logger.info('Emitting data of message: ', msgId);
29-
await this.emit('data', msg);
30-
this.logger.info('Data emitted');
31-
};
26+
this.logger.info('Updated body: \n', JSON.stringify(msg.body));
27+
}
3228

29+
this.logger.info('Emitting data of message: ', msgId);
30+
await this.emit('data', msg);
31+
this.logger.info('Data emitted');
32+
};

0 commit comments

Comments
 (0)