@splitsoftware/splitio-commons 2.2.1-rc.4 → 2.2.1-rc.5

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/CHANGES.txt CHANGED
@@ -1,4 +1,4 @@
1
- 2.3.0 (May XXX, 2025)
1
+ 2.3.0 (May 12, 2025)
2
2
  - Added support for targeting rules based on rule-based segments.
3
3
  - Updated the Redis storage to:
4
4
  - Avoid lazy require of the `ioredis` dependency when the SDK is initialized, and
@@ -11,6 +11,8 @@ function ruleBasedSegmentMatcherContext(segmentName, storage, log) {
11
11
  var matchingKey = (0, key_1.getMatching)(key);
12
12
  function matchConditions(rbsegment) {
13
13
  var conditions = rbsegment.conditions || [];
14
+ if (!conditions.length)
15
+ return false;
14
16
  var evaluator = (0, parser_1.parser)(log, conditions, storage);
15
17
  var evaluation = evaluator((0, key_1.keyParser)(key), undefined, undefined, undefined, attributes, splitEvaluator);
16
18
  return (0, thenable_1.thenable)(evaluation) ?
@@ -4,6 +4,7 @@ exports.splitHttpClientFactory = void 0;
4
4
  var objectAssign_1 = require("../utils/lang/objectAssign");
5
5
  var constants_1 = require("../logger/constants");
6
6
  var decorateHeaders_1 = require("./decorateHeaders");
7
+ var timeout_1 = require("../utils/promise/timeout");
7
8
  var messageNoFetch = 'Global fetch API is not available.';
8
9
  /**
9
10
  * Factory of Split HTTP clients, which are HTTP clients with predefined headers for Split endpoints.
@@ -43,7 +44,8 @@ function splitHttpClientFactory(settings, _a) {
43
44
  // https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Checking_that_the_fetch_was_successful
44
45
  .then(function (response) {
45
46
  if (!response.ok) {
46
- return response.text().then(function (message) { return Promise.reject({ response: response, message: message }); });
47
+ // timeout after 100ms because `text()` promise doesn't settle in some implementations and cases (e.g. no content)
48
+ return (0, timeout_1.timeout)(100, response.text()).then(function (message) { return Promise.reject({ response: response, message: message }); }, function () { return Promise.reject({ response: response }); });
47
49
  }
48
50
  latencyTracker();
49
51
  return response;
@@ -6,7 +6,7 @@ var settingsValidation_1 = require("../../../utils/settingsValidation");
6
6
  var constants_2 = require("../../../logger/constants");
7
7
  var PROXY_CHECK_INTERVAL_MILLIS_CS = 60 * 60 * 1000; // 1 hour in Client Side
8
8
  var PROXY_CHECK_INTERVAL_MILLIS_SS = 24 * PROXY_CHECK_INTERVAL_MILLIS_CS; // 24 hours in Server Side
9
- function sdkEndpointOverriden(settings) {
9
+ function sdkEndpointOverridden(settings) {
10
10
  return settings.urls.sdk !== settingsValidation_1.base.urls.sdk;
11
11
  }
12
12
  /**
@@ -28,8 +28,8 @@ function splitChangesFetcherFactory(fetchSplitChanges, settings, storage) {
28
28
  var splitsPromise = fetchSplitChanges(since, noCache, till, settings.sync.flagSpecVersion === constants_1.FLAG_SPEC_VERSION ? rbSince : undefined)
29
29
  // Handle proxy error with spec 1.3
30
30
  .catch(function (err) {
31
- if (err.statusCode === 400 && sdkEndpointOverriden(settings) && settings.sync.flagSpecVersion === constants_1.FLAG_SPEC_VERSION) {
32
- log.error(constants_2.LOG_PREFIX_SYNC_SPLITS + 'Proxy error detected. If you are using Split Proxy, please upgrade to latest version');
31
+ if (err.statusCode === 400 && sdkEndpointOverridden(settings) && settings.sync.flagSpecVersion === constants_1.FLAG_SPEC_VERSION) {
32
+ log.error(constants_2.LOG_PREFIX_SYNC_SPLITS + 'Proxy error detected. Retrying with spec 1.2. If you are using Split Proxy, please upgrade to latest version');
33
33
  lastProxyCheckTimestamp = Date.now();
34
34
  settings.sync.flagSpecVersion = '1.2'; // fallback to 1.2 spec
35
35
  return fetchSplitChanges(since, noCache, till); // retry request without rbSince
@@ -8,6 +8,8 @@ export function ruleBasedSegmentMatcherContext(segmentName, storage, log) {
8
8
  var matchingKey = getMatching(key);
9
9
  function matchConditions(rbsegment) {
10
10
  var conditions = rbsegment.conditions || [];
11
+ if (!conditions.length)
12
+ return false;
11
13
  var evaluator = parser(log, conditions, storage);
12
14
  var evaluation = evaluator(keyParser(key), undefined, undefined, undefined, attributes, splitEvaluator);
13
15
  return thenable(evaluation) ?
@@ -1,6 +1,7 @@
1
1
  import { objectAssign } from '../utils/lang/objectAssign';
2
2
  import { ERROR_HTTP, ERROR_CLIENT_CANNOT_GET_READY } from '../logger/constants';
3
3
  import { decorateHeaders, removeNonISO88591 } from './decorateHeaders';
4
+ import { timeout } from '../utils/promise/timeout';
4
5
  var messageNoFetch = 'Global fetch API is not available.';
5
6
  /**
6
7
  * Factory of Split HTTP clients, which are HTTP clients with predefined headers for Split endpoints.
@@ -40,7 +41,8 @@ export function splitHttpClientFactory(settings, _a) {
40
41
  // https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Checking_that_the_fetch_was_successful
41
42
  .then(function (response) {
42
43
  if (!response.ok) {
43
- return response.text().then(function (message) { return Promise.reject({ response: response, message: message }); });
44
+ // timeout after 100ms because `text()` promise doesn't settle in some implementations and cases (e.g. no content)
45
+ return timeout(100, response.text()).then(function (message) { return Promise.reject({ response: response, message: message }); }, function () { return Promise.reject({ response: response }); });
44
46
  }
45
47
  latencyTracker();
46
48
  return response;
@@ -3,7 +3,7 @@ import { base } from '../../../utils/settingsValidation';
3
3
  import { LOG_PREFIX_SYNC_SPLITS } from '../../../logger/constants';
4
4
  var PROXY_CHECK_INTERVAL_MILLIS_CS = 60 * 60 * 1000; // 1 hour in Client Side
5
5
  var PROXY_CHECK_INTERVAL_MILLIS_SS = 24 * PROXY_CHECK_INTERVAL_MILLIS_CS; // 24 hours in Server Side
6
- function sdkEndpointOverriden(settings) {
6
+ function sdkEndpointOverridden(settings) {
7
7
  return settings.urls.sdk !== base.urls.sdk;
8
8
  }
9
9
  /**
@@ -25,8 +25,8 @@ export function splitChangesFetcherFactory(fetchSplitChanges, settings, storage)
25
25
  var splitsPromise = fetchSplitChanges(since, noCache, till, settings.sync.flagSpecVersion === FLAG_SPEC_VERSION ? rbSince : undefined)
26
26
  // Handle proxy error with spec 1.3
27
27
  .catch(function (err) {
28
- if (err.statusCode === 400 && sdkEndpointOverriden(settings) && settings.sync.flagSpecVersion === FLAG_SPEC_VERSION) {
29
- log.error(LOG_PREFIX_SYNC_SPLITS + 'Proxy error detected. If you are using Split Proxy, please upgrade to latest version');
28
+ if (err.statusCode === 400 && sdkEndpointOverridden(settings) && settings.sync.flagSpecVersion === FLAG_SPEC_VERSION) {
29
+ log.error(LOG_PREFIX_SYNC_SPLITS + 'Proxy error detected. Retrying with spec 1.2. If you are using Split Proxy, please upgrade to latest version');
30
30
  lastProxyCheckTimestamp = Date.now();
31
31
  settings.sync.flagSpecVersion = '1.2'; // fallback to 1.2 spec
32
32
  return fetchSplitChanges(since, noCache, till); // retry request without rbSince
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splitsoftware/splitio-commons",
3
- "version": "2.2.1-rc.4",
3
+ "version": "2.2.1-rc.5",
4
4
  "description": "Split JavaScript SDK common components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
package/src/dtos/types.ts CHANGED
@@ -210,8 +210,8 @@ export interface IRBSegment {
210
210
  status: 'ACTIVE' | 'ARCHIVED',
211
211
  conditions?: ISplitCondition[],
212
212
  excluded?: {
213
- keys?: string[],
214
- segments?: IExcludedSegment[]
213
+ keys?: string[] | null,
214
+ segments?: IExcludedSegment[] | null
215
215
  }
216
216
  }
217
217
 
@@ -15,6 +15,9 @@ export function ruleBasedSegmentMatcherContext(segmentName: string, storage: ISt
15
15
 
16
16
  function matchConditions(rbsegment: IRBSegment) {
17
17
  const conditions = rbsegment.conditions || [];
18
+
19
+ if (!conditions.length) return false;
20
+
18
21
  const evaluator = parser(log, conditions, storage);
19
22
 
20
23
  const evaluation = evaluator(
@@ -4,6 +4,7 @@ import { ERROR_HTTP, ERROR_CLIENT_CANNOT_GET_READY } from '../logger/constants';
4
4
  import { ISettings } from '../types';
5
5
  import { IPlatform } from '../sdkFactory/types';
6
6
  import { decorateHeaders, removeNonISO88591 } from './decorateHeaders';
7
+ import { timeout } from '../utils/promise/timeout';
7
8
 
8
9
  const messageNoFetch = 'Global fetch API is not available.';
9
10
 
@@ -45,7 +46,8 @@ export function splitHttpClientFactory(settings: ISettings, { getOptions, getFet
45
46
  // https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Checking_that_the_fetch_was_successful
46
47
  .then(response => {
47
48
  if (!response.ok) {
48
- return response.text().then(message => Promise.reject({ response, message }));
49
+ // timeout after 100ms because `text()` promise doesn't settle in some implementations and cases (e.g. no content)
50
+ return timeout(100, response.text()).then(message => Promise.reject({ response, message }), () => Promise.reject({ response }));
49
51
  }
50
52
  latencyTracker();
51
53
  return response;
@@ -10,7 +10,7 @@ import { LOG_PREFIX_SYNC_SPLITS } from '../../../logger/constants';
10
10
  const PROXY_CHECK_INTERVAL_MILLIS_CS = 60 * 60 * 1000; // 1 hour in Client Side
11
11
  const PROXY_CHECK_INTERVAL_MILLIS_SS = 24 * PROXY_CHECK_INTERVAL_MILLIS_CS; // 24 hours in Server Side
12
12
 
13
- function sdkEndpointOverriden(settings: ISettings) {
13
+ function sdkEndpointOverridden(settings: ISettings) {
14
14
  return settings.urls.sdk !== base.urls.sdk;
15
15
  }
16
16
 
@@ -42,8 +42,8 @@ export function splitChangesFetcherFactory(fetchSplitChanges: IFetchSplitChanges
42
42
  let splitsPromise = fetchSplitChanges(since, noCache, till, settings.sync.flagSpecVersion === FLAG_SPEC_VERSION ? rbSince : undefined)
43
43
  // Handle proxy error with spec 1.3
44
44
  .catch((err) => {
45
- if (err.statusCode === 400 && sdkEndpointOverriden(settings) && settings.sync.flagSpecVersion === FLAG_SPEC_VERSION) {
46
- log.error(LOG_PREFIX_SYNC_SPLITS + 'Proxy error detected. If you are using Split Proxy, please upgrade to latest version');
45
+ if (err.statusCode === 400 && sdkEndpointOverridden(settings) && settings.sync.flagSpecVersion === FLAG_SPEC_VERSION) {
46
+ log.error(LOG_PREFIX_SYNC_SPLITS + 'Proxy error detected. Retrying with spec 1.2. If you are using Split Proxy, please upgrade to latest version');
47
47
  lastProxyCheckTimestamp = Date.now();
48
48
  settings.sync.flagSpecVersion = '1.2'; // fallback to 1.2 spec
49
49
  return fetchSplitChanges(since, noCache, till); // retry request without rbSince