Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
178 commits
Select commit Hold shift + click to select a range
c59423c
removed SplitErrors, and handling user callback errors in another way
EmilianoSanchez Apr 24, 2021
2d6e83a
wrapper adapter impl and tests
EmilianoSanchez Apr 26, 2021
7c63777
update
EmilianoSanchez Apr 26, 2021
111d53c
fixed test
EmilianoSanchez Apr 26, 2021
e5cd837
splits pluggable storage implementation and tests
EmilianoSanchez Apr 26, 2021
2c7f89a
polishing
EmilianoSanchez Apr 28, 2021
7447709
added remaining wrapper methods
EmilianoSanchez Apr 28, 2021
395d312
implementation and unit tests
EmilianoSanchez Apr 28, 2021
5cee3ba
applied Emi's feedback
EmilianoSanchez Apr 28, 2021
e487f86
implementation and unit tests
EmilianoSanchez Apr 28, 2021
160944e
applied feedback
EmilianoSanchez Apr 29, 2021
6c46d94
Merge pull request #22 from splitio/pluggable_storage_impressions_and…
EmilianoSanchez Apr 29, 2021
ee05fe5
Merge pull request #20 from splitio/pluggable_storage_splits_cache
EmilianoSanchez Apr 29, 2021
337cb1d
Merge branch 'pluggable_storage_wrapper_adapter' into pluggable_stora…
EmilianoSanchez Apr 29, 2021
05ccd7d
some fixes
EmilianoSanchez Apr 30, 2021
e002ede
Merge pull request #21 from splitio/pluggable_storage_segments_cache
EmilianoSanchez Apr 30, 2021
2261553
test fixes
EmilianoSanchez Apr 30, 2021
5273d10
test fixes
EmilianoSanchez Apr 30, 2021
927d505
removed sanitizer logic for a separete PR
EmilianoSanchez Apr 30, 2021
634d694
Merge pull request #19 from splitio/pluggable_storage_wrapper_adapter
EmilianoSanchez Apr 30, 2021
8ea1568
updated merge util types
EmilianoSanchez Apr 30, 2021
2ecca5f
Revert "updated merge util types"
EmilianoSanchez Apr 30, 2021
c2dfb19
storage factory with options validation
EmilianoSanchez Apr 30, 2021
b342cc4
refactors
EmilianoSanchez May 3, 2021
231f754
updated comment
EmilianoSanchez May 3, 2021
d51d10c
Merge branch 'pluggable_storage_metadata_polishing' into pluggable_st…
EmilianoSanchez May 4, 2021
11937d6
updated pluggable storage factory
EmilianoSanchez May 4, 2021
b71fc33
fixed sdkFactory signal listener
EmilianoSanchez May 4, 2021
493bbc1
separete updaters from sync tasks
EmilianoSanchez May 4, 2021
7ef9b78
refactor on updaters to support async splits and segments storages
EmilianoSanchez May 4, 2021
d4343fa
updated index
EmilianoSanchez May 4, 2021
d0b4520
Merge pull request #26 from splitio/pluggable_storage_metadata_polishing
EmilianoSanchez May 4, 2021
1e5cfe3
feedback
EmilianoSanchez May 4, 2021
bb69d09
Merge branch 'pluggable_storage_baseline' into pluggable_storage_sync…
EmilianoSanchez May 4, 2021
5f0e0d3
Merge pull request #27 from splitio/pluggable_storage_sync_tasks_refa…
EmilianoSanchez May 4, 2021
5f13e2b
Merge branch 'pluggable_storage_baseline' into pluggable_storage_upda…
EmilianoSanchez May 4, 2021
7068ab8
feedback
EmilianoSanchez May 4, 2021
3bdcd14
Merge branch 'pluggable_storage_updaters_async_support' into pluggabl…
EmilianoSanchez May 4, 2021
4c4e88c
updates to integrate with JS-client
EmilianoSanchez May 4, 2021
a8e9fae
updates
EmilianoSanchez May 4, 2021
b5d2b01
Merge pull request #28 from splitio/pluggable_storage_updaters_async_…
EmilianoSanchez May 4, 2021
d260365
Merge branch 'pluggable_storage_baseline' into pluggable_storage_conf…
EmilianoSanchez May 4, 2021
ffba1bd
some updates
EmilianoSanchez May 5, 2021
b796fa4
updated version for rc
EmilianoSanchez May 5, 2021
ed6bc04
added unit tests
EmilianoSanchez May 5, 2021
cdd9213
emi's feedback
EmilianoSanchez May 5, 2021
a68f2dc
nico's feedback
EmilianoSanchez May 6, 2021
7590d3f
Merge pull request #25 from splitio/pluggable_storage_config_validator
EmilianoSanchez May 6, 2021
83f92ef
implementation and unit test
EmilianoSanchez May 6, 2021
e7e2b3b
handling onReadyCb in InMemory storage server-side
EmilianoSanchez May 10, 2021
534b1d2
Merge branch 'development' into pluggable_storage_baseline
EmilianoSanchez May 10, 2021
2105906
Merge branch 'pluggable_storage_baseline' into pluggable_storage_onre…
EmilianoSanchez May 10, 2021
a5880b0
added comment and prepare for rc
EmilianoSanchez May 10, 2021
33d9b81
updated connect callback and wrapper method
EmilianoSanchez May 10, 2021
1c442b8
rollback name
EmilianoSanchez May 10, 2021
0e840d9
updated some comments
EmilianoSanchez May 10, 2021
561f47f
fixed ut
EmilianoSanchez May 10, 2021
4dd75c8
rename variable for readability
EmilianoSanchez May 10, 2021
e8617d9
Merge pull request #29 from splitio/pluggable_storage_onready_callback
EmilianoSanchez May 10, 2021
deee311
fixed producer methods of splits storage inredis and pluggable. added…
EmilianoSanchez May 11, 2021
8d7ca18
polishing
EmilianoSanchez May 12, 2021
d9397d7
polishing
EmilianoSanchez May 12, 2021
f443d5f
implementation based on registerSegments key approach
EmilianoSanchez May 12, 2021
9bc62b2
added missing entry in README list of SDKs
EmilianoSanchez May 12, 2021
f8ef708
Merge pull request #31 from splitio/pluggable_storage_splits_producer…
EmilianoSanchez May 12, 2021
eb9a554
Merge branch 'pluggable_storage_baseline' into pluggable_storage_segm…
EmilianoSanchez May 12, 2021
f5ac008
fixed issue with user cb errors
EmilianoSanchez May 13, 2021
de33734
implementation and some interface updates
EmilianoSanchez May 14, 2021
552a9d7
updated UTs
EmilianoSanchez May 14, 2021
400c21e
feedback
EmilianoSanchez May 14, 2021
64a85eb
Merge pull request #33 from splitio/pluggable_storage_segments_produc…
EmilianoSanchez May 14, 2021
0ab4843
Merge branch 'pluggable_storage_baseline' into pluggable_storage_impr…
EmilianoSanchez May 14, 2021
ddee304
updated UTs
EmilianoSanchez May 14, 2021
3af5fe2
fix issue with a test
EmilianoSanchez May 14, 2021
9f6c372
prepare rc
EmilianoSanchez May 14, 2021
daf2cae
Merge pull request #34 from splitio/pluggable_storage_impressions_pro…
EmilianoSanchez May 14, 2021
83b22a2
updated redis dependency, and fixed validateTrafficTypeExistance
EmilianoSanchez May 17, 2021
a57d9f2
updated manager to handle errors on pluggable storage calls
EmilianoSanchez May 18, 2021
bd6bc26
added inMemoryWrapper
EmilianoSanchez May 18, 2021
c5b718c
Merge branch 'development' into update_error_handling_part2
EmilianoSanchez May 19, 2021
01d88e0
Merge branch 'pluggable_storage_polishing' into update_error_handling…
EmilianoSanchez May 19, 2021
59a14d9
updated comments
EmilianoSanchez May 19, 2021
d166b0a
polishing
EmilianoSanchez May 19, 2021
90c02fe
typescript polishing
EmilianoSanchez May 19, 2021
dea583c
Merge pull request #35 from splitio/pluggable_storage_polishing
EmilianoSanchez May 19, 2021
47cc02a
Merge branch 'pluggable_storage_baseline' into update_error_handling_…
EmilianoSanchez May 19, 2021
a1dbf7d
polishing
EmilianoSanchez May 20, 2021
ca2edee
prepare rc
EmilianoSanchez May 20, 2021
a373239
Merge pull request #37 from splitio/update_error_handling_part2
EmilianoSanchez May 20, 2021
5891263
extended splitApi to let overwrite default headers for LW synchronizer
EmilianoSanchez May 20, 2021
9775771
rc
EmilianoSanchez May 26, 2021
9529b8d
updated types
EmilianoSanchez May 26, 2021
9812a71
updated types
EmilianoSanchez May 26, 2021
ad526d3
some fixes and updates for server-side
EmilianoSanchez May 31, 2021
623d045
comment update
EmilianoSanchez May 31, 2021
715c6f8
fixed issue with syncTask factory
EmilianoSanchez May 31, 2021
59d0a25
Emi's feedback
EmilianoSanchez Jun 9, 2021
5dc9f74
polish test
EmilianoSanchez Jun 9, 2021
cb6069d
Merge pull request #38 from splitio/pluggable_storage_polishing
EmilianoSanchez Jun 9, 2021
5201d30
sse metadata implementation
EmilianoSanchez Jun 10, 2021
4331cc7
sse close on unload browser event implementation
EmilianoSanchez Jun 10, 2021
eaa83a1
Merge pull request #40 from splitio/SDKS-2797-close-sse-connection-on…
EmilianoSanchez Jun 18, 2021
326b22c
Merge pull request #39 from splitio/SDKS-2655-sse-headers
EmilianoSanchez Jun 18, 2021
a020190
fix: fixed segments updater to resolve properly
EmilianoSanchez Jun 18, 2021
a3ecfec
Merge pull request #41 from splitio/segments_updater_fix
EmilianoSanchez Jun 28, 2021
ab4066c
feat: added APIs health check to SplitAPI service
emilianofant-split Jun 29, 2021
abcc416
chore: changed version for canary release
emilianofant-split Jun 30, 2021
7f08d55
refactor: changed API check function's name
emilianofant-split Jul 1, 2021
1dec42d
Merge pull request #42 from splitio/efant_addSplitApis_Healthcheck
EmilianoSanchez Jul 1, 2021
a49f58c
refactor: renamed splitApi endpoint for consistency
EmilianoSanchez Jul 1, 2021
cb35954
updated SSEClient to use addEventListener
EmilianoSanchez Jul 1, 2021
8140144
signal listener is responsible of starting the sync manager
EmilianoSanchez Jul 1, 2021
f8319a1
support pausing/resuming the sync manager
EmilianoSanchez Jul 1, 2021
d52b437
rc
EmilianoSanchez Jul 5, 2021
032bcab
revert commit 8140144
EmilianoSanchez Jul 6, 2021
b1a05a9
polishing in syncManager
EmilianoSanchez Jul 6, 2021
a29a78b
ignore pushManager start call if streaming is disabled
EmilianoSanchez Jul 8, 2021
2f6a1a8
polishing
EmilianoSanchez Jul 8, 2021
296aff4
rc
EmilianoSanchez Jul 8, 2021
72c1c06
polishing
EmilianoSanchez Jul 16, 2021
5fa7347
Merge pull request #43 from splitio/SDKS_2777_refactors_for_reactnati…
EmilianoSanchez Jul 16, 2021
fd82270
more refactors for RN
EmilianoSanchez Jul 16, 2021
5d65143
updated tests
EmilianoSanchez Jul 16, 2021
3b7a99e
fix: avoiding warning 'Error parsing SSE message notification' for ke…
EmilianoSanchez Jul 21, 2021
514671c
chore: comments polishing
EmilianoSanchez Jul 23, 2021
5b05841
bug fix
EmilianoSanchez Jul 27, 2021
91c1266
fixed some vulnerabilities
EmilianoSanchez Jul 27, 2021
173769d
Merge pull request #45 from splitio/SDKS_2777_refactors_for_reactnati…
EmilianoSanchez Aug 2, 2021
a258429
promise wrapper update to support runtimes where Promise.prototype.th…
EmilianoSanchez Aug 2, 2021
c0d8aa9
fixed log message for HTTP errors
EmilianoSanchez Aug 6, 2021
ece6657
chore: comments polishing
EmilianoSanchez Aug 9, 2021
e8f800b
Merge pull request #46 from splitio/promise_wrapper_update
EmilianoSanchez Aug 9, 2021
35a2ed9
remove TT values from storage when reaching to 0
EmilianoSanchez Aug 11, 2021
845d011
added UTs asserts
EmilianoSanchez Aug 11, 2021
cbd2cb2
fixed UT
EmilianoSanchez Aug 11, 2021
e729301
removed unused getByPrefix method
EmilianoSanchez Aug 11, 2021
92cba9d
prepare rc
EmilianoSanchez Aug 11, 2021
925bfa1
Merge pull request #47 from splitio/pluggable_storage_polishing
EmilianoSanchez Sep 1, 2021
3d60d40
migrations of localhost mode updates
EmilianoSanchez Sep 1, 2021
048b58e
updated redis test to reduce test flakiness
EmilianoSanchez Sep 1, 2021
2e0d0cf
implementation and tests
EmilianoSanchez Sep 8, 2021
7ca1c07
Merge pull request #48 from splitio/localhost_mode_updates
EmilianoSanchez Sep 8, 2021
6af7766
Nico's feedback
EmilianoSanchez Sep 16, 2021
d6f4227
More Nico's feedback
EmilianoSanchez Sep 16, 2021
78e45c5
added missed UT
EmilianoSanchez Sep 16, 2021
a56ebe7
Merge pull request #49 from splitio/streaming_v2_updates
EmilianoSanchez Sep 16, 2021
bd499ed
localhost with SDK_READY_FROM_CACHE
EmilianoSanchez Sep 17, 2021
5ec5ca2
STREAMING_RESET update
EmilianoSanchez Sep 21, 2021
84d627b
60 secs as default connDelay
EmilianoSanchez Sep 27, 2021
51cd16a
Fix typescript compiler errors related to const enum usage in RN
EmilianoSanchez Oct 1, 2021
f578d4d
performance improvements
EmilianoSanchez Oct 1, 2021
43be8e2
renamed a few vars for consistency with js sdk
EmilianoSanchez Oct 1, 2021
823aeed
Merge pull request #52 from splitio/streaming_v2_polishing
EmilianoSanchez Oct 1, 2021
b58c20c
Merge pull request #51 from splitio/localhost_with_ready_from_cache
EmilianoSanchez Oct 1, 2021
fb47f20
comment polishing
EmilianoSanchez Oct 6, 2021
d8a6118
Merge pull request #53 from splitio/polishing
EmilianoSanchez Oct 6, 2021
3a92d96
update rc version
EmilianoSanchez Oct 6, 2021
8056192
localhost mode with localstorage
EmilianoSanchez Oct 7, 2021
45398e7
added localhost module validator, used in the slim entry point of JS …
EmilianoSanchez Oct 7, 2021
3516320
updated test mocks
EmilianoSanchez Oct 7, 2021
5a52680
vulnerability fixes
EmilianoSanchez Oct 7, 2021
c4a999a
Merge branch 'localhost_with_ready_from_cache' into localhost_module_…
EmilianoSanchez Oct 7, 2021
c7f8e30
tests fixed
EmilianoSanchez Oct 7, 2021
805896c
Merge branch 'localhost_with_ready_from_cache' into localhost_module_…
EmilianoSanchez Oct 7, 2021
069c590
review
EmilianoSanchez Oct 13, 2021
8230e89
polishing on some export default
EmilianoSanchez Oct 14, 2021
34a15f4
Merge pull request #54 from splitio/localhost_with_ready_from_cache
EmilianoSanchez Oct 14, 2021
427f56c
validator update
EmilianoSanchez Oct 14, 2021
60741a3
polish comment
EmilianoSanchez Oct 14, 2021
9addabc
polishing
EmilianoSanchez Oct 14, 2021
0285a62
Merge branch 'development' into pluggable_storage_baseline
EmilianoSanchez Oct 14, 2021
d6d8f87
Merge branch 'pluggable_storage_baseline' into localhost_module_for_s…
EmilianoSanchez Oct 14, 2021
8a1d5ec
more polishing
EmilianoSanchez Oct 14, 2021
a37a8cb
polishing and tests
EmilianoSanchez Oct 14, 2021
5717c08
Merge pull request #55 from splitio/localhost_module_for_slim_entrypoint
EmilianoSanchez Oct 14, 2021
96c1e54
Merge branch 'pluggable_storage_baseline' into localhost_module_polis…
EmilianoSanchez Oct 14, 2021
54e97fa
updated readme
EmilianoSanchez Oct 18, 2021
890174c
Merge pull request #56 from splitio/localhost_module_polishing
EmilianoSanchez Oct 18, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

"globals": {
// global TS types
"Response": "readonly",
"EventSource": "readonly", // @TODO remove. Configure as a type declaration
"MessageEvent": "readonly", // @TODO remove. Configure as a type declaration
"Event": "readonly", // @TODO remove. Configure as a type declaration
Expand Down Expand Up @@ -66,7 +65,21 @@
"plugin:compat/recommended"
],
"rules": {
"no-restricted-syntax": ["error", "ForOfStatement", "ForInStatement", "ArrayPattern"],
"no-restricted-syntax": [
"error",
{
"selector": "ForOfStatement",
"message": "Avoid for-of syntax in favor of a smaller transpiled code"
},
{
"selector": "ForInStatement",
"message": "Don't use for-in syntax in libraries, because it iterates over members inherited from the prototype chain"
},
{
"selector": "TSEnumDeclaration[const=true]",
"message": "Don't declare const enum, because it is not supported by Babel used for building RN SDK"
}
],
"compat/compat": ["error", "defaults, not ie < 10, not node < 6"],
"no-throw-literal": "error"
},
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ To learn more about Split, contact hello@split.io, or get started with feature f

Split has built and maintains SDKs for:

* .NET [Github](https://github.com/splitio/.net-core-client) [Docs](https://help.split.io/hc/en-us/articles/360020240172--NET-SDK)
* .NET [Github](https://github.com/splitio/dotnet-client) [Docs](https://help.split.io/hc/en-us/articles/360020240172--NET-SDK)
* Android [Github](https://github.com/splitio/android-client) [Docs](https://help.split.io/hc/en-us/articles/360020343291-Android-SDK)
* GO [Github](https://github.com/splitio/go-client) [Docs](https://help.split.io/hc/en-us/articles/360020093652-Go-SDK)
* iOS [Github](https://github.com/splitio/ios-client) [Docs](https://help.split.io/hc/en-us/articles/360020401491-iOS-SDK)
* Java [Github](https://github.com/splitio/java-client) [Docs](https://help.split.io/hc/en-us/articles/360020405151-Java-SDK)
* Javascript [Github](https://github.com/splitio/javascript-client) [Docs](https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK)
* Node [Github](https://github.com/splitio/javascript-client) [Docs](https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK)
* Javascript for Browser [Github](https://github.com/splitio/javascript-browser-client) [Docs](https://help.split.io/hc/en-us/articles/360058730852)
* PHP [Github](https://github.com/splitio/php-client) [Docs](https://help.split.io/hc/en-us/articles/360020350372-PHP-SDK)
* Python [Github](https://github.com/splitio/python-client) [Docs](https://help.split.io/hc/en-us/articles/360020359652-Python-SDK)
* React [Github](https://github.com/splitio/react-client) [Docs](https://help.split.io/hc/en-us/articles/360038825091-React-SDK)
* React Native [Github](https://github.com/splitio/react-native-client) [Docs](https://help.split.io/hc/en-us/articles/4406066357901-React-Native-SDK)
* Redux [Github](https://github.com/splitio/redux-client) [Docs](https://help.split.io/hc/en-us/articles/360038851551-Redux-SDK)
* Ruby [Github](https://github.com/splitio/ruby-client) [Docs](https://help.split.io/hc/en-us/articles/360020673251-Ruby-SDK)

Expand Down
8,310 changes: 2,609 additions & 5,701 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@splitsoftware/splitio-commons",
"version": "0.1.0",
"version": "0.1.1-rc.20",
"description": "Split Javascript SDK common components",
"main": "cjs/index.js",
"module": "esm/index.js",
Expand Down Expand Up @@ -50,26 +50,26 @@
"devDependencies": {
"@types/google.analytics": "0.0.40",
"@types/ioredis": "^4.14.1",
"@types/jest": "^26.0.10",
"@types/jest": "^27.0.0",
"@types/lodash": "^4.14.162",
"@types/node": "^14.14.7",
"@types/object-assign": "^4.0.30",
"@typescript-eslint/eslint-plugin": "^4.2.0",
"@typescript-eslint/parser": "^4.2.0",
"cross-env": "^7.0.2",
"csv-streamify": "^4.0.0",
"eslint": "^7.9.0",
"eslint": "^7.32.0",
"eslint-plugin-compat": "3.7.0",
"fetch-mock": "^9.10.7",
"ioredis": "4.18.0",
"jest": "^26.6.3",
"ioredis": "^4.26.0",
"jest": "^27.2.3",
"jest-localstorage-mock": "^2.4.3",
"js-yaml": "^3.14.0",
"lodash": "^4.17.20",
"lodash": "^4.17.21",
"node-fetch": "^2.6.1",
"redis-server": "1.2.2",
"rimraf": "^3.0.2",
"ts-jest": "^26.3.0",
"ts-jest": "^27.0.5",
"typescript": "^4.0.2"
},
"sideEffects": false
Expand Down
4 changes: 4 additions & 0 deletions src/__tests__/mocks/message.STREAMING_RESET.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "message",
"data": "{\"timestamp\":1457552660000,\"data\":\"{\\\"type\\\":\\\"CONTROL\\\",\\\"controlType\\\":\\\"STREAMING_RESET\\\"}\"}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "message",
"data": "{\"data\":\"{\\\"type\\\":\\\"MY_SEGMENTS_UPDATE_V2\\\",\\\"changeNumber\\\":1457552651000,\\\"segmentName\\\":\\\"\\\",\\\"c\\\": 1,\\\"u\\\": 1,\\\"d\\\":\\\"H4sIAAAAAAAA/2JABxzYeIxQLguYFIBLN8Bl4EABjc+EzOnAsA4QAAD//8YBvWeAAAAA\\\"}\"}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "message",
"data": "{\"data\":\"{\\\"type\\\":\\\"MY_SEGMENTS_UPDATE_V2\\\",\\\"changeNumber\\\":1457552652000,\\\"segmentName\\\":\\\"splitters\\\",\\\"c\\\": 1,\\\"u\\\": 2,\\\"d\\\":\\\"H4sIAAAAAAAA/wTAsRHDUAgD0F2ofwEIkPAqPhdZIW0uu/v97GPXHU004ULuMGrYR6XUbIjlXULPPse+dt1yhJibBODjrTmj3GJ4emduuDDP/w0AAP//18WLsl0AAAA=\\\"}\"}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "message",
"data": "{\"data\":\"{\\\"type\\\":\\\"MY_SEGMENTS_UPDATE_V2\\\",\\\"changeNumber\\\":1457552653000,\\\"segmentName\\\":\\\"splitters\\\",\\\"c\\\": 0,\\\"u\\\": 3,\\\"d\\\":\\\"\\\"}\"}"
}
4 changes: 4 additions & 0 deletions src/__tests__/mocks/message.V2.UNBOUNDED.1457552650000.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "message",
"data": "{\"data\":\"{\\\"type\\\":\\\"MY_SEGMENTS_UPDATE_V2\\\",\\\"changeNumber\\\":1457552650000,\\\"segmentName\\\":\\\"\\\",\\\"c\\\": 0,\\\"u\\\": 0,\\\"d\\\":\\\"\\\"}\"}"
}
30 changes: 18 additions & 12 deletions src/__tests__/testUtils/eventSourceMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export default class EventSource {
static readonly CLOSED: ReadyStateType = 2;

private readonly __emitter: IEventEmitter;
onerror?: (evt: MessageEvent) => any;;
private readonly __eventSourceInitDict: EventSourceInitDict;
onerror?: (evt: MessageEvent) => any;
onmessage?: (evt: MessageEvent) => any;
onopen?: (evt?: MessageEvent) => any;
readyState: ReadyStateType;
Expand All @@ -56,13 +57,14 @@ export default class EventSource {

constructor(
url: string,
configuration: EventSourceInitDict = defaultOptions
eventSourceInitDict: EventSourceInitDict = defaultOptions
) {
this.url = url;
this.withCredentials = configuration.withCredentials;
this.withCredentials = eventSourceInitDict.withCredentials;
this.readyState = 0;
// @ts-ignore
this.__emitter = new EventEmitter();
this.__eventSourceInitDict = arguments[1];
sources[url] = this;
if (__listener) setTimeout(__listener, 0, this);
}
Expand All @@ -81,24 +83,28 @@ export default class EventSource {

emit(eventName: string, messageEvent?: MessageEvent) {
this.__emitter.emit(eventName, messageEvent);

let listener: ((evt: any) => any) | undefined;
switch (eventName) {
case 'error': listener = this.onerror; break;
case 'open': listener = this.onopen; break;
case 'message': listener = this.onmessage; break;
}
if (typeof listener === 'function') {
listener(messageEvent);
}
}

emitError(error: MessageEvent) {
if (typeof this.onerror === 'function') {
this.onerror(error);
}
this.emit('error', error);
}

emitOpen() {
this.readyState = 1;
if (typeof this.onopen === 'function') {
this.onopen();
}
this.emit('open');
}

emitMessage(message: MessageEvent) {
if (typeof this.onmessage === 'function') {
this.onmessage(message);
}
this.emit('message', message);
}
}
17 changes: 7 additions & 10 deletions src/dtos/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,15 @@ export interface IMySegmentsResponse {
mySegments: IMySegmentsResponseItem[]
}

/** Metadata internal types */
/** Metadata internal type for storages */

export interface IMetadata {
version: string // SDK version
ip: string | false // host IP
hostname: string | false // host name
}

export interface IRedisMetadata {
s: string // SDK version
i: string // host IP
n: string // host name
/** SDK version */
s: string
/** host IP */
i: string
/** host name */
n: string
}

export type ISplitFiltersValidation = {
Expand Down
37 changes: 23 additions & 14 deletions src/evaluator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ const treatmentException = {
config: null
};

function treatmentsException(splitNames: string[]) {
const evaluations: Record<string, IEvaluationResult> = {};
splitNames.forEach(splitName => {
evaluations[splitName] = treatmentException;
});
return evaluations;
}

export function evaluateFeature(
log: ILogger,
key: SplitIO.SplitKey,
Expand All @@ -27,10 +35,8 @@ export function evaluateFeature(
try {
stringifiedSplit = storage.splits.getSplit(splitName);
} catch (e) {
// the only scenario where getSplit can throw an error is when the storage
// is redis and there is a connection issue and we can't retrieve the split
// to be evaluated
return Promise.resolve(treatmentException);
// Exception on sync `getSplit` storage. Not possible ATM with InMemory and InLocal storages.
return treatmentException;
}

if (thenable(stringifiedSplit)) {
Expand All @@ -40,7 +46,11 @@ export function evaluateFeature(
key,
attributes,
storage,
));
)).catch(
// Exception on async `getSplit` storage. For example, when the storage is redis or
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
() => treatmentException
);
}

return getEvaluation(
Expand All @@ -60,22 +70,21 @@ export function evaluateFeatures(
storage: IStorageSync | IStorageAsync,
): MaybeThenable<Record<string, IEvaluationResult>> {
let stringifiedSplits;
const evaluations: Record<string, IEvaluationResult> = {};

try {
stringifiedSplits = storage.splits.getSplits(splitNames);
} catch (e) {
// the only scenario where `getSplits` can throw an error is when the storage
// is redis and there is a connection issue and we can't retrieve the split
// to be evaluated
splitNames.forEach(splitName => {
evaluations[splitName] = treatmentException;
});
return Promise.resolve(evaluations);
// Exception on sync `getSplits` storage. Not possible ATM with InMemory and InLocal storages.
return treatmentsException(splitNames);
}

return (thenable(stringifiedSplits)) ?
stringifiedSplits.then(splits => getEvaluations(log, splitNames, splits, key, attributes, storage)) :
stringifiedSplits.then(splits => getEvaluations(log, splitNames, splits, key, attributes, storage))
.catch(() => {
// Exception on async `getSplits` storage. For example, when the storage is redis or
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
return treatmentsException(splitNames);
}) :
getEvaluations(log, splitNames, stringifiedSplits, key, attributes, storage);
}

Expand Down
4 changes: 2 additions & 2 deletions src/evaluator/matchers/matcherTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const matcherTypes: Record<string, number> = {
MATCHES_STRING: 17
};

export const dataTypes = {
export const matcherDataTypes = {
BOOLEAN: 'BOOLEAN',
STRING: 'STRING',
NUMBER: 'NUMBER',
Expand All @@ -28,7 +28,7 @@ export const dataTypes = {
NOT_SPECIFIED: 'NOT_SPECIFIED'
};

export function mapper(matcherType: string) {
export function matcherTypesMapper(matcherType: string) {
const type = matcherTypes[matcherType];
if (type) return type;
else return matcherTypes.UNDEFINED;
Expand Down
24 changes: 12 additions & 12 deletions src/evaluator/matchersTransform/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { findIndex } from '../../utils/lang';
import { matcherTypes, mapper, dataTypes } from '../matchers/matcherTypes';
import { matcherTypes, matcherTypesMapper, matcherDataTypes } from '../matchers/matcherTypes';
import segmentTransform from './segment';
import whitelistTransform from './whitelist';
import setTransform from './set';
Expand Down Expand Up @@ -28,9 +28,9 @@ export default function matchersTransform(matchers: ISplitMatcher[]): IMatcherDt
} = matcher;

let attribute = keySelector && keySelector.attribute;
let type = mapper(matcherType);
let type = matcherTypesMapper(matcherType);
// As default input data type we use string (even for ALL_KEYS)
let dataType = dataTypes.STRING;
let dataType = matcherDataTypes.STRING;
let value = undefined;

if (type === matcherTypes.IN_SEGMENT) {
Expand All @@ -39,29 +39,29 @@ export default function matchersTransform(matchers: ISplitMatcher[]): IMatcherDt
value = whitelistTransform(whitelistObject as IWhitelistMatcherData);
} else if (type === matcherTypes.EQUAL_TO) {
value = numericTransform(unaryNumericObject as IUnaryNumericMatcherData);
dataType = dataTypes.NUMBER;
dataType = matcherDataTypes.NUMBER;

if ((unaryNumericObject as IUnaryNumericMatcherData).dataType === 'DATETIME') {
value = zeroSinceHH(value);
dataType = dataTypes.DATETIME;
dataType = matcherDataTypes.DATETIME;
}
} else if (type === matcherTypes.GREATER_THAN_OR_EQUAL_TO ||
type === matcherTypes.LESS_THAN_OR_EQUAL_TO) {
value = numericTransform(unaryNumericObject as IUnaryNumericMatcherData);
dataType = dataTypes.NUMBER;
dataType = matcherDataTypes.NUMBER;

if ((unaryNumericObject as IUnaryNumericMatcherData).dataType === 'DATETIME') {
value = zeroSinceSS(value);
dataType = dataTypes.DATETIME;
dataType = matcherDataTypes.DATETIME;
}
} else if (type === matcherTypes.BETWEEN) {
value = betweenObject as IBetweenMatcherData;
dataType = dataTypes.NUMBER;
dataType = matcherDataTypes.NUMBER;

if (value.dataType === 'DATETIME') {
value.start = zeroSinceSS(value.start);
value.end = zeroSinceSS(value.end);
dataType = dataTypes.DATETIME;
dataType = matcherDataTypes.DATETIME;
}
} else if (
type === matcherTypes.EQUAL_TO_SET ||
Expand All @@ -70,7 +70,7 @@ export default function matchersTransform(matchers: ISplitMatcher[]): IMatcherDt
type === matcherTypes.PART_OF_SET
) {
value = setTransform(whitelistObject as IWhitelistMatcherData);
dataType = dataTypes.SET;
dataType = matcherDataTypes.SET;
} else if (
type === matcherTypes.STARTS_WITH ||
type === matcherTypes.ENDS_WITH ||
Expand All @@ -79,9 +79,9 @@ export default function matchersTransform(matchers: ISplitMatcher[]): IMatcherDt
value = setTransform(whitelistObject as IWhitelistMatcherData);
} else if (type === matcherTypes.IN_SPLIT_TREATMENT) {
value = dependencyObject;
dataType = dataTypes.NOT_SPECIFIED;
dataType = matcherDataTypes.NOT_SPECIFIED;
} else if (type === matcherTypes.EQUAL_TO_BOOLEAN) {
dataType = dataTypes.BOOLEAN;
dataType = matcherDataTypes.BOOLEAN;
value = booleanMatcherData;
} else if (type === matcherTypes.MATCHES_STRING) {
value = stringMatcherData;
Expand Down
Loading