featureflow-node-sdk 0.6.15 → 0.6.17

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
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![][npm-img]][npm-url]
4
4
 
5
- [![Featureflow](https://circleci.com/gh/featureflow/featureflow-node-sdk.svg?style=svg)](https://circleci.com/gh/featureflow/featureflow-node-sdk)
5
+ [![CI](https://github.com/featureflow/featureflow-node-sdk/workflows/CI/badge.svg)](https://github.com/featureflow/featureflow-node-sdk/actions)
6
6
 
7
7
  [![][dependency-img]][dependency-url]
8
8
 
package/dist/Client.js CHANGED
@@ -123,6 +123,7 @@ var Featureflow = function (_EventEmitter) {
123
123
  }, {
124
124
  key: 'evaluateAll',
125
125
  value: function evaluateAll(user) {
126
+ this.pollingClient.maybeRefresh();
126
127
  var evaluatedFeatures = {};
127
128
  var features = this.config.featureStore.getAll();
128
129
  for (var p in features) {
@@ -151,6 +152,7 @@ var Featureflow = function (_EventEmitter) {
151
152
  }, {
152
153
  key: 'evaluate',
153
154
  value: function evaluate(key, user) {
155
+ this.pollingClient.maybeRefresh();
154
156
  var evaluatedVariant = void 0;
155
157
  var feature = this.config.featureStore.get(key);
156
158
 
@@ -29,7 +29,7 @@ var EventsClient = function () {
29
29
 
30
30
  this.SEND_INTERVAL = 60;
31
31
  this.QUEUE_SIZE = 10000;
32
- this.clientVersion = 'NodeJsClient/0.6.15';
32
+ this.clientVersion = 'NodeJsClient/0.6.16';
33
33
  this.queue = [];
34
34
  this.overLimit = false;
35
35
 
@@ -3,6 +3,8 @@ export default class PollingClient {
3
3
  DEFAULT_TIMEOUT: number;
4
4
  DEFAULT_INTERVAL: number;
5
5
  clientVersion: string;
6
+ lastRefreshTime: number;
7
+ refreshInProgress: boolean;
6
8
  url: any;
7
9
  apiKey: any;
8
10
  featureStore: any;
@@ -11,5 +13,6 @@ export default class PollingClient {
11
13
  etag: string;
12
14
  interval: number | undefined;
13
15
  getFeatures(callback?: () => void): void;
16
+ maybeRefresh(): void;
14
17
  close(): void;
15
18
  }
@@ -24,7 +24,9 @@ var PollingClient = function () {
24
24
 
25
25
  this.DEFAULT_TIMEOUT = 5 * 1000;
26
26
  this.DEFAULT_INTERVAL = 20 * 1000;
27
- this.clientVersion = 'NodeJsClient/0.6.15';
27
+ this.clientVersion = 'NodeJsClient/0.6.16';
28
+ this.lastRefreshTime = 0;
29
+ this.refreshInProgress = false;
28
30
 
29
31
  this.url = url;
30
32
  this.apiKey = config.apiKey;
@@ -54,6 +56,7 @@ var PollingClient = function () {
54
56
 
55
57
  var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
56
58
 
59
+ this.lastRefreshTime = Date.now();
57
60
  (0, _request2.default)({
58
61
  method: 'get',
59
62
  uri: this.url,
@@ -80,6 +83,23 @@ var PollingClient = function () {
80
83
  }
81
84
  });
82
85
  }
86
+ }, {
87
+ key: 'maybeRefresh',
88
+ value: function maybeRefresh() {
89
+ var _this2 = this;
90
+
91
+ var now = Date.now();
92
+ var elapsed = now - this.lastRefreshTime;
93
+
94
+ if (elapsed >= this.pollingInterval && !this.refreshInProgress) {
95
+ this.refreshInProgress = true;
96
+ this.lastRefreshTime = now;
97
+
98
+ this.getFeatures(function () {
99
+ _this2.refreshInProgress = false;
100
+ });
101
+ }
102
+ }
83
103
  }, {
84
104
  key: 'close',
85
105
  value: function close() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "featureflow-node-sdk",
3
- "version": "0.6.15",
3
+ "version": "0.6.17",
4
4
  "description": "Featureflow sdk for Node",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",