@autofleet/node-common 1.1.5 → 1.1.8

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
@@ -7,10 +7,21 @@ Make sure you have:
7
7
  * Tests
8
8
  * Docs
9
9
 
10
+ ## Consts
11
+
12
+ Currently we suppurt:
13
+ ```
14
+ {
15
+ 'OK'
16
+ 'ERROR'
17
+ 'FAIL'
18
+ }
19
+ ```
20
+
10
21
  ## Network
11
22
  Server 2 Servers communication.
12
23
 
13
- Implement:
24
+ Implemented:
14
25
  * Retriving service urls from environment
15
26
  * Retry - Using https://github.com/softonic/axios-retry
16
27
  * Caching - TBD
@@ -36,7 +47,16 @@ RIDE_SERVICE_HOST=jsonplaceholder.typicode.com
36
47
 
37
48
  To learn more [click here](https://blog.risingstack.com/designing-microservices-architecture-for-failure/).
38
49
 
50
+ ## Settings
51
+
52
+ See example.
53
+
54
+ ## DeLorean
55
+
56
+ Use this model to mock time on server - more info TBD.
57
+
39
58
  ## Publish package
59
+
40
60
  bump the version number in package.json
41
61
  and run
42
62
  ```
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ ok: 'OK',
3
+ error: 'ERROR',
4
+ fail: 'FAIL',
5
+ };
package/network/index.js CHANGED
@@ -25,7 +25,7 @@ const HTTPMethods = [
25
25
  const defaultSettings = {
26
26
  timeout: 2500,
27
27
  headers: { 'X-AF-AUTH': 'ANYONE' },
28
- paramsSerializer: params => qs.stringify(params),
28
+ paramsSerializer: params => qs.stringify(params, { arrayFormat: 'brackets' }),
29
29
  };
30
30
 
31
31
  module.exports = class Network {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/node-common",
3
- "version": "1.1.5",
3
+ "version": "1.1.8",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "coverage": "jest --coverage --forceExit --runInBand",
@@ -26,9 +26,13 @@
26
26
  "axios-retry": "^3.1.0",
27
27
  "dotenv": "^5.0.1",
28
28
  "jest": "^22.4.3",
29
+ "mock-socket": "^7.1.0",
29
30
  "node-cache": "^4.2.0",
31
+ "portfinder": "^1.0.13",
30
32
  "qs": "^6.5.2",
31
- "winston": "^3.0.0-rc4"
33
+ "winston": "^3.0.0-rc4",
34
+ "ws": "^5.2.0",
35
+ "timekeeper": "^2.1.2"
32
36
  },
33
37
  "devDependencies": {
34
38
  "eslint": "^4.19.1",
package/settings/index.js CHANGED
@@ -7,9 +7,13 @@ require('dotenv').config();
7
7
 
8
8
  const fiveMinutes = 60 * 5;
9
9
 
10
+ const findUrl = serviceUrl => serviceUrl ||
11
+ process.env.SETTING_MS_SERVICE_HOST ||
12
+ (process.env.NODE_ENV !== 'test' ? 'http://setting-ms.autofleet.io/' : 'http://localhost:9999/');
13
+
10
14
  module.exports = class SettingsManager {
11
15
  constructor({ serviceUrl, ttl = fiveMinutes } = {}) {
12
- const localServiceUrl = serviceUrl || process.env.SETTING_MS_SERVICE_HOST;
16
+ const localServiceUrl = findUrl(serviceUrl);
13
17
 
14
18
  this.ttl = ttl;
15
19
  this.settingsCache = new NodeCache();
@@ -4,7 +4,7 @@ const Settings = require('./index');
4
4
  const serviceUrl = 'http://localhost:8085';
5
5
 
6
6
  const mockSetting = (key, value, labels, response = 200) => nock(serviceUrl)
7
- .get(`/api/v1/setting/get-setting/${key}`)
7
+ .get(`/api/v1/settings/get-setting/${key}`)
8
8
  .query(labels ? { labels } : undefined)
9
9
  .reply(response, { value });
10
10