flagsmith-nodejs 2.1.2 → 2.2.0

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.
@@ -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;
@@ -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
  }
@@ -339,10 +340,10 @@ var Flagsmith = /** @class */ (function () {
339
340
  }
340
341
  return [4 /*yield*/, (0, utils_1.retryFetch)(url, {
341
342
  method: method,
342
- timeout: this.requestTimeoutSeconds || undefined,
343
+ timeout: this.requestTimeoutMs || undefined,
343
344
  body: JSON.stringify(body),
344
345
  headers: headers
345
- }, this.retries, (this.requestTimeoutSeconds || 10) * 1000)];
346
+ }, this.retries)];
346
347
  case 1:
347
348
  data = _e.sent();
348
349
  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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flagsmith-nodejs",
3
- "version": "2.1.2",
3
+ "version": "2.2.0",
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
  }
@@ -271,12 +273,11 @@ export class Flagsmith {
271
273
  url,
272
274
  {
273
275
  method: method,
274
- timeout: this.requestTimeoutSeconds || undefined,
276
+ timeout: this.requestTimeoutMs || undefined,
275
277
  body: JSON.stringify(body),
276
278
  headers: headers
277
279
  },
278
- this.retries,
279
- (this.requestTimeoutSeconds || 10) * 1000
280
+ this.retries
280
281
  );
281
282
 
282
283
  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