@autofleet/node-common 1.1.15 → 1.1.21

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.
@@ -0,0 +1,14 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "type": "node",
9
+ "request": "launch",
10
+ "name": "Launch Program",
11
+ "program": "${workspaceFolder}/events/index.js"
12
+ }
13
+ ]
14
+ }
@@ -0,0 +1,20 @@
1
+ const event = require('./index');
2
+
3
+ const vehicleEvent = {
4
+ event_timestamp: '2018-08-10 11:05:11',
5
+ vehicle_id: '1a',
6
+ fleet_id: '2b',
7
+ shift_id: '3c',
8
+ action: 'Changed State',
9
+ original_state: 'Activating',
10
+ new_state: 'Idle',
11
+ lat: 5.7,
12
+ lng: 8.9,
13
+ city_name: 'Tel Aviv',
14
+ region_name: 'Hamerkaz',
15
+ country_name: 'Israel',
16
+ duration: 1420,
17
+ additional_params: '{}',
18
+ };
19
+
20
+ event.publish('vehicle', vehicleEvent, true);
@@ -0,0 +1,37 @@
1
+ const PubSub = require('@google-cloud/pubsub');
2
+ const logger = require('../logger/index')();
3
+
4
+ // EventType - 'vehicle'/'stop_point' etc.
5
+ const publish = (eventType, eventObj, debug = false) => {
6
+ const envv = process.env.NODE_ENV || 'development';
7
+ const projectId = process.env.PROJECT;
8
+ const topic = process.env.TOPIC;
9
+
10
+ if (envv === 'development' && !debug) {
11
+ return 'not publishing in dev';
12
+ }
13
+
14
+ const pubsubClient = new PubSub({ projectId });
15
+
16
+ const msg = {
17
+ type: eventType,
18
+ event: eventObj,
19
+ env: envv,
20
+ };
21
+
22
+ const data = JSON.stringify(msg);
23
+ const dataBuffer = Buffer.from(data);
24
+
25
+ return pubsubClient
26
+ .topic(topic)
27
+ .publisher()
28
+ .publish(dataBuffer)
29
+ .then((messageId) => {
30
+ logger.info(`Message ${messageId} published.`);
31
+ })
32
+ .catch((err) => {
33
+ logger.error('Error:', err);
34
+ });
35
+ };
36
+
37
+ module.exports = { publish };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/node-common",
3
- "version": "1.1.15",
3
+ "version": "1.1.21",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "coverage": "jest --coverage --forceExit --runInBand",
@@ -22,10 +22,12 @@
22
22
  },
23
23
  "homepage": "https://gitlab.com/AutoFleet/node-common#README",
24
24
  "dependencies": {
25
+ "@google-cloud/pubsub": "^0.19.0",
25
26
  "axios": "^0.18.0",
26
27
  "express": "^4.16.2",
27
28
  "axios-retry": "^3.1.0",
28
29
  "dotenv": "^5.0.1",
30
+ "event-pubsub": "^4.3.0",
29
31
  "jest": "^22.4.3",
30
32
  "mock-socket": "^7.1.0",
31
33
  "node-cache": "^4.2.0",
package/settings/index.js CHANGED
@@ -46,7 +46,7 @@ module.exports = class SettingsManager {
46
46
  logger.error('Cant get setting from network', error);
47
47
  }
48
48
 
49
- const returnValue = networkValue || defaultValue;
49
+ const returnValue = typeof networkValue !== 'undefined' ? networkValue : defaultValue;
50
50
  this.settingsCache.set(cacheKey, returnValue, this.ttl);
51
51
  return returnValue;
52
52
  }