flagsmith-nodejs 2.2.0 → 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.
@@ -114,6 +114,7 @@ export declare class Flagsmith {
114
114
  * You only need to call this if you wish to bypass environmentRefreshIntervalSeconds.
115
115
  */
116
116
  updateEnvironment(): Promise<void>;
117
+ close(): Promise<void>;
117
118
  private getJSONResponse;
118
119
  /**
119
120
  * This promise ensures that the environment is retrieved before attempting to locally evaluate.
@@ -183,10 +183,10 @@ var Flagsmith = /** @class */ (function () {
183
183
  return [2 /*return*/, cachedItem];
184
184
  }
185
185
  if (this.enableLocalEvaluation) {
186
- return [2 /*return*/, new Promise(function (resolve) {
186
+ return [2 /*return*/, new Promise(function (resolve, reject) {
187
187
  return _this.environmentPromise.then(function () {
188
188
  resolve(_this.getEnvironmentFlagsFromDocument());
189
- });
189
+ }).catch(function (e) { return reject(e); });
190
190
  })];
191
191
  }
192
192
  if (this.environment) {
@@ -228,10 +228,10 @@ var Flagsmith = /** @class */ (function () {
228
228
  }
229
229
  traits = traits || {};
230
230
  if (this.enableLocalEvaluation) {
231
- return [2 /*return*/, new Promise(function (resolve) {
231
+ return [2 /*return*/, new Promise(function (resolve, reject) {
232
232
  return _this.environmentPromise.then(function () {
233
233
  resolve(_this.getIdentityFlagsFromDocument(identifier, traits || {}));
234
- });
234
+ }).catch(function (e) { return reject(e); });
235
235
  })];
236
236
  }
237
237
  return [2 /*return*/, this.getIdentityFlagsFromApi(identifier, traits)];
@@ -254,15 +254,15 @@ var Flagsmith = /** @class */ (function () {
254
254
  var _this = this;
255
255
  traits = traits || {};
256
256
  if (this.enableLocalEvaluation) {
257
- return this.environmentPromise.then(function () {
258
- return new Promise(function (resolve) {
257
+ return new Promise(function (resolve, reject) {
258
+ return _this.environmentPromise.then(function () {
259
259
  var identityModel = _this.buildIdentityModel(identifier, Object.keys(traits || {}).map(function (key) { return ({
260
260
  key: key,
261
261
  value: traits === null || traits === void 0 ? void 0 : traits[key]
262
262
  }); }));
263
263
  var segments = (0, evaluators_1.getIdentitySegments)(_this.environment, identityModel);
264
264
  return resolve(segments);
265
- });
265
+ }).catch(function (e) { return reject(e); });
266
266
  });
267
267
  }
268
268
  console.error('This function is only permitted with local evaluation.');
@@ -312,6 +312,15 @@ var Flagsmith = /** @class */ (function () {
312
312
  });
313
313
  });
314
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
+ };
315
324
  Flagsmith.prototype.getJSONResponse = function (url, method, body) {
316
325
  return __awaiter(this, void 0, void 0, function () {
317
326
  var headers, _a, _b, _c, k, v, data;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flagsmith-nodejs",
3
- "version": "2.2.0",
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/index.ts CHANGED
@@ -152,10 +152,10 @@ export class Flagsmith {
152
152
  return cachedItem;
153
153
  }
154
154
  if (this.enableLocalEvaluation) {
155
- return new Promise(resolve =>
155
+ return new Promise((resolve, reject) =>
156
156
  this.environmentPromise!.then(() => {
157
157
  resolve(this.getEnvironmentFlagsFromDocument());
158
- })
158
+ }).catch((e) => reject(e))
159
159
  );
160
160
  }
161
161
  if (this.environment) {
@@ -182,10 +182,10 @@ export class Flagsmith {
182
182
  }
183
183
  traits = traits || {};
184
184
  if (this.enableLocalEvaluation) {
185
- return new Promise(resolve =>
185
+ return new Promise((resolve, reject) =>
186
186
  this.environmentPromise!.then(() => {
187
187
  resolve(this.getIdentityFlagsFromDocument(identifier, traits || {}));
188
- })
188
+ }).catch(e => reject(e))
189
189
  );
190
190
  }
191
191
  return this.getIdentityFlagsFromApi(identifier, traits);
@@ -208,8 +208,8 @@ export class Flagsmith {
208
208
  ): Promise<SegmentModel[]> {
209
209
  traits = traits || {};
210
210
  if (this.enableLocalEvaluation) {
211
- return this.environmentPromise!.then(() => {
212
- return new Promise(resolve => {
211
+ return new Promise((resolve, reject) => {
212
+ return this.environmentPromise!.then(() => {
213
213
  const identityModel = this.buildIdentityModel(
214
214
  identifier,
215
215
  Object.keys(traits || {}).map(key => ({
@@ -220,7 +220,7 @@ export class Flagsmith {
220
220
 
221
221
  const segments = getIdentitySegments(this.environment, identityModel);
222
222
  return resolve(segments);
223
- });
223
+ }).catch((e) => reject(e));
224
224
  });
225
225
  }
226
226
  console.error('This function is only permitted with local evaluation.');
@@ -253,6 +253,10 @@ export class Flagsmith {
253
253
  }
254
254
  }
255
255
 
256
+ async close() {
257
+ this.environmentDataPollingManager?.stop();
258
+ }
259
+
256
260
  private async getJSONResponse(
257
261
  url: string,
258
262
  method: string,