elasticio-sailor-nodejs 2.7.1-dev3 → 2.7.1-dev5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,247 +1,247 @@
1
- # elasticio-sailor-nodejs [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url]
2
-
3
- > The official elastic.io library for bootstrapping and executing for Node.js connectors.
4
-
5
- [![NPM](https://nodei.co/npm/elasticio-sailor-nodejs.png?downloads=true)](https://nodei.co/npm/elasticio-sailor-nodejs/)
6
-
7
- `elasticio-sailor-nodejs` is a **required dependency for all components build for [elastic.io platform](http://www.elastic.io) in Node.js**. Add the dependency in the `package.json` file in the following way:
8
-
9
- ```json
10
- "dependencies": {
11
- "q": "^1.4.1",
12
- "elasticio-sailor-nodejs": "^2.2.1",
13
- "elasticio-node": "^0.0.8"
14
- }
15
- ```
16
-
17
- ## Building components in Node.js
18
-
19
- If you plan to build a component for [elastic.io platform](http://www.elastic.io) in Node.js then you can visit our dedicated documentation page which describes [how to build a component in node.js](https://docs.elastic.io/guides/building-nodejs-component).
20
-
21
- ### Before you start
22
-
23
- Before you can deploy any code into our system **you must be a registered elastic.io platform user**. Please see our home page at [http://www.elastic.io](http://www.elastic.io) to learn how.
24
-
25
- > Any attempt to deploy a code into our platform without a registration would fail.
26
-
27
- After the registration and opening of the account you must **[upload your SSH Key](https://docs.elastic.io/guides/ssh-keys)** into our platform.
28
-
29
- > If you fail to upload you SSH Key you will get **permission denied** error during the deployment.
30
-
31
- ### Getting Started
32
-
33
- After registration and uploading of your SSH Key you can proceed to deploy it into our system. At this stage we suggest you to:
34
- * [Create a team](https://docs.elastic.io/guides/teams-and-repos#creating-a-developer-team) to work on your new component. This is not required but will be automatically created using random naming by our system so we suggest you name your team accordingly.
35
- * [Create a repository](https://docs.elastic.io/guides/teams-and-repos#create-a-component-repository) inside the team to deploy your new component code.
36
-
37
- ### Examples of Node.js components
38
-
39
- Here is a list of components build on Node.js:
40
-
41
- * [petstore-component-nodejs](https://github.com/elasticio/petstore-component-nodejs) to build your first component
42
- * [code-component](https://github.com/elasticio/code-component) to run pieces of synchronous JavaScript inside your integration flow,
43
- * [webhook-component](https://github.com/elasticio/webhook-component) to send and receive WebHooks on elastic.io platform,
44
- * [csv-component](https://github.com/elasticio/csv-component) to work with CSV files in your integration flow,
45
- * [sugarcrm-component](https://github.com/elasticio/sugarcrm-component) to use Sugar CRM in your integrations
46
-
47
- [travis-image]: https://travis-ci.org/elasticio/sailor-nodejs.svg?branch=master
48
- [travis-url]: https://travis-ci.org/elasticio/sailor-nodejs
49
- [daviddm-image]: https://david-dm.org/elasticio/sailor-nodejs.svg?theme=shields.io
50
- [daviddm-url]: https://david-dm.org/elasticio/sailor-nodejs
51
-
52
- ## Sailor logging
53
-
54
- Sailor uses [bunyan](https://github.com/trentm/node-bunyan) logging framework.
55
-
56
- Supported log levels are:
57
-
58
- - `FATAL`
59
- - `ERROR`
60
- - `WARN`
61
- - `INFO`
62
- - `DEBUG`
63
- - `TRACE`
64
-
65
- Default log level is `INFO`. You can change default log level with environment variable `LOG_LEVEL`.
66
-
67
- Sailor logger adds the following extra context to log messages:
68
-
69
- - `ELASTICIO_API_USERNAME`
70
- - `ELASTICIO_COMP_ID`
71
- - `ELASTICIO_COMP_NAME`
72
- - `ELASTICIO_CONTAINER_ID`
73
- - `ELASTICIO_CONTRACT_ID`
74
- - `ELASTICIO_EXEC_ID`
75
- - `ELASTICIO_EXEC_TYPE`
76
- - `ELASTICIO_EXECUTION_RESULT_ID`
77
- - `ELASTICIO_FLOW_ID`
78
- - `ELASTICIO_FLOW_VERSION`
79
- - `ELASTICIO_FUNCTION`
80
- - `ELASTICIO_STEP_ID`
81
- - `ELASTICIO_TASK_USER_EMAIL`
82
- - `ELASTICIO_TENANT_ID`
83
- - `ELASTICIO_USER_ID`
84
- - `ELASTICIO_WORKSPACE_ID`
85
-
86
- ## Component logging
87
-
88
- Sailor exposes logger object for use in a component. Component logger inherits log level from sailor's logger
89
- and adds the following extra context to log messages:
90
-
91
- - `messageId` (unique ID of the next RabbitMQ message)
92
- - `parentMessageId` (unique ID of previous RabbitMQ message)
93
- - `threadId` (unique ID of execution thread)
94
-
95
- Component logger usage example:
96
-
97
- ```JavaScript
98
- this.logger.fatal('message');
99
- this.logger.error('message');
100
- this.logger.warn('message');
101
- this.logger.info('message');
102
- this.logger.debug('message');
103
- this.logger.trace('message');
104
- ```
105
-
106
- ## Flow control
107
-
108
- When working in the multi-tenant integration environment it's important to obey the API and
109
- consumption limits imposed by the platform. This is not only a condition for you integrations to
110
- run on the platform (and not begin suspended), but also a good integration practice to sustainably
111
- and efficiently use resources.
112
-
113
- Imagine a system where one party (published) publishes to the queue and one or more consumers
114
- consume from the queue. If publishers are writing to the queue faster than consumers read data
115
- from the queue, queue will earlier or later be overfilled. Once one queue of your integration flow
116
- will grow to a particular limit, the complete integration flow will be suspended and author will be
117
- informed about it. Flow control is a build-in mechanism in the SDK that will help you to prevent
118
- the overflow to happen.
119
-
120
- There are two types of flow control:
121
- * Static flow control - the hard limit of the events (e.g. messages published to the queue) that can
122
- be generated by component. This limit is dictated by your pricing plan and will limit protect the
123
- platform from extensive load.
124
- * Dynamic flow control - the limit that is imposed based on the state of individual queue, more
125
- messages are in the queue, slower publisher could write to it.
126
-
127
- Let's take a look at the simple example:
128
-
129
- ```JavaScript
130
- 'use strict';
131
-
132
- exports.process = process;
133
-
134
- async function process(msg, cfg, snapshot) {
135
- for (let i = 0; i < 100000; i++) {
136
- this.logger.info('Sending message %s', i);
137
- await this.emit('data', {
138
- body: {
139
- counter: i,
140
- hi: 'there'
141
- }
142
- });
143
- this.logger.info('Message %s was sent', i);
144
- }
145
- }
146
- ```
147
-
148
- This simple component, once started on the platform will generate 100k messages. Without flow control this
149
- example will quickly bring the integration queue to the limits and integration flow will be suspended.
150
- With flow control the publishing rate of the messages will be slowed down so both publisher and consumers
151
- will operate in balance.
152
-
153
- ### How to configure it
154
-
155
- There is a set of environment variables that are responsible for the configuration of the static flow control
156
- (dynamic flow control is implemented in the message-oriented middleware of the platform hence can't be configured
157
- on the component level)
158
-
159
- * ELASTICIO_DATA_RATE_LIMIT - a number of maximum `data` messages per second that could be emitted
160
- by the component
161
-
162
- * ELASTICIO_SNAPSHOT_RATE_LIMIT - a number of maximum `snapshot` messages per second that could be emitted
163
- by the component
164
-
165
- * ELASTICIO_PROCESS_AMQP_DRAIN, (boolean) - true value means that 'emit' method in component would return
166
- promise which will resolve to true value when amqplib inner buffer would be empty. Preventing OutOfMemoryError
167
- on buffer overflow.
168
-
169
- ## Sailor hooks
170
-
171
- ### Init hook
172
-
173
- ```javascript
174
- /**
175
- * cfg - This is the same config as the one passed to "processMessage" method of the trigger or action
176
- */
177
- exports.init = function(cfg) {
178
- //do stuff
179
- return Promise.resolve();
180
- }
181
- ```
182
-
183
- ### Startup hook
184
-
185
- ```javascript
186
- /**
187
- * cfg - This is the same config as the one passed to "processMessage" method of the trigger or action
188
- */
189
- exports.startup = function(cfg) {
190
- //do stuff
191
- const data = {
192
- message: 'Hello from STARTUP_HOOK'
193
- };
194
- return Promise.resolve(data);
195
- }
196
- ```
197
-
198
- - Only on the first trigger
199
- - Called without ``this``
200
- - May return promise
201
- - May return value
202
- - May throw - not recommended
203
- - May return a promise that will fail
204
-
205
- - Startup logs can be found in the tab of the component on execution page
206
- - TBD - Separate them under different tab in UI
207
- - TBD - Where to see restart errors?overwritten
208
-
209
- Startup state data - either return value or the result of the promise
210
-
211
- - OK
212
- - Results will be stored as the startup state, previous will be overwritten with warning
213
- - After that init hook will be run, etc
214
- - NOK
215
- - Sailor will exit the process
216
- - Platform will restart the component immediately
217
- - If init wont' happen it will be removed after 5 minutes (see restart policy)
218
- - In the next scheduling interval initialisation will repeat
219
-
220
- ### Shutdown hook
221
-
222
- ```javascript
223
- /**
224
- * cfg - This is the same config as the one passed to "processMessage" method of the trigger or action
225
- * startData - result from the startup
226
- */
227
- exports.shutdown = function(cfg, startData) {
228
- //corresponding to the startup example above, startData is { message: 'Hello from STARTUP_HOOK' }
229
- //do stuff
230
- return Promise.resolve();
231
- }
232
- ```
233
-
234
- - Only on the first trigger
235
- - One stop is pressed
236
- - If task is running then containers are shutdown
237
- - If task is sleeping then do nothing
238
- - Start new trigger container
239
- - Trigger starts without ``this`` context - it's not possible to log errors or send new data
240
- - Should either return value (ignored) or promise (resolved).
241
- - Startup data is removed after shutdown hook
242
- - Call the shutdown hook, parameters that are passed is from the startup results or ``{}`` if nothing was returned
243
- - Errors are ignored
244
- - If shutdown hook won't complete within 60 seconds then container will be killed
245
- - As soon as user pressed stop, task is marked as inactive and 'webhooks gateway' will start responding with the error (Task either does not exist or is inactive) to possible data
246
-
247
- TBD - log for shutdown hooks?
1
+ # elasticio-sailor-nodejs [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url]
2
+
3
+ > The official elastic.io library for bootstrapping and executing for Node.js connectors.
4
+
5
+ [![NPM](https://nodei.co/npm/elasticio-sailor-nodejs.png?downloads=true)](https://nodei.co/npm/elasticio-sailor-nodejs/)
6
+
7
+ `elasticio-sailor-nodejs` is a **required dependency for all components build for [elastic.io platform](http://www.elastic.io) in Node.js**. Add the dependency in the `package.json` file in the following way:
8
+
9
+ ```json
10
+ "dependencies": {
11
+ "q": "^1.4.1",
12
+ "elasticio-sailor-nodejs": "^2.2.1",
13
+ "elasticio-node": "^0.0.8"
14
+ }
15
+ ```
16
+
17
+ ## Building components in Node.js
18
+
19
+ If you plan to build a component for [elastic.io platform](http://www.elastic.io) in Node.js then you can visit our dedicated documentation page which describes [how to build a component in node.js](https://docs.elastic.io/guides/building-nodejs-component).
20
+
21
+ ### Before you start
22
+
23
+ Before you can deploy any code into our system **you must be a registered elastic.io platform user**. Please see our home page at [http://www.elastic.io](http://www.elastic.io) to learn how.
24
+
25
+ > Any attempt to deploy a code into our platform without a registration would fail.
26
+
27
+ After the registration and opening of the account you must **[upload your SSH Key](https://docs.elastic.io/guides/ssh-keys)** into our platform.
28
+
29
+ > If you fail to upload you SSH Key you will get **permission denied** error during the deployment.
30
+
31
+ ### Getting Started
32
+
33
+ After registration and uploading of your SSH Key you can proceed to deploy it into our system. At this stage we suggest you to:
34
+ * [Create a team](https://docs.elastic.io/guides/teams-and-repos#creating-a-developer-team) to work on your new component. This is not required but will be automatically created using random naming by our system so we suggest you name your team accordingly.
35
+ * [Create a repository](https://docs.elastic.io/guides/teams-and-repos#create-a-component-repository) inside the team to deploy your new component code.
36
+
37
+ ### Examples of Node.js components
38
+
39
+ Here is a list of components build on Node.js:
40
+
41
+ * [petstore-component-nodejs](https://github.com/elasticio/petstore-component-nodejs) to build your first component
42
+ * [code-component](https://github.com/elasticio/code-component) to run pieces of synchronous JavaScript inside your integration flow,
43
+ * [webhook-component](https://github.com/elasticio/webhook-component) to send and receive WebHooks on elastic.io platform,
44
+ * [csv-component](https://github.com/elasticio/csv-component) to work with CSV files in your integration flow,
45
+ * [sugarcrm-component](https://github.com/elasticio/sugarcrm-component) to use Sugar CRM in your integrations
46
+
47
+ [travis-image]: https://travis-ci.org/elasticio/sailor-nodejs.svg?branch=master
48
+ [travis-url]: https://travis-ci.org/elasticio/sailor-nodejs
49
+ [daviddm-image]: https://david-dm.org/elasticio/sailor-nodejs.svg?theme=shields.io
50
+ [daviddm-url]: https://david-dm.org/elasticio/sailor-nodejs
51
+
52
+ ## Sailor logging
53
+
54
+ Sailor uses [bunyan](https://github.com/trentm/node-bunyan) logging framework.
55
+
56
+ Supported log levels are:
57
+
58
+ - `FATAL`
59
+ - `ERROR`
60
+ - `WARN`
61
+ - `INFO`
62
+ - `DEBUG`
63
+ - `TRACE`
64
+
65
+ Default log level is `INFO`. You can change default log level with environment variable `LOG_LEVEL`.
66
+
67
+ Sailor logger adds the following extra context to log messages:
68
+
69
+ - `ELASTICIO_API_USERNAME`
70
+ - `ELASTICIO_COMP_ID`
71
+ - `ELASTICIO_COMP_NAME`
72
+ - `ELASTICIO_CONTAINER_ID`
73
+ - `ELASTICIO_CONTRACT_ID`
74
+ - `ELASTICIO_EXEC_ID`
75
+ - `ELASTICIO_EXEC_TYPE`
76
+ - `ELASTICIO_EXECUTION_RESULT_ID`
77
+ - `ELASTICIO_FLOW_ID`
78
+ - `ELASTICIO_FLOW_VERSION`
79
+ - `ELASTICIO_FUNCTION`
80
+ - `ELASTICIO_STEP_ID`
81
+ - `ELASTICIO_TASK_USER_EMAIL`
82
+ - `ELASTICIO_TENANT_ID`
83
+ - `ELASTICIO_USER_ID`
84
+ - `ELASTICIO_WORKSPACE_ID`
85
+
86
+ ## Component logging
87
+
88
+ Sailor exposes logger object for use in a component. Component logger inherits log level from sailor's logger
89
+ and adds the following extra context to log messages:
90
+
91
+ - `messageId` (unique ID of the next RabbitMQ message)
92
+ - `parentMessageId` (unique ID of previous RabbitMQ message)
93
+ - `threadId` (unique ID of execution thread)
94
+
95
+ Component logger usage example:
96
+
97
+ ```JavaScript
98
+ this.logger.fatal('message');
99
+ this.logger.error('message');
100
+ this.logger.warn('message');
101
+ this.logger.info('message');
102
+ this.logger.debug('message');
103
+ this.logger.trace('message');
104
+ ```
105
+
106
+ ## Flow control
107
+
108
+ When working in the multi-tenant integration environment it's important to obey the API and
109
+ consumption limits imposed by the platform. This is not only a condition for you integrations to
110
+ run on the platform (and not begin suspended), but also a good integration practice to sustainably
111
+ and efficiently use resources.
112
+
113
+ Imagine a system where one party (published) publishes to the queue and one or more consumers
114
+ consume from the queue. If publishers are writing to the queue faster than consumers read data
115
+ from the queue, queue will earlier or later be overfilled. Once one queue of your integration flow
116
+ will grow to a particular limit, the complete integration flow will be suspended and author will be
117
+ informed about it. Flow control is a build-in mechanism in the SDK that will help you to prevent
118
+ the overflow to happen.
119
+
120
+ There are two types of flow control:
121
+ * Static flow control - the hard limit of the events (e.g. messages published to the queue) that can
122
+ be generated by component. This limit is dictated by your pricing plan and will limit protect the
123
+ platform from extensive load.
124
+ * Dynamic flow control - the limit that is imposed based on the state of individual queue, more
125
+ messages are in the queue, slower publisher could write to it.
126
+
127
+ Let's take a look at the simple example:
128
+
129
+ ```JavaScript
130
+ 'use strict';
131
+
132
+ exports.process = process;
133
+
134
+ async function process(msg, cfg, snapshot) {
135
+ for (let i = 0; i < 100000; i++) {
136
+ this.logger.info('Sending message %s', i);
137
+ await this.emit('data', {
138
+ body: {
139
+ counter: i,
140
+ hi: 'there'
141
+ }
142
+ });
143
+ this.logger.info('Message %s was sent', i);
144
+ }
145
+ }
146
+ ```
147
+
148
+ This simple component, once started on the platform will generate 100k messages. Without flow control this
149
+ example will quickly bring the integration queue to the limits and integration flow will be suspended.
150
+ With flow control the publishing rate of the messages will be slowed down so both publisher and consumers
151
+ will operate in balance.
152
+
153
+ ### How to configure it
154
+
155
+ There is a set of environment variables that are responsible for the configuration of the static flow control
156
+ (dynamic flow control is implemented in the message-oriented middleware of the platform hence can't be configured
157
+ on the component level)
158
+
159
+ * ELASTICIO_DATA_RATE_LIMIT - a number of maximum `data` messages per second that could be emitted
160
+ by the component
161
+
162
+ * ELASTICIO_SNAPSHOT_RATE_LIMIT - a number of maximum `snapshot` messages per second that could be emitted
163
+ by the component
164
+
165
+ * ELASTICIO_PROCESS_AMQP_DRAIN, (boolean) - true value means that 'emit' method in component would return
166
+ promise which will resolve to true value when amqplib inner buffer would be empty. Preventing OutOfMemoryError
167
+ on buffer overflow.
168
+
169
+ ## Sailor hooks
170
+
171
+ ### Init hook
172
+
173
+ ```javascript
174
+ /**
175
+ * cfg - This is the same config as the one passed to "processMessage" method of the trigger or action
176
+ */
177
+ exports.init = function(cfg) {
178
+ //do stuff
179
+ return Promise.resolve();
180
+ }
181
+ ```
182
+
183
+ ### Startup hook
184
+
185
+ ```javascript
186
+ /**
187
+ * cfg - This is the same config as the one passed to "processMessage" method of the trigger or action
188
+ */
189
+ exports.startup = function(cfg) {
190
+ //do stuff
191
+ const data = {
192
+ message: 'Hello from STARTUP_HOOK'
193
+ };
194
+ return Promise.resolve(data);
195
+ }
196
+ ```
197
+
198
+ - Only on the first trigger
199
+ - Called without ``this``
200
+ - May return promise
201
+ - May return value
202
+ - May throw - not recommended
203
+ - May return a promise that will fail
204
+
205
+ - Startup logs can be found in the tab of the component on execution page
206
+ - TBD - Separate them under different tab in UI
207
+ - TBD - Where to see restart errors?overwritten
208
+
209
+ Startup state data - either return value or the result of the promise
210
+
211
+ - OK
212
+ - Results will be stored as the startup state, previous will be overwritten with warning
213
+ - After that init hook will be run, etc
214
+ - NOK
215
+ - Sailor will exit the process
216
+ - Platform will restart the component immediately
217
+ - If init wont' happen it will be removed after 5 minutes (see restart policy)
218
+ - In the next scheduling interval initialisation will repeat
219
+
220
+ ### Shutdown hook
221
+
222
+ ```javascript
223
+ /**
224
+ * cfg - This is the same config as the one passed to "processMessage" method of the trigger or action
225
+ * startData - result from the startup
226
+ */
227
+ exports.shutdown = function(cfg, startData) {
228
+ //corresponding to the startup example above, startData is { message: 'Hello from STARTUP_HOOK' }
229
+ //do stuff
230
+ return Promise.resolve();
231
+ }
232
+ ```
233
+
234
+ - Only on the first trigger
235
+ - One stop is pressed
236
+ - If task is running then containers are shutdown
237
+ - If task is sleeping then do nothing
238
+ - Start new trigger container
239
+ - Trigger starts without ``this`` context - it's not possible to log errors or send new data
240
+ - Should either return value (ignored) or promise (resolved).
241
+ - Startup data is removed after shutdown hook
242
+ - Call the shutdown hook, parameters that are passed is from the startup results or ``{}`` if nothing was returned
243
+ - Errors are ignored
244
+ - If shutdown hook won't complete within 60 seconds then container will be killed
245
+ - As soon as user pressed stop, task is marked as inactive and 'webhooks gateway' will start responding with the error (Task either does not exist or is inactive) to possible data
246
+
247
+ TBD - log for shutdown hooks?