@splitsoftware/splitio 10.22.3 → 10.22.5-rc.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.
- package/CHANGES.txt +32 -20
- package/CONTRIBUTORS-GUIDE.md +2 -2
- package/LICENSE +1 -1
- package/README.md +6 -6
- package/es/index.js +0 -15
- package/es/settings/defaults/version.js +1 -1
- package/es/sync/offline/splitsParserFromFile.js +27 -26
- package/lib/index.js +0 -15
- package/lib/settings/defaults/version.js +1 -1
- package/lib/sync/offline/splitsParserFromFile.js +27 -26
- package/package.json +7 -2
- package/src/index.js +0 -16
- package/src/platform/EventEmitter.js +95 -95
- package/src/settings/defaults/version.js +1 -1
- package/src/sync/offline/splitsParserFromFile.js +27 -26
- package/types/client/index.d.ts +1 -1
- package/types/index.d.ts +1 -1
- package/types/server/index.d.ts +1 -1
- package/types/splitio.d.ts +104 -98
package/CHANGES.txt
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
10.22.5 (May 15, 2023)
|
|
2
|
+
- Updated @splitsoftware/splitio-commons package to version 1.8.2 that includes minor improvements.
|
|
3
|
+
- Updated terminology on the SDKs codebase to be more aligned with current standard without causing a breaking change. The core change is the term split for feature flag on things like logs and IntelliSense comments.
|
|
4
|
+
- Updated split storage modules to optimize some operations when using Redis and pluggable storages.
|
|
5
|
+
- Updated some transitive dependencies for vulnerability fixes.
|
|
6
|
+
|
|
7
|
+
10.22.4 (March 9, 2023)
|
|
8
|
+
- Updated @splitsoftware/splitio-commons package to version 1.8.1 that includes minor improvements.
|
|
9
|
+
- Updated some transitive dependencies for vulnerability fixes.
|
|
10
|
+
|
|
1
11
|
10.22.3 (December 16, 2022)
|
|
2
12
|
- Updated some transitive dependencies for vulnerability fixes.
|
|
3
13
|
- Bugfixing - Upgrade @splitsoftware/splitio-commons package to version 1.7.3 which includes a memory leak fix for localhost mode (Related to issue https://github.com/splitio/javascript-commons/issues/181) among other improvements.
|
|
@@ -11,7 +21,7 @@
|
|
|
11
21
|
10.22.0 (October 5, 2022)
|
|
12
22
|
- Added a new impressions mode for the SDK called NONE, to be used in factory when there is no desire to capture impressions on an SDK factory to feed Split's analytics engine. Running NONE mode, the SDK will only capture unique keys evaluated for a particular feature flag instead of full blown impressions.
|
|
13
23
|
- Updated default value of `scheduler.featuresRefreshRate` config parameter from 5 seconds to 60 seconds for NodeJS and from 30 seconds to 60 seconds for Browser.
|
|
14
|
-
- Updated @splitsoftware/splitio-commons package to version 1.7.1, that improves the performance of
|
|
24
|
+
- Updated @splitsoftware/splitio-commons package to version 1.7.1, that improves the performance of feature flag evaluations (i.e., `getTreatment(s)` method calls) when using the default storage in memory, among other improvements.
|
|
15
25
|
|
|
16
26
|
10.21.1 (July 25, 2022)
|
|
17
27
|
- Bugfixing - Added missed type definitions `enabled` from `sync`.
|
|
@@ -80,7 +90,7 @@
|
|
|
80
90
|
- Bugfixing - Fixed an issue returning dynamic configs when the treatment name contains a dot (".").
|
|
81
91
|
|
|
82
92
|
10.16.1 (October 25, 2021)
|
|
83
|
-
- Updated some internal modules to optimize the time efficiency of
|
|
93
|
+
- Updated some internal modules to optimize the time efficiency of feature flag evaluations (i.e., `getTreatment(s)` method calls).
|
|
84
94
|
- Updated some dependencies for vulnerability fixes (ioredis, @babel/cli, eslint, eslint-plugin-compat).
|
|
85
95
|
- Bugfixing - Fixed localhost mode with localStorage, to use a mock in memory instead of localStorage API directly but keep emitting emit SDK_READY_FROM_CACHE event.
|
|
86
96
|
|
|
@@ -91,6 +101,7 @@
|
|
|
91
101
|
- Implemented handling of the new MySegmentsV2 notification types (SegmentRemoval, KeyList, Bounded and Unbounded)
|
|
92
102
|
- New control notification for environment scoped streaming reset.
|
|
93
103
|
- Updated some dependencies to their latest versions, including Webpack 4 to 5, to build a more optimized UMD bundle.
|
|
104
|
+
- NOTE: build script is configured to transpile to ES5 with Babel loose mode (https://2ality.com/2015/12/babel6-loose-mode.html). It results in a smaller bundle size and faster code execution but with some differences in the transpiled code, that may affect old browser versions like some builds of IE10.
|
|
94
105
|
|
|
95
106
|
10.15.9 (Aug 13, 2021)
|
|
96
107
|
- Updated some dependencies with vulnerability fixes.
|
|
@@ -141,7 +152,7 @@
|
|
|
141
152
|
- Updated TypeScript declarations to include the `urls` settings object (to connect to Split Synchronizer in proxy mode) for the non-async settings where it would be applicable.
|
|
142
153
|
- Bugfixing - Updating some imports of hashing utilities to use safe relative paths and avoid module resolution issues.
|
|
143
154
|
- Bugfixing - Updating logic to avoid a corner case issue with the sendHitTask callback handling of the GOOGLE_ANALYTICS_TO_SPLIT integration.
|
|
144
|
-
- Bugfixing - Updating the package.json version import to be compatible with latest standards (thanks @andrew-t-james-hm).
|
|
155
|
+
- Bugfixing - Updating the package.json version import to be compatible with latest standards (Related to issue https://github.com/splitio/javascript-client/pull/495, thanks @andrew-t-james-hm).
|
|
145
156
|
|
|
146
157
|
10.15.0 (Oct 6, 2020)
|
|
147
158
|
- Added impressions dedupe logic to avoid sending duplicated impressions:
|
|
@@ -166,9 +177,10 @@
|
|
|
166
177
|
- Bugfixing - Replaced the use of `for...in` statements since it iterates over enumerable properties on the prototype chain, which might be polluted by code external to the library.
|
|
167
178
|
|
|
168
179
|
10.14.0 (Jul 31, 2020)
|
|
169
|
-
- Added `sync.splitFilters` property to SDK configuration to pass a list of filters for the
|
|
170
|
-
- Added expiration policy to
|
|
180
|
+
- Added `sync.splitFilters` property to SDK configuration to pass a list of filters for the feature flags that will be downloaded. Read more in our docs.
|
|
181
|
+
- Added expiration policy to SDK cache for browsers using localStorage: cache is cleared after 10 days of the last successful update.
|
|
171
182
|
- Updated babel configuration to remove core-js dependency and refactored code in favor of size reduction of UMD, ESM and CommonJS builds.
|
|
183
|
+
- NOTE: removed some polyfills of global objects not available in some builds of IE10.
|
|
172
184
|
|
|
173
185
|
10.13.0 (Jun 25, 2020)
|
|
174
186
|
- Updated client.ready() and manager.ready() functions to be consumed on demand and return a promise reflecting the current status of the SDK at the time the method was invoked.
|
|
@@ -199,7 +211,7 @@
|
|
|
199
211
|
- Bugfixing - Emit SDK_UPDATE in localhost only when mock was actually updated.
|
|
200
212
|
|
|
201
213
|
10.10.0 (Jan 10, 2020)
|
|
202
|
-
- Added SDK_READY_FROM_CACHE event, which will be emitted in LocalStorage mode when the SDK finds
|
|
214
|
+
- Added SDK_READY_FROM_CACHE event, which will be emitted in LocalStorage mode when the SDK finds feature flag definitions in the storage of the browser.
|
|
203
215
|
- Updated a dependency to fix a vulnerability (serialize-javascript).
|
|
204
216
|
- Updated multiple dependencies and dev dependencies (@types/node, axios, core-js, events, sinon, tape and the babel cli, core, preset-env, register and plugin-transform-runtime)
|
|
205
217
|
|
|
@@ -214,14 +226,14 @@
|
|
|
214
226
|
10.9.0 (Oct 24, 2019)
|
|
215
227
|
- Added listener for 'unload' DOM events to push remaining impressions and events when the browser page is closed or reloaded.
|
|
216
228
|
- Added setting core.IPAddressesEnabled to disable reporting IP Addresses and Machine name back to Split cloud.
|
|
217
|
-
- Updated Redis storage to fetch multiple
|
|
229
|
+
- Updated Redis storage to fetch multiple feature flags at once for getTreatments/getTreatmentsWithConfig.
|
|
218
230
|
- Updated most dependencies to their latest versions. Biggest change is babel (from 6 to 7), Webpack 3 to 4, Karma and ioredis.
|
|
219
231
|
|
|
220
232
|
10.8.4 (Sep 24, 2019)
|
|
221
233
|
- Added module "events" as optional dependency.
|
|
222
234
|
- Removed dependency on "util" module.
|
|
223
235
|
- Updated transport module to use a local axios instance instead of the global one, to avoid polluting the shared one.
|
|
224
|
-
- Updated input validation log when trying to get data of a non-existent
|
|
236
|
+
- Updated input validation log when trying to get data of a non-existent feature flag to have level WARN instead of ERROR.
|
|
225
237
|
|
|
226
238
|
10.8.3 (Sep 16, 2019)
|
|
227
239
|
- Updated two default values on startup configuration for Browsers:
|
|
@@ -344,7 +356,7 @@
|
|
|
344
356
|
- Updated SDK labels.
|
|
345
357
|
- Bugfixing - Shared clients (browser) were ready even if the main client was not.
|
|
346
358
|
- Bugfixing - Shared clients (browser) from different SDK instances should be separate.
|
|
347
|
-
- Bugfixing - When using
|
|
359
|
+
- Bugfixing - When using SDK key with wrong permissions, Node was throwing a false ready event (without segments).
|
|
348
360
|
- Bugfixing - Localhost mode was trying to flush impressions when client.destroy was invoked.
|
|
349
361
|
|
|
350
362
|
9.3.7 (Dec 22, 2017)
|
|
@@ -401,7 +413,7 @@
|
|
|
401
413
|
|
|
402
414
|
var settings = {
|
|
403
415
|
core: {
|
|
404
|
-
authorizationKey: '
|
|
416
|
+
authorizationKey: 'YOUR_SDK_KEY',
|
|
405
417
|
key: 'CUSTOMER_KEY' // If on the browser.
|
|
406
418
|
},
|
|
407
419
|
debug: true // Boolean flag for enabling logs. Default value is false.
|
|
@@ -417,7 +429,7 @@
|
|
|
417
429
|
|
|
418
430
|
var sdk = splitio({
|
|
419
431
|
core: {
|
|
420
|
-
authorizationKey: '
|
|
432
|
+
authorizationKey: 'YOUR_SDK_KEY',
|
|
421
433
|
key: 'CUSTOMER_KEY' // If on the browser.
|
|
422
434
|
}
|
|
423
435
|
});
|
|
@@ -454,13 +466,13 @@
|
|
|
454
466
|
- Adding getTreatments method to client API. For example:
|
|
455
467
|
|
|
456
468
|
```js
|
|
457
|
-
var treatmentsMap = client.getTreatments('CUSTOMER_KEY', ['
|
|
469
|
+
var treatmentsMap = client.getTreatments('CUSTOMER_KEY', ['Feature_flag_1', 'Feature_flag_2']);
|
|
458
470
|
|
|
459
471
|
/*
|
|
460
|
-
* treatmentsMap will be an object mapping
|
|
472
|
+
* treatmentsMap will be an object mapping feature flags with treatments. For example:
|
|
461
473
|
* {
|
|
462
|
-
*
|
|
463
|
-
*
|
|
474
|
+
* Feature_flag_1: 'on',
|
|
475
|
+
* Feature_flag_2: 'off
|
|
464
476
|
* }
|
|
465
477
|
*/
|
|
466
478
|
```
|
|
@@ -627,7 +639,7 @@ var treatmentsMap = client.getTreatments('CUSTOMER_KEY', ['Split_1', 'Split_2'])
|
|
|
627
639
|
|
|
628
640
|
6.0.0 (June 24, 2016)
|
|
629
641
|
- In the browser land we allow quick retries before start using the refresh
|
|
630
|
-
rates defined for segments and
|
|
642
|
+
rates defined for segments and feature flags, plus the possibility of receive an
|
|
631
643
|
event when the SDK is taking to much time to startup.
|
|
632
644
|
|
|
633
645
|
```html
|
|
@@ -692,8 +704,8 @@ var treatmentsMap = client.getTreatments('CUSTOMER_KEY', ['Split_1', 'Split_2'])
|
|
|
692
704
|
});
|
|
693
705
|
|
|
694
706
|
// usage
|
|
695
|
-
var t1 = dynamic1.getTreatment('
|
|
696
|
-
var t2 = dynamic2.getTreatment('another-
|
|
707
|
+
var t1 = dynamic1.getTreatment('feature-flag-name');
|
|
708
|
+
var t2 = dynamic2.getTreatment('another-feature-flag-name');
|
|
697
709
|
|
|
698
710
|
// stop SDK
|
|
699
711
|
dynamic1.destroy();
|
|
@@ -770,7 +782,7 @@ var treatmentsMap = client.getTreatments('CUSTOMER_KEY', ['Split_1', 'Split_2'])
|
|
|
770
782
|
```js
|
|
771
783
|
var sdk = splitio({
|
|
772
784
|
core: {
|
|
773
|
-
authorizationKey: 'c1l5vkd50gimccout3c03pntbu', // your
|
|
785
|
+
authorizationKey: 'c1l5vkd50gimccout3c03pntbu', // your SDK key
|
|
774
786
|
key: '4a2c4490-ced1-11e5-9b97-d8a25e8b1578' // your customer id
|
|
775
787
|
}
|
|
776
788
|
});
|
|
@@ -799,7 +811,7 @@ seconds:
|
|
|
799
811
|
```js
|
|
800
812
|
var sdk = splitio({
|
|
801
813
|
core: {
|
|
802
|
-
authorizationKey: 'c1l5vkd50gimccout3c03pntbu', // your
|
|
814
|
+
authorizationKey: 'c1l5vkd50gimccout3c03pntbu', // your SDK key
|
|
803
815
|
key: '4a2c4490-ced1-11e5-9b97-d8a25e8b1578' // your customer id
|
|
804
816
|
},
|
|
805
817
|
scheduler: {
|
package/CONTRIBUTORS-GUIDE.md
CHANGED
|
@@ -7,10 +7,10 @@ Split SDK is an open source project and we welcome feedback and contribution. Th
|
|
|
7
7
|
### Development process
|
|
8
8
|
|
|
9
9
|
1. Fork the repository and create a topic branch from `development` branch. Please use a descriptive name for your branch.
|
|
10
|
-
2. Run `nvm use` to ensure that you are using the right npm and node version, and `npm install` to have the dependencies up to date.
|
|
10
|
+
2. Run `nvm use` to ensure that you are using the right npm and node version, and `npm install` to have the dependencies up to date.
|
|
11
11
|
3. While developing, use descriptive messages in your commits. Avoid short or meaningless sentences like: "fix bug".
|
|
12
12
|
4. Make sure to add tests for both positive and negative cases.
|
|
13
|
-
5. If your changes have any impact on the public API, make sure you update the TypeScript
|
|
13
|
+
5. If your changes have any impact on the public API, make sure you update the TypeScript declarations as well as it's related test file.
|
|
14
14
|
6. Run the linter script of the project and fix any issues you find.
|
|
15
15
|
7. Run the build script and make sure it runs with no errors.
|
|
16
16
|
8. Run all tests and make sure there are no failures.
|
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
# Split SDK for
|
|
1
|
+
# Split SDK for JavaScript
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/js/%40splitsoftware%2Fsplitio) [](https://github.com/splitio/javascript-client/actions/workflows/ci-cd.yml) [](https://greenkeeper.io/)
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
|
-
This SDK is designed to work with Split, the platform for controlled rollouts, which serves features to your users via
|
|
6
|
+
This SDK is designed to work with Split, the platform for controlled rollouts, which serves features to your users via feature flags to manage your complete customer experience.
|
|
7
7
|
|
|
8
8
|
[](https://twitter.com/intent/follow?screen_name=splitsoftware)
|
|
9
9
|
|
|
@@ -23,7 +23,7 @@ var SplitFactory = require('@splitsoftware/splitio').SplitFactory;
|
|
|
23
23
|
// Instantiate the SDK
|
|
24
24
|
var factory = SplitFactory({
|
|
25
25
|
core: {
|
|
26
|
-
authorizationKey: '
|
|
26
|
+
authorizationKey: 'YOUR_SDK_KEY'
|
|
27
27
|
}
|
|
28
28
|
});
|
|
29
29
|
|
|
@@ -32,7 +32,7 @@ var client = factory.client();
|
|
|
32
32
|
|
|
33
33
|
// Set a callback to listen for the SDK_READY event, to make sure the SDK is properly loaded before asking for a treatment
|
|
34
34
|
client.on(client.Event.SDK_READY, function() {
|
|
35
|
-
var treatment = client.getTreatment('CUSTOMER_ID', '
|
|
35
|
+
var treatment = client.getTreatment('CUSTOMER_ID', 'FEATURE_FLAG_NAME');
|
|
36
36
|
if (treatment == 'on') {
|
|
37
37
|
// insert code here for on treatment
|
|
38
38
|
} else if (treatment == 'off') {
|
|
@@ -67,8 +67,8 @@ Split has built and maintains SDKs for:
|
|
|
67
67
|
* GO [Github](https://github.com/splitio/go-client) [Docs](https://help.split.io/hc/en-us/articles/360020093652-Go-SDK)
|
|
68
68
|
* iOS [Github](https://github.com/splitio/ios-client) [Docs](https://help.split.io/hc/en-us/articles/360020401491-iOS-SDK)
|
|
69
69
|
* Java [Github](https://github.com/splitio/java-client) [Docs](https://help.split.io/hc/en-us/articles/360020405151-Java-SDK)
|
|
70
|
-
*
|
|
71
|
-
*
|
|
70
|
+
* JavaScript [Github](https://github.com/splitio/javascript-client) [Docs](https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK)
|
|
71
|
+
* JavaScript for Browser [Github](https://github.com/splitio/javascript-browser-client) [Docs](https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK)
|
|
72
72
|
* Node [Github](https://github.com/splitio/javascript-client) [Docs](https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK)
|
|
73
73
|
* PHP [Github](https://github.com/splitio/php-client) [Docs](https://help.split.io/hc/en-us/articles/360020350372-PHP-SDK)
|
|
74
74
|
* Python [Github](https://github.com/splitio/python-client) [Docs](https://help.split.io/hc/en-us/articles/360020359652-Python-SDK)
|
package/es/index.js
CHANGED
|
@@ -1,16 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
Copyright 2022 Split Software
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
**/
|
|
16
1
|
export { SplitFactory } from './factory';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export var packageVersion = '10.22.
|
|
1
|
+
export var packageVersion = '10.22.5-rc.0';
|
|
@@ -3,31 +3,32 @@ import path from 'path';
|
|
|
3
3
|
import yaml from 'js-yaml';
|
|
4
4
|
import { isString, endsWith, find, forOwn, uniq, } from '@splitsoftware/splitio-commons/esm/utils/lang';
|
|
5
5
|
import { parseCondition } from '@splitsoftware/splitio-commons/esm/sync/offline/splitsParser/parseCondition';
|
|
6
|
-
var logPrefix = 'sync:offline:
|
|
6
|
+
var logPrefix = 'sync:offline:fetcher: ';
|
|
7
7
|
var DEFAULT_FILENAME = '.split';
|
|
8
8
|
function configFilesPath(configFilePath) {
|
|
9
9
|
if (configFilePath === DEFAULT_FILENAME || !isString(configFilePath)) {
|
|
10
10
|
var root = process.env.HOME;
|
|
11
|
+
// @TODO env var not documented in help center
|
|
11
12
|
if (process.env.SPLIT_CONFIG_ROOT)
|
|
12
13
|
root = process.env.SPLIT_CONFIG_ROOT;
|
|
13
14
|
if (!root)
|
|
14
|
-
throw new Error('Missing
|
|
15
|
+
throw new Error('Missing root of the feature flags mock file.');
|
|
15
16
|
configFilePath = path.join(root, DEFAULT_FILENAME);
|
|
16
17
|
}
|
|
17
18
|
// Validate the extensions
|
|
18
19
|
if (!(endsWith(configFilePath, '.yaml', true) || endsWith(configFilePath, '.yml', true) || endsWith(configFilePath, '.split', true)))
|
|
19
|
-
throw new Error("Invalid extension specified for
|
|
20
|
+
throw new Error("Invalid extension specified for feature flags mock file. Accepted extensions are \".yml\" and \".yaml\". Your specified file is " + configFilePath);
|
|
20
21
|
if (!fs.existsSync(configFilePath))
|
|
21
|
-
throw new Error("
|
|
22
|
+
throw new Error("Feature flags mock file not found in " + configFilePath + " - Please review the file location.");
|
|
22
23
|
return configFilePath;
|
|
23
24
|
}
|
|
24
25
|
// This function is not pure nor meant to be. Here we apply modifications to cover
|
|
25
26
|
// for behaviour that's ensured by the BE.
|
|
26
27
|
function arrangeConditions(mocksData) {
|
|
27
|
-
// Iterate through each
|
|
28
|
+
// Iterate through each feature flag data
|
|
28
29
|
forOwn(mocksData, function (data) {
|
|
29
30
|
var conditions = data.conditions;
|
|
30
|
-
// On the manager, as
|
|
31
|
+
// On the manager, as feature flag JSONs come with all treatments on the partitions prop,
|
|
31
32
|
// we'll add all the treatments to the first condition.
|
|
32
33
|
var firstRolloutCondition = find(conditions, function (cond) { return cond.conditionType === 'ROLLOUT'; });
|
|
33
34
|
// Malformed mocks may have
|
|
@@ -49,9 +50,9 @@ function arrangeConditions(mocksData) {
|
|
|
49
50
|
}
|
|
50
51
|
export function splitsParserFromFileFactory() {
|
|
51
52
|
var previousMock = 'NO_MOCK_LOADED';
|
|
52
|
-
// Parse `.split` configuration file and return a map of
|
|
53
|
-
function
|
|
54
|
-
var
|
|
53
|
+
// Parse `.split` configuration file and return a map of feature flag objects
|
|
54
|
+
function readFeatureFlagConfigFile(log, filePath) {
|
|
55
|
+
var FEATURE_FLAG_POSITION = 0;
|
|
55
56
|
var TREATMENT_POSITION = 1;
|
|
56
57
|
var data;
|
|
57
58
|
try {
|
|
@@ -64,7 +65,7 @@ export function splitsParserFromFileFactory() {
|
|
|
64
65
|
if (data === previousMock)
|
|
65
66
|
return false;
|
|
66
67
|
previousMock = data;
|
|
67
|
-
var
|
|
68
|
+
var featureFlagObjects = data.split(/\r?\n/).reduce(function (accum, line, index) {
|
|
68
69
|
var tuple = line.trim();
|
|
69
70
|
if (tuple === '' || tuple.charAt(0) === '#') {
|
|
70
71
|
log.debug(logPrefix + ("Ignoring empty line or comment at #" + index));
|
|
@@ -75,16 +76,16 @@ export function splitsParserFromFileFactory() {
|
|
|
75
76
|
log.debug(logPrefix + ("Ignoring line since it does not have exactly two columns #" + index));
|
|
76
77
|
}
|
|
77
78
|
else {
|
|
78
|
-
var
|
|
79
|
+
var featureFlagName = tuple[FEATURE_FLAG_POSITION];
|
|
79
80
|
var condition = parseCondition({ treatment: tuple[TREATMENT_POSITION] });
|
|
80
|
-
accum[
|
|
81
|
+
accum[featureFlagName] = { conditions: [condition], configurations: {}, trafficTypeName: 'localhost' };
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
return accum;
|
|
84
85
|
}, {});
|
|
85
|
-
return
|
|
86
|
+
return featureFlagObjects;
|
|
86
87
|
}
|
|
87
|
-
// Parse `.yml` or `.yaml` configuration files and return a map of
|
|
88
|
+
// Parse `.yml` or `.yaml` configuration files and return a map of feature flag objects
|
|
88
89
|
function readYAMLConfigFile(log, filePath) {
|
|
89
90
|
var data = '';
|
|
90
91
|
var yamldoc = null;
|
|
@@ -100,39 +101,39 @@ export function splitsParserFromFileFactory() {
|
|
|
100
101
|
return {};
|
|
101
102
|
}
|
|
102
103
|
// Each entry will be mapped to a condition, but we'll also keep the configurations map.
|
|
103
|
-
var mocksData = (yamldoc).reduce(function (accum,
|
|
104
|
-
var
|
|
105
|
-
if (!
|
|
104
|
+
var mocksData = (yamldoc).reduce(function (accum, featureFlagEntry) {
|
|
105
|
+
var featureFlagName = Object.keys(featureFlagEntry)[0];
|
|
106
|
+
if (!featureFlagName || !isString(featureFlagEntry[featureFlagName].treatment))
|
|
106
107
|
log.error(logPrefix + 'Ignoring entry on YAML since the format is incorrect.');
|
|
107
|
-
var mockData =
|
|
108
|
-
// "Template" for each
|
|
109
|
-
if (!accum[
|
|
110
|
-
accum[
|
|
108
|
+
var mockData = featureFlagEntry[featureFlagName];
|
|
109
|
+
// "Template" for each feature flag accumulated data
|
|
110
|
+
if (!accum[featureFlagName]) {
|
|
111
|
+
accum[featureFlagName] = {
|
|
111
112
|
configurations: {}, conditions: [], treatments: [], trafficTypeName: 'localhost'
|
|
112
113
|
};
|
|
113
114
|
}
|
|
114
115
|
// Assign the config if there is one on the mock
|
|
115
116
|
if (mockData.config)
|
|
116
|
-
accum[
|
|
117
|
+
accum[featureFlagName].configurations[mockData.treatment] = mockData.config;
|
|
117
118
|
// Parse the condition from the entry.
|
|
118
119
|
var condition = parseCondition(mockData);
|
|
119
|
-
accum[
|
|
120
|
+
accum[featureFlagName].conditions[condition.conditionType === 'ROLLOUT' ? 'push' : 'unshift'](condition);
|
|
120
121
|
// Also keep track of the treatments, will be useful for manager functionality.
|
|
121
|
-
accum[
|
|
122
|
+
accum[featureFlagName].treatments.push(mockData.treatment);
|
|
122
123
|
return accum;
|
|
123
124
|
}, {});
|
|
124
125
|
arrangeConditions(mocksData);
|
|
125
126
|
return mocksData;
|
|
126
127
|
}
|
|
127
128
|
// Load the content of a configuration file into an Object
|
|
128
|
-
return function
|
|
129
|
+
return function featureFlagsParserFromFile(_a) {
|
|
129
130
|
var features = _a.features, log = _a.log;
|
|
130
131
|
var filePath = configFilesPath(features);
|
|
131
132
|
var mockData;
|
|
132
133
|
// If we have a filePath, it means the extension is correct, choose the parser.
|
|
133
134
|
if (endsWith(filePath, '.split')) {
|
|
134
135
|
log.warn(logPrefix + '.split mocks will be deprecated soon in favor of YAML files, which provide more targeting power. Take a look in our documentation.');
|
|
135
|
-
mockData =
|
|
136
|
+
mockData = readFeatureFlagConfigFile(log, filePath);
|
|
136
137
|
}
|
|
137
138
|
else {
|
|
138
139
|
mockData = readYAMLConfigFile(log, filePath);
|
package/lib/index.js
CHANGED
|
@@ -1,19 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
Copyright 2022 Split Software
|
|
4
|
-
|
|
5
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
you may not use this file except in compliance with the License.
|
|
7
|
-
You may obtain a copy of the License at
|
|
8
|
-
|
|
9
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
|
|
11
|
-
Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
See the License for the specific language governing permissions and
|
|
15
|
-
limitations under the License.
|
|
16
|
-
**/
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.SplitFactory = void 0;
|
|
19
4
|
var factory_1 = require("./factory");
|
|
@@ -7,31 +7,32 @@ var path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
|
7
7
|
var js_yaml_1 = (0, tslib_1.__importDefault)(require("js-yaml"));
|
|
8
8
|
var lang_1 = require("@splitsoftware/splitio-commons/cjs/utils/lang");
|
|
9
9
|
var parseCondition_1 = require("@splitsoftware/splitio-commons/cjs/sync/offline/splitsParser/parseCondition");
|
|
10
|
-
var logPrefix = 'sync:offline:
|
|
10
|
+
var logPrefix = 'sync:offline:fetcher: ';
|
|
11
11
|
var DEFAULT_FILENAME = '.split';
|
|
12
12
|
function configFilesPath(configFilePath) {
|
|
13
13
|
if (configFilePath === DEFAULT_FILENAME || !(0, lang_1.isString)(configFilePath)) {
|
|
14
14
|
var root = process.env.HOME;
|
|
15
|
+
// @TODO env var not documented in help center
|
|
15
16
|
if (process.env.SPLIT_CONFIG_ROOT)
|
|
16
17
|
root = process.env.SPLIT_CONFIG_ROOT;
|
|
17
18
|
if (!root)
|
|
18
|
-
throw new Error('Missing
|
|
19
|
+
throw new Error('Missing root of the feature flags mock file.');
|
|
19
20
|
configFilePath = path_1.default.join(root, DEFAULT_FILENAME);
|
|
20
21
|
}
|
|
21
22
|
// Validate the extensions
|
|
22
23
|
if (!((0, lang_1.endsWith)(configFilePath, '.yaml', true) || (0, lang_1.endsWith)(configFilePath, '.yml', true) || (0, lang_1.endsWith)(configFilePath, '.split', true)))
|
|
23
|
-
throw new Error("Invalid extension specified for
|
|
24
|
+
throw new Error("Invalid extension specified for feature flags mock file. Accepted extensions are \".yml\" and \".yaml\". Your specified file is " + configFilePath);
|
|
24
25
|
if (!fs_1.default.existsSync(configFilePath))
|
|
25
|
-
throw new Error("
|
|
26
|
+
throw new Error("Feature flags mock file not found in " + configFilePath + " - Please review the file location.");
|
|
26
27
|
return configFilePath;
|
|
27
28
|
}
|
|
28
29
|
// This function is not pure nor meant to be. Here we apply modifications to cover
|
|
29
30
|
// for behaviour that's ensured by the BE.
|
|
30
31
|
function arrangeConditions(mocksData) {
|
|
31
|
-
// Iterate through each
|
|
32
|
+
// Iterate through each feature flag data
|
|
32
33
|
(0, lang_1.forOwn)(mocksData, function (data) {
|
|
33
34
|
var conditions = data.conditions;
|
|
34
|
-
// On the manager, as
|
|
35
|
+
// On the manager, as feature flag JSONs come with all treatments on the partitions prop,
|
|
35
36
|
// we'll add all the treatments to the first condition.
|
|
36
37
|
var firstRolloutCondition = (0, lang_1.find)(conditions, function (cond) { return cond.conditionType === 'ROLLOUT'; });
|
|
37
38
|
// Malformed mocks may have
|
|
@@ -53,9 +54,9 @@ function arrangeConditions(mocksData) {
|
|
|
53
54
|
}
|
|
54
55
|
function splitsParserFromFileFactory() {
|
|
55
56
|
var previousMock = 'NO_MOCK_LOADED';
|
|
56
|
-
// Parse `.split` configuration file and return a map of
|
|
57
|
-
function
|
|
58
|
-
var
|
|
57
|
+
// Parse `.split` configuration file and return a map of feature flag objects
|
|
58
|
+
function readFeatureFlagConfigFile(log, filePath) {
|
|
59
|
+
var FEATURE_FLAG_POSITION = 0;
|
|
59
60
|
var TREATMENT_POSITION = 1;
|
|
60
61
|
var data;
|
|
61
62
|
try {
|
|
@@ -68,7 +69,7 @@ function splitsParserFromFileFactory() {
|
|
|
68
69
|
if (data === previousMock)
|
|
69
70
|
return false;
|
|
70
71
|
previousMock = data;
|
|
71
|
-
var
|
|
72
|
+
var featureFlagObjects = data.split(/\r?\n/).reduce(function (accum, line, index) {
|
|
72
73
|
var tuple = line.trim();
|
|
73
74
|
if (tuple === '' || tuple.charAt(0) === '#') {
|
|
74
75
|
log.debug(logPrefix + ("Ignoring empty line or comment at #" + index));
|
|
@@ -79,16 +80,16 @@ function splitsParserFromFileFactory() {
|
|
|
79
80
|
log.debug(logPrefix + ("Ignoring line since it does not have exactly two columns #" + index));
|
|
80
81
|
}
|
|
81
82
|
else {
|
|
82
|
-
var
|
|
83
|
+
var featureFlagName = tuple[FEATURE_FLAG_POSITION];
|
|
83
84
|
var condition = (0, parseCondition_1.parseCondition)({ treatment: tuple[TREATMENT_POSITION] });
|
|
84
|
-
accum[
|
|
85
|
+
accum[featureFlagName] = { conditions: [condition], configurations: {}, trafficTypeName: 'localhost' };
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
88
|
return accum;
|
|
88
89
|
}, {});
|
|
89
|
-
return
|
|
90
|
+
return featureFlagObjects;
|
|
90
91
|
}
|
|
91
|
-
// Parse `.yml` or `.yaml` configuration files and return a map of
|
|
92
|
+
// Parse `.yml` or `.yaml` configuration files and return a map of feature flag objects
|
|
92
93
|
function readYAMLConfigFile(log, filePath) {
|
|
93
94
|
var data = '';
|
|
94
95
|
var yamldoc = null;
|
|
@@ -104,39 +105,39 @@ function splitsParserFromFileFactory() {
|
|
|
104
105
|
return {};
|
|
105
106
|
}
|
|
106
107
|
// Each entry will be mapped to a condition, but we'll also keep the configurations map.
|
|
107
|
-
var mocksData = (yamldoc).reduce(function (accum,
|
|
108
|
-
var
|
|
109
|
-
if (!
|
|
108
|
+
var mocksData = (yamldoc).reduce(function (accum, featureFlagEntry) {
|
|
109
|
+
var featureFlagName = Object.keys(featureFlagEntry)[0];
|
|
110
|
+
if (!featureFlagName || !(0, lang_1.isString)(featureFlagEntry[featureFlagName].treatment))
|
|
110
111
|
log.error(logPrefix + 'Ignoring entry on YAML since the format is incorrect.');
|
|
111
|
-
var mockData =
|
|
112
|
-
// "Template" for each
|
|
113
|
-
if (!accum[
|
|
114
|
-
accum[
|
|
112
|
+
var mockData = featureFlagEntry[featureFlagName];
|
|
113
|
+
// "Template" for each feature flag accumulated data
|
|
114
|
+
if (!accum[featureFlagName]) {
|
|
115
|
+
accum[featureFlagName] = {
|
|
115
116
|
configurations: {}, conditions: [], treatments: [], trafficTypeName: 'localhost'
|
|
116
117
|
};
|
|
117
118
|
}
|
|
118
119
|
// Assign the config if there is one on the mock
|
|
119
120
|
if (mockData.config)
|
|
120
|
-
accum[
|
|
121
|
+
accum[featureFlagName].configurations[mockData.treatment] = mockData.config;
|
|
121
122
|
// Parse the condition from the entry.
|
|
122
123
|
var condition = (0, parseCondition_1.parseCondition)(mockData);
|
|
123
|
-
accum[
|
|
124
|
+
accum[featureFlagName].conditions[condition.conditionType === 'ROLLOUT' ? 'push' : 'unshift'](condition);
|
|
124
125
|
// Also keep track of the treatments, will be useful for manager functionality.
|
|
125
|
-
accum[
|
|
126
|
+
accum[featureFlagName].treatments.push(mockData.treatment);
|
|
126
127
|
return accum;
|
|
127
128
|
}, {});
|
|
128
129
|
arrangeConditions(mocksData);
|
|
129
130
|
return mocksData;
|
|
130
131
|
}
|
|
131
132
|
// Load the content of a configuration file into an Object
|
|
132
|
-
return function
|
|
133
|
+
return function featureFlagsParserFromFile(_a) {
|
|
133
134
|
var features = _a.features, log = _a.log;
|
|
134
135
|
var filePath = configFilesPath(features);
|
|
135
136
|
var mockData;
|
|
136
137
|
// If we have a filePath, it means the extension is correct, choose the parser.
|
|
137
138
|
if ((0, lang_1.endsWith)(filePath, '.split')) {
|
|
138
139
|
log.warn(logPrefix + '.split mocks will be deprecated soon in favor of YAML files, which provide more targeting power. Take a look in our documentation.');
|
|
139
|
-
mockData =
|
|
140
|
+
mockData = readFeatureFlagConfigFile(log, filePath);
|
|
140
141
|
}
|
|
141
142
|
else {
|
|
142
143
|
mockData = readYAMLConfigFile(log, filePath);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@splitsoftware/splitio",
|
|
3
|
-
"version": "10.22.
|
|
3
|
+
"version": "10.22.5-rc.0",
|
|
4
4
|
"description": "Split SDK",
|
|
5
5
|
"files": [
|
|
6
6
|
"README.md",
|
|
@@ -27,6 +27,11 @@
|
|
|
27
27
|
"url": "https://github.com/NicoZelaya"
|
|
28
28
|
}
|
|
29
29
|
],
|
|
30
|
+
"keywords": [
|
|
31
|
+
"splitio",
|
|
32
|
+
"sdk",
|
|
33
|
+
"javascript"
|
|
34
|
+
],
|
|
30
35
|
"main": "lib/index.js",
|
|
31
36
|
"module": "es/index.js",
|
|
32
37
|
"types": "types",
|
|
@@ -35,7 +40,7 @@
|
|
|
35
40
|
"node": ">=6"
|
|
36
41
|
},
|
|
37
42
|
"dependencies": {
|
|
38
|
-
"@splitsoftware/splitio-commons": "1.
|
|
43
|
+
"@splitsoftware/splitio-commons": "1.8.2-rc.2",
|
|
39
44
|
"@types/google.analytics": "0.0.40",
|
|
40
45
|
"@types/ioredis": "^4.28.0",
|
|
41
46
|
"bloom-filters": "^3.0.0",
|
package/src/index.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
Copyright 2022 Split Software
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
**/
|
|
16
|
-
|
|
17
1
|
export { SplitFactory } from './factory';
|