flagsmith-nodejs 2.1.1 → 2.2.1

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/build/index.d.ts CHANGED
@@ -1,4 +1,2 @@
1
- import Flagsmith from './sdk';
2
1
  export { AnalyticsProcessor, FlagsmithAPIError, FlagsmithClientError, EnvironmentDataPollingManager, FlagsmithCache, DefaultFlag, Flags } from './sdk';
3
2
  export { EnvironmentModel, IntegrationModel, FeatureStateModel, IdentityModel, TraitModel, SegmentModel, OrganisationModel } from './flagsmith-engine';
4
- export default Flagsmith;
package/build/index.js CHANGED
@@ -20,5 +20,4 @@ Object.defineProperty(exports, "IdentityModel", { enumerable: true, get: functio
20
20
  Object.defineProperty(exports, "TraitModel", { enumerable: true, get: function () { return flagsmith_engine_1.TraitModel; } });
21
21
  Object.defineProperty(exports, "SegmentModel", { enumerable: true, get: function () { return flagsmith_engine_1.SegmentModel; } });
22
22
  Object.defineProperty(exports, "OrganisationModel", { enumerable: true, get: function () { return flagsmith_engine_1.OrganisationModel; } });
23
- exports.default = sdk_1.default;
24
23
  module.exports = sdk_1.default;
@@ -5,20 +5,20 @@ export declare class AnalyticsProcessor {
5
5
  analyticsData: {
6
6
  [key: string]: any;
7
7
  };
8
- private timeout;
8
+ private requestTimeoutMs;
9
9
  /**
10
10
  * AnalyticsProcessor is used to track how often individual Flags are evaluated within
11
11
  * the Flagsmith SDK. Docs: https://docs.flagsmith.com/advanced-use/flag-analytics.
12
12
  *
13
13
  * @param data.environmentKey environment key obtained from the Flagsmith UI
14
14
  * @param data.baseApiUrl base api url to override when using self hosted version
15
- * @param data.timeout used to tell requests to stop waiting for a response after a
16
- given number of seconds
15
+ * @param data.requestTimeoutMs used to tell requests to stop waiting for a response after a
16
+ given number of milliseconds
17
17
  */
18
18
  constructor(data: {
19
19
  environmentKey: string;
20
20
  baseApiUrl: string;
21
- timeout?: number;
21
+ requestTimeoutMs?: number;
22
22
  });
23
23
  /**
24
24
  * Sends all the collected data to the api asynchronously and resets the timer
@@ -51,16 +51,16 @@ var AnalyticsProcessor = /** @class */ (function () {
51
51
  *
52
52
  * @param data.environmentKey environment key obtained from the Flagsmith UI
53
53
  * @param data.baseApiUrl base api url to override when using self hosted version
54
- * @param data.timeout used to tell requests to stop waiting for a response after a
55
- given number of seconds
54
+ * @param data.requestTimeoutMs used to tell requests to stop waiting for a response after a
55
+ given number of milliseconds
56
56
  */
57
57
  function AnalyticsProcessor(data) {
58
- this.timeout = 3;
58
+ this.requestTimeoutMs = 3000;
59
59
  this.analyticsEndpoint = data.baseApiUrl + ANALYTICS_ENDPOINT;
60
60
  this.environmentKey = data.environmentKey;
61
61
  this.lastFlushed = Date.now();
62
62
  this.analyticsData = {};
63
- this.timeout = data.timeout || this.timeout;
63
+ this.requestTimeoutMs = data.requestTimeoutMs || this.requestTimeoutMs;
64
64
  }
65
65
  /**
66
66
  * Sends all the collected data to the api asynchronously and resets the timer
@@ -76,7 +76,7 @@ var AnalyticsProcessor = /** @class */ (function () {
76
76
  return [4 /*yield*/, (0, node_fetch_1.default)(this.analyticsEndpoint, {
77
77
  method: 'POST',
78
78
  body: JSON.stringify(this.analyticsData),
79
- timeout: this.timeout,
79
+ timeout: this.requestTimeoutMs,
80
80
  headers: {
81
81
  'Content-Type': 'application/json',
82
82
  'X-Environment-Key': this.environmentKey
@@ -15,6 +15,7 @@ export declare class Flagsmith {
15
15
  [key: string]: any;
16
16
  };
17
17
  requestTimeoutSeconds?: number;
18
+ requestTimeoutMs?: number;
18
19
  enableLocalEvaluation?: boolean;
19
20
  environmentRefreshIntervalSeconds: number;
20
21
  retries?: number;
@@ -113,6 +114,7 @@ export declare class Flagsmith {
113
114
  * You only need to call this if you wish to bypass environmentRefreshIntervalSeconds.
114
115
  */
115
116
  updateEnvironment(): Promise<void>;
117
+ close(): Promise<void>;
116
118
  private getJSONResponse;
117
119
  /**
118
120
  * This promise ensures that the environment is retrieved before attempting to locally evaluate.
@@ -125,6 +125,7 @@ var Flagsmith = /** @class */ (function () {
125
125
  this.apiUrl = data.apiUrl || this.apiUrl;
126
126
  this.customHeaders = data.customHeaders;
127
127
  this.requestTimeoutSeconds = data.requestTimeoutSeconds;
128
+ this.requestTimeoutMs = data.requestTimeoutSeconds ? data.requestTimeoutSeconds * 1000 : undefined;
128
129
  this.enableLocalEvaluation = data.enableLocalEvaluation;
129
130
  this.environmentRefreshIntervalSeconds =
130
131
  data.environmentRefreshIntervalSeconds || this.environmentRefreshIntervalSeconds;
@@ -154,7 +155,7 @@ var Flagsmith = /** @class */ (function () {
154
155
  ? new analytics_1.AnalyticsProcessor({
155
156
  environmentKey: this.environmentKey,
156
157
  baseApiUrl: this.apiUrl,
157
- timeout: this.requestTimeoutSeconds
158
+ requestTimeoutMs: this.requestTimeoutMs
158
159
  })
159
160
  : undefined;
160
161
  }
@@ -182,10 +183,10 @@ var Flagsmith = /** @class */ (function () {
182
183
  return [2 /*return*/, cachedItem];
183
184
  }
184
185
  if (this.enableLocalEvaluation) {
185
- return [2 /*return*/, new Promise(function (resolve) {
186
+ return [2 /*return*/, new Promise(function (resolve, reject) {
186
187
  return _this.environmentPromise.then(function () {
187
188
  resolve(_this.getEnvironmentFlagsFromDocument());
188
- });
189
+ }).catch(function (e) { return reject(e); });
189
190
  })];
190
191
  }
191
192
  if (this.environment) {
@@ -227,10 +228,10 @@ var Flagsmith = /** @class */ (function () {
227
228
  }
228
229
  traits = traits || {};
229
230
  if (this.enableLocalEvaluation) {
230
- return [2 /*return*/, new Promise(function (resolve) {
231
+ return [2 /*return*/, new Promise(function (resolve, reject) {
231
232
  return _this.environmentPromise.then(function () {
232
233
  resolve(_this.getIdentityFlagsFromDocument(identifier, traits || {}));
233
- });
234
+ }).catch(function (e) { return reject(e); });
234
235
  })];
235
236
  }
236
237
  return [2 /*return*/, this.getIdentityFlagsFromApi(identifier, traits)];
@@ -253,15 +254,15 @@ var Flagsmith = /** @class */ (function () {
253
254
  var _this = this;
254
255
  traits = traits || {};
255
256
  if (this.enableLocalEvaluation) {
256
- return this.environmentPromise.then(function () {
257
- return new Promise(function (resolve) {
257
+ return new Promise(function (resolve, reject) {
258
+ return _this.environmentPromise.then(function () {
258
259
  var identityModel = _this.buildIdentityModel(identifier, Object.keys(traits || {}).map(function (key) { return ({
259
260
  key: key,
260
261
  value: traits === null || traits === void 0 ? void 0 : traits[key]
261
262
  }); }));
262
263
  var segments = (0, evaluators_1.getIdentitySegments)(_this.environment, identityModel);
263
264
  return resolve(segments);
264
- });
265
+ }).catch(function (e) { return reject(e); });
265
266
  });
266
267
  }
267
268
  console.error('This function is only permitted with local evaluation.');
@@ -311,6 +312,15 @@ var Flagsmith = /** @class */ (function () {
311
312
  });
312
313
  });
313
314
  };
315
+ Flagsmith.prototype.close = function () {
316
+ var _a;
317
+ return __awaiter(this, void 0, void 0, function () {
318
+ return __generator(this, function (_b) {
319
+ (_a = this.environmentDataPollingManager) === null || _a === void 0 ? void 0 : _a.stop();
320
+ return [2 /*return*/];
321
+ });
322
+ });
323
+ };
314
324
  Flagsmith.prototype.getJSONResponse = function (url, method, body) {
315
325
  return __awaiter(this, void 0, void 0, function () {
316
326
  var headers, _a, _b, _c, k, v, data;
@@ -339,10 +349,10 @@ var Flagsmith = /** @class */ (function () {
339
349
  }
340
350
  return [4 /*yield*/, (0, utils_1.retryFetch)(url, {
341
351
  method: method,
342
- timeout: this.requestTimeoutSeconds || undefined,
352
+ timeout: this.requestTimeoutMs || undefined,
343
353
  body: JSON.stringify(body),
344
354
  headers: headers
345
- }, this.retries, (this.requestTimeoutSeconds || 10) * 1000)];
355
+ }, this.retries)];
346
356
  case 1:
347
357
  data = _e.sent();
348
358
  if (data.status !== 200) {
@@ -9,4 +9,4 @@ export declare function generateIdentitiesData(identifier: string, traits: {
9
9
  }[];
10
10
  };
11
11
  export declare const delay: (ms: number) => Promise<unknown>;
12
- export declare const retryFetch: (url: string, fetchOptions: any, retries: number | undefined, timeout: number) => Promise<Response>;
12
+ export declare const retryFetch: (url: string, fetchOptions: any, retries?: number, timeout?: number | undefined) => Promise<Response>;
@@ -59,7 +59,8 @@ var delay = function (ms) {
59
59
  return new Promise(function (resolve) { return setTimeout(function () { return resolve(undefined); }, ms); });
60
60
  };
61
61
  exports.delay = delay;
62
- var retryFetch = function (url, fetchOptions, retries, timeout) {
62
+ var retryFetch = function (url, fetchOptions, retries, timeout // set an overall timeout for this function
63
+ ) {
63
64
  if (retries === void 0) { retries = 3; }
64
65
  return new Promise(function (resolve, reject) {
65
66
  // check for timeout
@@ -9,7 +9,6 @@
9
9
  "version": "1.0.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
- "flagsmith-nodejs": "^2.1.0",
13
12
  "node-cache": "^5.1.2"
14
13
  },
15
14
  "devDependencies": {
@@ -1291,14 +1290,6 @@
1291
1290
  "node": ">=0.10.0"
1292
1291
  }
1293
1292
  },
1294
- "node_modules/big-integer": {
1295
- "version": "1.6.51",
1296
- "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.51.tgz",
1297
- "integrity": "sha512-GPEid2Y9QU1Exl1rpO9B2IPJGHPSupF5GnVIP0blYvNOMer2bTvSWs1jGOUg04hTmu67nmLsQ9TBo1puaotBHg==",
1298
- "engines": {
1299
- "node": ">=0.6"
1300
- }
1301
- },
1302
1293
  "node_modules/binary-extensions": {
1303
1294
  "version": "1.13.1",
1304
1295
  "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-1.13.1.tgz",
@@ -1480,14 +1471,6 @@
1480
1471
  "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==",
1481
1472
  "dev": true
1482
1473
  },
1483
- "node_modules/charenc": {
1484
- "version": "0.0.2",
1485
- "resolved": "https://registry.npmjs.org/charenc/-/charenc-0.0.2.tgz",
1486
- "integrity": "sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA==",
1487
- "engines": {
1488
- "node": "*"
1489
- }
1490
- },
1491
1474
  "node_modules/chokidar": {
1492
1475
  "version": "2.1.8",
1493
1476
  "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-2.1.8.tgz",
@@ -1732,14 +1715,6 @@
1732
1715
  "node": ">=4.8"
1733
1716
  }
1734
1717
  },
1735
- "node_modules/crypt": {
1736
- "version": "0.0.2",
1737
- "resolved": "https://registry.npmjs.org/crypt/-/crypt-0.0.2.tgz",
1738
- "integrity": "sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow==",
1739
- "engines": {
1740
- "node": "*"
1741
- }
1742
- },
1743
1718
  "node_modules/debug": {
1744
1719
  "version": "2.6.9",
1745
1720
  "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
@@ -2473,32 +2448,6 @@
2473
2448
  "node": ">= 0.8"
2474
2449
  }
2475
2450
  },
2476
- "node_modules/flagsmith-nodejs": {
2477
- "version": "2.1.0",
2478
- "resolved": "https://registry.npmjs.org/flagsmith-nodejs/-/flagsmith-nodejs-2.1.0.tgz",
2479
- "integrity": "sha512-LZV3JiU+GPVPD0a8wPnEiVAvUtQklv1ESrrkGcfV+Zo5YE96c0wUlCJlBgpXs/eztFv7RVhms+gv7X0Nx4JqEQ==",
2480
- "dependencies": {
2481
- "big-integer": "^1.6.51",
2482
- "md5": "^2.3.0",
2483
- "node-fetch": "^2.1.2",
2484
- "semver": "^7.3.7",
2485
- "uuid": "^8.3.2"
2486
- }
2487
- },
2488
- "node_modules/flagsmith-nodejs/node_modules/semver": {
2489
- "version": "7.3.7",
2490
- "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz",
2491
- "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==",
2492
- "dependencies": {
2493
- "lru-cache": "^6.0.0"
2494
- },
2495
- "bin": {
2496
- "semver": "bin/semver.js"
2497
- },
2498
- "engines": {
2499
- "node": ">=10"
2500
- }
2501
- },
2502
2451
  "node_modules/flat-cache": {
2503
2452
  "version": "2.0.1",
2504
2453
  "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-2.0.1.tgz",
@@ -3624,7 +3573,9 @@
3624
3573
  "node_modules/is-buffer": {
3625
3574
  "version": "1.1.6",
3626
3575
  "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
3627
- "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w=="
3576
+ "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==",
3577
+ "dev": true,
3578
+ "optional": true
3628
3579
  },
3629
3580
  "node_modules/is-data-descriptor": {
3630
3581
  "version": "0.1.4",
@@ -3918,17 +3869,6 @@
3918
3869
  "loose-envify": "cli.js"
3919
3870
  }
3920
3871
  },
3921
- "node_modules/lru-cache": {
3922
- "version": "6.0.0",
3923
- "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
3924
- "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
3925
- "dependencies": {
3926
- "yallist": "^4.0.0"
3927
- },
3928
- "engines": {
3929
- "node": ">=10"
3930
- }
3931
- },
3932
3872
  "node_modules/map-cache": {
3933
3873
  "version": "0.2.2",
3934
3874
  "resolved": "https://registry.npmjs.org/map-cache/-/map-cache-0.2.2.tgz",
@@ -3952,16 +3892,6 @@
3952
3892
  "node": ">=0.10.0"
3953
3893
  }
3954
3894
  },
3955
- "node_modules/md5": {
3956
- "version": "2.3.0",
3957
- "resolved": "https://registry.npmjs.org/md5/-/md5-2.3.0.tgz",
3958
- "integrity": "sha512-T1GITYmFaKuO91vxyoQMFETst+O71VUPEU3ze5GNzDm0OWdP8v1ziTaAEPUr/3kLsY3Sftgz242A1SetQiDL7g==",
3959
- "dependencies": {
3960
- "charenc": "0.0.2",
3961
- "crypt": "0.0.2",
3962
- "is-buffer": "~1.1.6"
3963
- }
3964
- },
3965
3895
  "node_modules/media-typer": {
3966
3896
  "version": "0.3.0",
3967
3897
  "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
@@ -4184,25 +4114,6 @@
4184
4114
  "node": ">= 8.0.0"
4185
4115
  }
4186
4116
  },
4187
- "node_modules/node-fetch": {
4188
- "version": "2.6.7",
4189
- "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
4190
- "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==",
4191
- "dependencies": {
4192
- "whatwg-url": "^5.0.0"
4193
- },
4194
- "engines": {
4195
- "node": "4.x || >=6.0.0"
4196
- },
4197
- "peerDependencies": {
4198
- "encoding": "^0.1.0"
4199
- },
4200
- "peerDependenciesMeta": {
4201
- "encoding": {
4202
- "optional": true
4203
- }
4204
- }
4205
- },
4206
4117
  "node_modules/node-releases": {
4207
4118
  "version": "1.1.28",
4208
4119
  "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.28.tgz",
@@ -5695,11 +5606,6 @@
5695
5606
  "nodetouch": "bin/nodetouch.js"
5696
5607
  }
5697
5608
  },
5698
- "node_modules/tr46": {
5699
- "version": "0.0.3",
5700
- "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
5701
- "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="
5702
- },
5703
5609
  "node_modules/trim-right": {
5704
5610
  "version": "1.0.1",
5705
5611
  "resolved": "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz",
@@ -5917,14 +5823,6 @@
5917
5823
  "node": ">= 0.4.0"
5918
5824
  }
5919
5825
  },
5920
- "node_modules/uuid": {
5921
- "version": "8.3.2",
5922
- "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
5923
- "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
5924
- "bin": {
5925
- "uuid": "dist/bin/uuid"
5926
- }
5927
- },
5928
5826
  "node_modules/v8-compile-cache": {
5929
5827
  "version": "2.1.0",
5930
5828
  "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.1.0.tgz",
@@ -5940,20 +5838,6 @@
5940
5838
  "node": ">= 0.8"
5941
5839
  }
5942
5840
  },
5943
- "node_modules/webidl-conversions": {
5944
- "version": "3.0.1",
5945
- "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
5946
- "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
5947
- },
5948
- "node_modules/whatwg-url": {
5949
- "version": "5.0.0",
5950
- "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
5951
- "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
5952
- "dependencies": {
5953
- "tr46": "~0.0.3",
5954
- "webidl-conversions": "^3.0.0"
5955
- }
5956
- },
5957
5841
  "node_modules/which": {
5958
5842
  "version": "1.3.1",
5959
5843
  "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz",
@@ -5989,11 +5873,6 @@
5989
5873
  "engines": {
5990
5874
  "node": ">=4"
5991
5875
  }
5992
- },
5993
- "node_modules/yallist": {
5994
- "version": "4.0.0",
5995
- "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
5996
- "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
5997
5876
  }
5998
5877
  },
5999
5878
  "dependencies": {
@@ -7055,11 +6934,6 @@
7055
6934
  }
7056
6935
  }
7057
6936
  },
7058
- "big-integer": {
7059
- "version": "1.6.51",
7060
- "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.51.tgz",
7061
- "integrity": "sha512-GPEid2Y9QU1Exl1rpO9B2IPJGHPSupF5GnVIP0blYvNOMer2bTvSWs1jGOUg04hTmu67nmLsQ9TBo1puaotBHg=="
7062
- },
7063
6937
  "binary-extensions": {
7064
6938
  "version": "1.13.1",
7065
6939
  "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-1.13.1.tgz",
@@ -7212,11 +7086,6 @@
7212
7086
  "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==",
7213
7087
  "dev": true
7214
7088
  },
7215
- "charenc": {
7216
- "version": "0.0.2",
7217
- "resolved": "https://registry.npmjs.org/charenc/-/charenc-0.0.2.tgz",
7218
- "integrity": "sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA=="
7219
- },
7220
7089
  "chokidar": {
7221
7090
  "version": "2.1.8",
7222
7091
  "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-2.1.8.tgz",
@@ -7417,11 +7286,6 @@
7417
7286
  "which": "^1.2.9"
7418
7287
  }
7419
7288
  },
7420
- "crypt": {
7421
- "version": "0.0.2",
7422
- "resolved": "https://registry.npmjs.org/crypt/-/crypt-0.0.2.tgz",
7423
- "integrity": "sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow=="
7424
- },
7425
7289
  "debug": {
7426
7290
  "version": "2.6.9",
7427
7291
  "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
@@ -8007,28 +7871,6 @@
8007
7871
  "unpipe": "~1.0.0"
8008
7872
  }
8009
7873
  },
8010
- "flagsmith-nodejs": {
8011
- "version": "2.1.0",
8012
- "resolved": "https://registry.npmjs.org/flagsmith-nodejs/-/flagsmith-nodejs-2.1.0.tgz",
8013
- "integrity": "sha512-LZV3JiU+GPVPD0a8wPnEiVAvUtQklv1ESrrkGcfV+Zo5YE96c0wUlCJlBgpXs/eztFv7RVhms+gv7X0Nx4JqEQ==",
8014
- "requires": {
8015
- "big-integer": "^1.6.51",
8016
- "md5": "^2.3.0",
8017
- "node-fetch": "^2.1.2",
8018
- "semver": "^7.3.7",
8019
- "uuid": "^8.3.2"
8020
- },
8021
- "dependencies": {
8022
- "semver": {
8023
- "version": "7.3.7",
8024
- "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz",
8025
- "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==",
8026
- "requires": {
8027
- "lru-cache": "^6.0.0"
8028
- }
8029
- }
8030
- }
8031
- },
8032
7874
  "flat-cache": {
8033
7875
  "version": "2.0.1",
8034
7876
  "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-2.0.1.tgz",
@@ -8916,7 +8758,9 @@
8916
8758
  "is-buffer": {
8917
8759
  "version": "1.1.6",
8918
8760
  "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
8919
- "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w=="
8761
+ "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==",
8762
+ "dev": true,
8763
+ "optional": true
8920
8764
  },
8921
8765
  "is-data-descriptor": {
8922
8766
  "version": "0.1.4",
@@ -9149,14 +8993,6 @@
9149
8993
  "js-tokens": "^3.0.0 || ^4.0.0"
9150
8994
  }
9151
8995
  },
9152
- "lru-cache": {
9153
- "version": "6.0.0",
9154
- "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
9155
- "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
9156
- "requires": {
9157
- "yallist": "^4.0.0"
9158
- }
9159
- },
9160
8996
  "map-cache": {
9161
8997
  "version": "0.2.2",
9162
8998
  "resolved": "https://registry.npmjs.org/map-cache/-/map-cache-0.2.2.tgz",
@@ -9174,16 +9010,6 @@
9174
9010
  "object-visit": "^1.0.0"
9175
9011
  }
9176
9012
  },
9177
- "md5": {
9178
- "version": "2.3.0",
9179
- "resolved": "https://registry.npmjs.org/md5/-/md5-2.3.0.tgz",
9180
- "integrity": "sha512-T1GITYmFaKuO91vxyoQMFETst+O71VUPEU3ze5GNzDm0OWdP8v1ziTaAEPUr/3kLsY3Sftgz242A1SetQiDL7g==",
9181
- "requires": {
9182
- "charenc": "0.0.2",
9183
- "crypt": "0.0.2",
9184
- "is-buffer": "~1.1.6"
9185
- }
9186
- },
9187
9013
  "media-typer": {
9188
9014
  "version": "0.3.0",
9189
9015
  "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
@@ -9363,14 +9189,6 @@
9363
9189
  "clone": "2.x"
9364
9190
  }
9365
9191
  },
9366
- "node-fetch": {
9367
- "version": "2.6.7",
9368
- "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
9369
- "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==",
9370
- "requires": {
9371
- "whatwg-url": "^5.0.0"
9372
- }
9373
- },
9374
9192
  "node-releases": {
9375
9193
  "version": "1.1.28",
9376
9194
  "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.28.tgz",
@@ -10550,11 +10368,6 @@
10550
10368
  "nopt": "~1.0.10"
10551
10369
  }
10552
10370
  },
10553
- "tr46": {
10554
- "version": "0.0.3",
10555
- "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
10556
- "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="
10557
- },
10558
10371
  "trim-right": {
10559
10372
  "version": "1.0.1",
10560
10373
  "resolved": "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz",
@@ -10726,11 +10539,6 @@
10726
10539
  "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==",
10727
10540
  "dev": true
10728
10541
  },
10729
- "uuid": {
10730
- "version": "8.3.2",
10731
- "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
10732
- "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
10733
- },
10734
10542
  "v8-compile-cache": {
10735
10543
  "version": "2.1.0",
10736
10544
  "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.1.0.tgz",
@@ -10743,20 +10551,6 @@
10743
10551
  "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==",
10744
10552
  "dev": true
10745
10553
  },
10746
- "webidl-conversions": {
10747
- "version": "3.0.1",
10748
- "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
10749
- "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
10750
- },
10751
- "whatwg-url": {
10752
- "version": "5.0.0",
10753
- "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
10754
- "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
10755
- "requires": {
10756
- "tr46": "~0.0.3",
10757
- "webidl-conversions": "^3.0.0"
10758
- }
10759
- },
10760
10554
  "which": {
10761
10555
  "version": "1.3.1",
10762
10556
  "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz",
@@ -10786,11 +10580,6 @@
10786
10580
  "requires": {
10787
10581
  "mkdirp": "^0.5.1"
10788
10582
  }
10789
- },
10790
- "yallist": {
10791
- "version": "4.0.0",
10792
- "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
10793
- "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
10794
10583
  }
10795
10584
  }
10796
10585
  }
@@ -50,7 +50,6 @@
50
50
  "prettier": "^1.18.2"
51
51
  },
52
52
  "dependencies": {
53
- "flagsmith-nodejs": "^2.1.0",
54
53
  "node-cache": "^5.1.2"
55
54
  }
56
55
  }
@@ -1,5 +1,5 @@
1
1
  import {Router} from 'express'
2
- import Flagsmith, {Flags} from '../../../build'
2
+ import Flagsmith from '../../../build'
3
3
 
4
4
  const environmentKey = '';
5
5
  import nodecache from "node-cache";
package/index.ts CHANGED
@@ -19,5 +19,5 @@ export {
19
19
  SegmentModel,
20
20
  OrganisationModel
21
21
  } from './flagsmith-engine';
22
- export default Flagsmith
22
+
23
23
  module.exports = Flagsmith;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flagsmith-nodejs",
3
- "version": "2.1.1",
3
+ "version": "2.2.1",
4
4
  "description": "Flagsmith lets you manage features flags and remote config across web, mobile and server side applications. Deliver true Continuous Integration. Get builds out faster. Control who has access to new features.",
5
5
  "main": "build/index.js",
6
6
  "repository": {
package/sdk/analytics.ts CHANGED
@@ -10,22 +10,22 @@ export class AnalyticsProcessor {
10
10
  private environmentKey: string;
11
11
  private lastFlushed: number;
12
12
  analyticsData: { [key: string]: any };
13
- private timeout: number = 3;
13
+ private requestTimeoutMs: number = 3000;
14
14
  /**
15
15
  * AnalyticsProcessor is used to track how often individual Flags are evaluated within
16
16
  * the Flagsmith SDK. Docs: https://docs.flagsmith.com/advanced-use/flag-analytics.
17
17
  *
18
18
  * @param data.environmentKey environment key obtained from the Flagsmith UI
19
19
  * @param data.baseApiUrl base api url to override when using self hosted version
20
- * @param data.timeout used to tell requests to stop waiting for a response after a
21
- given number of seconds
20
+ * @param data.requestTimeoutMs used to tell requests to stop waiting for a response after a
21
+ given number of milliseconds
22
22
  */
23
- constructor(data: { environmentKey: string; baseApiUrl: string; timeout?: number }) {
23
+ constructor(data: { environmentKey: string; baseApiUrl: string; requestTimeoutMs?: number }) {
24
24
  this.analyticsEndpoint = data.baseApiUrl + ANALYTICS_ENDPOINT;
25
25
  this.environmentKey = data.environmentKey;
26
26
  this.lastFlushed = Date.now();
27
27
  this.analyticsData = {};
28
- this.timeout = data.timeout || this.timeout;
28
+ this.requestTimeoutMs = data.requestTimeoutMs || this.requestTimeoutMs;
29
29
  }
30
30
  /**
31
31
  * Sends all the collected data to the api asynchronously and resets the timer
@@ -38,7 +38,7 @@ export class AnalyticsProcessor {
38
38
  await fetch(this.analyticsEndpoint, {
39
39
  method: 'POST',
40
40
  body: JSON.stringify(this.analyticsData),
41
- timeout: this.timeout,
41
+ timeout: this.requestTimeoutMs,
42
42
  headers: {
43
43
  'Content-Type': 'application/json',
44
44
  'X-Environment-Key': this.environmentKey
package/sdk/index.ts CHANGED
@@ -28,6 +28,7 @@ export class Flagsmith {
28
28
  apiUrl: string = DEFAULT_API_URL;
29
29
  customHeaders?: { [key: string]: any };
30
30
  requestTimeoutSeconds?: number;
31
+ requestTimeoutMs?: number;
31
32
  enableLocalEvaluation?: boolean = false;
32
33
  environmentRefreshIntervalSeconds: number = 60;
33
34
  retries?: number;
@@ -92,6 +93,7 @@ export class Flagsmith {
92
93
  this.apiUrl = data.apiUrl || this.apiUrl;
93
94
  this.customHeaders = data.customHeaders;
94
95
  this.requestTimeoutSeconds = data.requestTimeoutSeconds;
96
+ this.requestTimeoutMs = data.requestTimeoutSeconds ? data.requestTimeoutSeconds * 1000 : undefined;
95
97
  this.enableLocalEvaluation = data.enableLocalEvaluation;
96
98
  this.environmentRefreshIntervalSeconds =
97
99
  data.environmentRefreshIntervalSeconds || this.environmentRefreshIntervalSeconds;
@@ -135,7 +137,7 @@ export class Flagsmith {
135
137
  ? new AnalyticsProcessor({
136
138
  environmentKey: this.environmentKey,
137
139
  baseApiUrl: this.apiUrl,
138
- timeout: this.requestTimeoutSeconds
140
+ requestTimeoutMs: this.requestTimeoutMs
139
141
  })
140
142
  : undefined;
141
143
  }
@@ -150,10 +152,10 @@ export class Flagsmith {
150
152
  return cachedItem;
151
153
  }
152
154
  if (this.enableLocalEvaluation) {
153
- return new Promise(resolve =>
155
+ return new Promise((resolve, reject) =>
154
156
  this.environmentPromise!.then(() => {
155
157
  resolve(this.getEnvironmentFlagsFromDocument());
156
- })
158
+ }).catch((e) => reject(e))
157
159
  );
158
160
  }
159
161
  if (this.environment) {
@@ -180,10 +182,10 @@ export class Flagsmith {
180
182
  }
181
183
  traits = traits || {};
182
184
  if (this.enableLocalEvaluation) {
183
- return new Promise(resolve =>
185
+ return new Promise((resolve, reject) =>
184
186
  this.environmentPromise!.then(() => {
185
187
  resolve(this.getIdentityFlagsFromDocument(identifier, traits || {}));
186
- })
188
+ }).catch(e => reject(e))
187
189
  );
188
190
  }
189
191
  return this.getIdentityFlagsFromApi(identifier, traits);
@@ -206,8 +208,8 @@ export class Flagsmith {
206
208
  ): Promise<SegmentModel[]> {
207
209
  traits = traits || {};
208
210
  if (this.enableLocalEvaluation) {
209
- return this.environmentPromise!.then(() => {
210
- return new Promise(resolve => {
211
+ return new Promise((resolve, reject) => {
212
+ return this.environmentPromise!.then(() => {
211
213
  const identityModel = this.buildIdentityModel(
212
214
  identifier,
213
215
  Object.keys(traits || {}).map(key => ({
@@ -218,7 +220,7 @@ export class Flagsmith {
218
220
 
219
221
  const segments = getIdentitySegments(this.environment, identityModel);
220
222
  return resolve(segments);
221
- });
223
+ }).catch((e) => reject(e));
222
224
  });
223
225
  }
224
226
  console.error('This function is only permitted with local evaluation.');
@@ -251,6 +253,10 @@ export class Flagsmith {
251
253
  }
252
254
  }
253
255
 
256
+ async close() {
257
+ this.environmentDataPollingManager?.stop();
258
+ }
259
+
254
260
  private async getJSONResponse(
255
261
  url: string,
256
262
  method: string,
@@ -271,12 +277,11 @@ export class Flagsmith {
271
277
  url,
272
278
  {
273
279
  method: method,
274
- timeout: this.requestTimeoutSeconds || undefined,
280
+ timeout: this.requestTimeoutMs || undefined,
275
281
  body: JSON.stringify(body),
276
282
  headers: headers
277
283
  },
278
- this.retries,
279
- (this.requestTimeoutSeconds || 10) * 1000
284
+ this.retries
280
285
  );
281
286
 
282
287
  if (data.status !== 200) {
package/sdk/utils.ts CHANGED
@@ -20,7 +20,7 @@ export const retryFetch = (
20
20
  url: string,
21
21
  fetchOptions: any,
22
22
  retries = 3,
23
- timeout: number
23
+ timeout?: number // set an overall timeout for this function
24
24
  ): Promise<Response> => {
25
25
  return new Promise((resolve, reject) => {
26
26
  // check for timeout
@@ -32,7 +32,7 @@ test('test_analytics_processor_flush_post_request_data_match_ananlytics_data', a
32
32
  body: '{"myFeature1":1,"myFeature2":1}',
33
33
  headers: { 'Content-Type': 'application/json', 'X-Environment-Key': 'test-key' },
34
34
  method: 'POST',
35
- timeout: 3
35
+ timeout: 3000
36
36
  });
37
37
  });
38
38