@splitsoftware/splitio 10.17.2 → 10.17.3-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/es/factory/clientSide.js +45 -0
- package/es/factory/commons.js +16 -0
- package/es/factory/package.json +4 -0
- package/es/factory/serverSide.js +42 -0
- package/es/index.js +1 -132
- package/es/platform/browser.js +11 -0
- package/es/{services → platform}/getEventSource/browser.js +1 -1
- package/es/{services → platform}/getEventSource/node.js +1 -1
- package/es/{client → platform/getEventSource}/package.json +0 -0
- package/es/{services → platform}/getFetch/browser.js +1 -1
- package/es/{services → platform}/getFetch/node.js +1 -1
- package/es/{impressions/observer → platform/getFetch}/package.json +0 -0
- package/es/platform/node.js +13 -0
- package/es/{integrations → platform}/package.json +0 -0
- package/es/{services → platform}/request/options/node.js +2 -2
- package/es/settings/clientSide.js +18 -0
- package/{lib/utils → es}/settings/defaults/browser.js +6 -8
- package/{src/utils → es}/settings/defaults/node.js +6 -3
- package/es/settings/defaults/version.js +1 -0
- package/es/settings/integrations/browser.js +5 -0
- package/es/settings/integrations/node.js +5 -0
- package/es/settings/package.json +4 -0
- package/es/{utils/settings → settings}/runtime/node.js +6 -4
- package/es/settings/serverSide.js +20 -0
- package/es/{utils/settings → settings}/storage/browser.js +12 -14
- package/es/{utils/settings → settings}/storage/node.js +10 -9
- package/es/umd.js +2 -1
- package/lib/factory/clientSide.js +65 -0
- package/lib/factory/commons.js +23 -0
- package/lib/factory/package.json +4 -0
- package/lib/factory/serverSide.js +60 -0
- package/lib/index.js +3 -151
- package/lib/platform/browser.js +24 -0
- package/lib/{services → platform}/getEventSource/browser.js +1 -1
- package/lib/{services → platform}/getEventSource/node.js +1 -1
- package/{es/listeners → lib/platform/getEventSource}/package.json +0 -0
- package/lib/{services → platform}/getFetch/browser.js +1 -1
- package/lib/{services → platform}/getFetch/node.js +1 -1
- package/{es/producer/offline → lib/platform/getFetch}/package.json +0 -0
- package/lib/platform/node.js +27 -0
- package/{es/producer → lib/platform}/package.json +0 -0
- package/lib/{services → platform}/request/options/node.js +2 -2
- package/lib/settings/clientSide.js +30 -0
- package/{src/utils → lib}/settings/defaults/browser.js +13 -3
- package/{es/utils → lib}/settings/defaults/node.js +13 -3
- package/lib/settings/defaults/version.js +6 -0
- package/lib/settings/integrations/browser.js +14 -0
- package/lib/settings/integrations/node.js +12 -0
- package/lib/settings/package.json +4 -0
- package/lib/{utils/settings → settings}/runtime/node.js +7 -5
- package/lib/settings/serverSide.js +33 -0
- package/lib/{utils/settings → settings}/storage/browser.js +15 -20
- package/lib/{utils/settings → settings}/storage/node.js +13 -11
- package/lib/umd.js +1 -0
- package/package.json +15 -12
- package/src/.DS_Store +0 -0
- package/src/factory/clientSide.js +58 -0
- package/src/factory/commons.js +16 -0
- package/src/factory/package.json +4 -0
- package/src/factory/serverSide.js +51 -0
- package/src/index.js +1 -140
- package/src/{sync/SSEHandler → platform}/.DS_Store +0 -0
- package/src/platform/browser.js +13 -0
- package/src/{services → platform}/getEventSource/browser.js +2 -2
- package/src/{services → platform}/getEventSource/node.js +2 -2
- package/{es/services → src/platform}/getEventSource/package.json +0 -0
- package/src/{services → platform}/getFetch/browser.js +2 -2
- package/src/{services → platform}/getFetch/node.js +1 -1
- package/{es/services → src/platform}/getFetch/package.json +0 -0
- package/src/platform/node.js +15 -0
- package/{es/services/request/options → src/platform}/package.json +0 -0
- package/src/{services → platform}/request/options/node.js +2 -2
- package/src/{listeners → settings}/.DS_Store +0 -0
- package/src/settings/clientSide.js +18 -0
- package/{es/utils → src}/settings/defaults/browser.js +8 -3
- package/{lib/utils → src}/settings/defaults/node.js +6 -6
- package/src/settings/defaults/version.js +1 -0
- package/src/settings/integrations/browser.js +6 -0
- package/src/{utils/settings → settings}/integrations/node.js +1 -3
- package/src/settings/package.json +4 -0
- package/src/{utils/settings → settings}/runtime/node.js +9 -6
- package/src/settings/serverSide.js +20 -0
- package/src/{utils/settings → settings}/storage/browser.js +10 -16
- package/src/{utils/settings → settings}/storage/node.js +7 -7
- package/src/umd.js +1 -0
- package/es/client/attributesDecoration.js +0 -116
- package/es/client/browser.js +0 -39
- package/es/client/client.js +0 -155
- package/es/client/inputValidation.js +0 -117
- package/es/client/node.js +0 -6
- package/es/engine/combiners/and.js +0 -54
- package/es/engine/combiners/ifelseif.js +0 -73
- package/es/engine/condition/index.js +0 -62
- package/es/engine/convertions/index.js +0 -29
- package/es/engine/engine/index.js +0 -60
- package/es/engine/engine/legacy.js +0 -77
- package/es/engine/engine/murmur3/common.js +0 -40
- package/es/engine/engine/murmur3/murmur3.js +0 -83
- package/es/engine/engine/murmur3/murmur3_128.js +0 -250
- package/es/engine/engine/murmur3/murmur3_128_x86.js +0 -183
- package/es/engine/engine/murmur3/murmur3_64.js +0 -52
- package/es/engine/engine/murmur3/utfx.js +0 -112
- package/es/engine/evaluator/index.js +0 -111
- package/es/engine/index.js +0 -112
- package/es/engine/matchers/all.js +0 -32
- package/es/engine/matchers/between.js +0 -35
- package/es/engine/matchers/boolean.js +0 -35
- package/es/engine/matchers/cont_all.js +0 -51
- package/es/engine/matchers/cont_any.js +0 -47
- package/es/engine/matchers/cont_str.js +0 -38
- package/es/engine/matchers/dependency.js +0 -50
- package/es/engine/matchers/eq.js +0 -35
- package/es/engine/matchers/eq_set.js +0 -49
- package/es/engine/matchers/ew.js +0 -38
- package/es/engine/matchers/gte.js +0 -35
- package/es/engine/matchers/index.js +0 -65
- package/es/engine/matchers/lte.js +0 -35
- package/es/engine/matchers/part_of.js +0 -49
- package/es/engine/matchers/segment.js +0 -39
- package/es/engine/matchers/string.js +0 -44
- package/es/engine/matchers/sw.js +0 -38
- package/es/engine/matchers/types.js +0 -48
- package/es/engine/matchers/whitelist.js +0 -36
- package/es/engine/parser/index.js +0 -69
- package/es/engine/parser/segments.js +0 -22
- package/es/engine/transforms/matcherGroup.js +0 -43
- package/es/engine/transforms/matchers.js +0 -109
- package/es/engine/transforms/segment.js +0 -28
- package/es/engine/transforms/set.js +0 -20
- package/es/engine/transforms/unaryNumeric.js +0 -20
- package/es/engine/transforms/whitelist.js +0 -22
- package/es/engine/treatments/index.js +0 -67
- package/es/engine/value/index.js +0 -54
- package/es/engine/value/sanitize.js +0 -125
- package/es/events/index.js +0 -65
- package/es/factory/offline.js +0 -50
- package/es/factory/online.js +0 -113
- package/es/impressions/counter.js +0 -52
- package/es/impressions/hasher/buildKey.js +0 -3
- package/es/impressions/hasher/hashImpression128.js +0 -5
- package/es/impressions/hasher/hashImpression32.js +0 -5
- package/es/impressions/observer/browser.js +0 -9
- package/es/impressions/observer/node.js +0 -9
- package/es/impressions/observer/observer.js +0 -21
- package/es/integrations/browser.js +0 -62
- package/es/integrations/ga/GaToSplit.js +0 -246
- package/es/integrations/ga/SplitToGa.js +0 -127
- package/es/integrations/node.js +0 -3
- package/es/listeners/browser.js +0 -157
- package/es/listeners/node.js +0 -65
- package/es/manager/index.js +0 -104
- package/es/metrics/Collectors.js +0 -100
- package/es/metrics/index.js +0 -157
- package/es/producer/browser/Partial.js +0 -103
- package/es/producer/browser.js +0 -70
- package/es/producer/fetcher/MySegments.js +0 -47
- package/es/producer/fetcher/SegmentChanges.js +0 -52
- package/es/producer/fetcher/SplitChanges.js +0 -46
- package/es/producer/node.js +0 -130
- package/es/producer/offline/browser.js +0 -26
- package/es/producer/offline/node.js +0 -26
- package/es/producer/task.js +0 -50
- package/es/producer/updater/MySegments.js +0 -108
- package/es/producer/updater/SegmentChanges.js +0 -135
- package/es/producer/updater/SplitChanges.js +0 -131
- package/es/producer/updater/SplitChangesFromFeatures.js +0 -21
- package/es/producer/updater/SplitChangesFromFileSystem.js +0 -21
- package/es/producer/updater/SplitChangesFromObject.js +0 -73
- package/es/readiness/index.js +0 -123
- package/es/readiness/statusManager.js +0 -114
- package/es/services/auth/auth.js +0 -25
- package/es/services/auth/index.js +0 -2
- package/es/services/events/bulk.js +0 -22
- package/es/services/events/index.js +0 -17
- package/es/services/impressions/bulk.js +0 -26
- package/es/services/impressions/count.js +0 -7
- package/es/services/impressions/dto.js +0 -73
- package/es/services/impressions/index.js +0 -17
- package/es/services/impressions/post.js +0 -22
- package/es/services/metrics/counters.js +0 -24
- package/es/services/metrics/dto.js +0 -38
- package/es/services/metrics/index.js +0 -17
- package/es/services/metrics/times.js +0 -24
- package/es/services/mySegments/get.js +0 -26
- package/es/services/mySegments/index.js +0 -17
- package/es/services/request/index.js +0 -43
- package/es/services/request/options/browser.js +0 -18
- package/es/services/segmentChanges/get.js +0 -21
- package/es/services/segmentChanges/index.js +0 -17
- package/es/services/splitChanges/get.js +0 -19
- package/es/services/splitChanges/index.js +0 -17
- package/es/services/splitChanges/offline/browser.js +0 -63
- package/es/services/splitChanges/offline/node.js +0 -176
- package/es/services/splitChanges/offline/package.json +0 -4
- package/es/services/splitChanges/offline/parseCondition.js +0 -43
- package/es/services/transport/index.js +0 -51
- package/es/storage/AttributesCache/InMemory.js +0 -85
- package/es/storage/BaseMetricsAsyncCache.js +0 -23
- package/es/storage/CountCache/InMemory.js +0 -48
- package/es/storage/CountCache/InRedis.js +0 -42
- package/es/storage/EventsCache/InMemory.js +0 -109
- package/es/storage/EventsCache/InRedis.js +0 -65
- package/es/storage/ImpressionsCache/InMemory.js +0 -71
- package/es/storage/ImpressionsCache/InRedis.js +0 -73
- package/es/storage/Keys.js +0 -125
- package/es/storage/KeysLocalStorage.js +0 -47
- package/es/storage/LatencyCache/InMemory.js +0 -56
- package/es/storage/LatencyCache/InRedis.js +0 -44
- package/es/storage/LatencyCache/findIndex.js +0 -2
- package/es/storage/Meta.js +0 -7
- package/es/storage/RedisAdapter.js +0 -198
- package/es/storage/SegmentCache/InLocalStorage/index.js +0 -138
- package/es/storage/SegmentCache/InMemory/browser.js +0 -107
- package/es/storage/SegmentCache/InMemory/node.js +0 -82
- package/es/storage/SegmentCache/InMemory/package.json +0 -4
- package/es/storage/SegmentCache/InRedis/index.js +0 -81
- package/es/storage/SplitCache/InLocalStorage.js +0 -332
- package/es/storage/SplitCache/InMemory.js +0 -162
- package/es/storage/SplitCache/InRedis.js +0 -214
- package/es/storage/SplitCache/killLocally.js +0 -35
- package/es/storage/browser.js +0 -101
- package/es/storage/node.js +0 -81
- package/es/storage/package.json +0 -4
- package/es/sync/AuthClient/index.js +0 -34
- package/es/sync/PushManager/index.js +0 -315
- package/es/sync/PushManager/mySegmentsV2utils.js +0 -76
- package/es/sync/PushManager/pushRequirements/browser.js +0 -23
- package/es/sync/PushManager/pushRequirements/node.js +0 -18
- package/es/sync/PushManager/pushRequirements/package.json +0 -4
- package/es/sync/SSEClient/index.js +0 -93
- package/es/sync/SSEHandler/NotificationKeeper.js +0 -97
- package/es/sync/SSEHandler/NotificationParser.js +0 -31
- package/es/sync/SSEHandler/index.js +0 -110
- package/es/sync/SegmentUpdateWorker/browser.js +0 -74
- package/es/sync/SegmentUpdateWorker/node.js +0 -79
- package/es/sync/SegmentUpdateWorker/package.json +0 -4
- package/es/sync/SplitUpdateWorker/index.js +0 -86
- package/es/sync/browser.js +0 -125
- package/es/sync/constants.js +0 -42
- package/es/sync/node.js +0 -60
- package/es/sync/package.json +0 -4
- package/es/trackers/event.js +0 -53
- package/es/trackers/impressions.js +0 -132
- package/es/utils/backoff/index.js +0 -51
- package/es/utils/base64/browser.js +0 -19
- package/es/utils/base64/node.js +0 -19
- package/es/utils/base64/package.json +0 -4
- package/es/utils/binarySearch/index.js +0 -50
- package/es/utils/constants/index.js +0 -38
- package/es/utils/context/constants.js +0 -30
- package/es/utils/context/index.js +0 -101
- package/es/utils/decompress/index.js +0 -476
- package/es/utils/fn/repeat.js +0 -58
- package/es/utils/inputValidation/apiKey.js +0 -39
- package/es/utils/inputValidation/attribute.js +0 -22
- package/es/utils/inputValidation/attributes.js +0 -19
- package/es/utils/inputValidation/event.js +0 -23
- package/es/utils/inputValidation/eventProperties.js +0 -69
- package/es/utils/inputValidation/eventValue.js +0 -9
- package/es/utils/inputValidation/index.js +0 -11
- package/es/utils/inputValidation/isOperational.js +0 -14
- package/es/utils/inputValidation/key.js +0 -50
- package/es/utils/inputValidation/split.js +0 -47
- package/es/utils/inputValidation/splitFilters.js +0 -121
- package/es/utils/inputValidation/splits.js +0 -27
- package/es/utils/inputValidation/trafficType.js +0 -55
- package/es/utils/jwt/hashUserKey.js +0 -11
- package/es/utils/jwt/index.js +0 -14
- package/es/utils/key/factory.js +0 -38
- package/es/utils/key/parser.js +0 -34
- package/es/utils/labels/index.js +0 -7
- package/es/utils/lang/Errors.js +0 -41
- package/es/utils/lang/Sets.js +0 -114
- package/es/utils/lang/index.js +0 -305
- package/es/utils/localstorage/isAvailable.js +0 -26
- package/es/utils/logger/LoggerFactory.js +0 -86
- package/es/utils/logger/index.js +0 -97
- package/es/utils/lrucache/linkedlist.js +0 -122
- package/es/utils/lrucache/lru.spec.js +0 -24
- package/es/utils/lrucache/lrucache.js +0 -80
- package/es/utils/now/browser.js +0 -27
- package/es/utils/now/node.js +0 -19
- package/es/utils/now/package.json +0 -4
- package/es/utils/promise/thenable.js +0 -3
- package/es/utils/promise/timeout.js +0 -34
- package/es/utils/promise/wrapper.js +0 -58
- package/es/utils/settings/defaults/package.json +0 -4
- package/es/utils/settings/impressionsMode.js +0 -16
- package/es/utils/settings/index.js +0 -194
- package/es/utils/settings/integrations/browser.js +0 -8
- package/es/utils/settings/integrations/common.js +0 -30
- package/es/utils/settings/integrations/node.js +0 -7
- package/es/utils/settings/integrations/package.json +0 -4
- package/es/utils/settings/language/browser.js +0 -16
- package/es/utils/settings/language/node.js +0 -16
- package/es/utils/settings/language/package.json +0 -4
- package/es/utils/settings/mode.js +0 -10
- package/es/utils/settings/runtime/browser.js +0 -21
- package/es/utils/settings/runtime/package.json +0 -4
- package/es/utils/settings/storage/package.json +0 -4
- package/es/utils/splits/usesSegments.js +0 -21
- package/es/utils/time/index.js +0 -8
- package/es/utils/timeTracker/index.js +0 -216
- package/es/utils/timeTracker/timer.js +0 -25
- package/lib/client/attributesDecoration.js +0 -128
- package/lib/client/browser.js +0 -50
- package/lib/client/client.js +0 -174
- package/lib/client/inputValidation.js +0 -129
- package/lib/client/node.js +0 -14
- package/lib/client/package.json +0 -4
- package/lib/engine/combiners/and.js +0 -65
- package/lib/engine/combiners/ifelseif.js +0 -88
- package/lib/engine/condition/index.js +0 -76
- package/lib/engine/convertions/index.js +0 -36
- package/lib/engine/engine/index.js +0 -71
- package/lib/engine/engine/legacy.js +0 -83
- package/lib/engine/engine/murmur3/common.js +0 -52
- package/lib/engine/engine/murmur3/murmur3.js +0 -90
- package/lib/engine/engine/murmur3/murmur3_128.js +0 -256
- package/lib/engine/engine/murmur3/murmur3_128_x86.js +0 -189
- package/lib/engine/engine/murmur3/murmur3_64.js +0 -57
- package/lib/engine/engine/murmur3/utfx.js +0 -121
- package/lib/engine/evaluator/index.js +0 -129
- package/lib/engine/index.js +0 -128
- package/lib/engine/matchers/all.js +0 -41
- package/lib/engine/matchers/between.js +0 -44
- package/lib/engine/matchers/boolean.js +0 -44
- package/lib/engine/matchers/cont_all.js +0 -61
- package/lib/engine/matchers/cont_any.js +0 -57
- package/lib/engine/matchers/cont_str.js +0 -48
- package/lib/engine/matchers/dependency.js +0 -60
- package/lib/engine/matchers/eq.js +0 -44
- package/lib/engine/matchers/eq_set.js +0 -59
- package/lib/engine/matchers/ew.js +0 -48
- package/lib/engine/matchers/gte.js +0 -44
- package/lib/engine/matchers/index.js +0 -90
- package/lib/engine/matchers/lte.js +0 -44
- package/lib/engine/matchers/part_of.js +0 -59
- package/lib/engine/matchers/segment.js +0 -49
- package/lib/engine/matchers/string.js +0 -53
- package/lib/engine/matchers/sw.js +0 -48
- package/lib/engine/matchers/types.js +0 -57
- package/lib/engine/matchers/whitelist.js +0 -46
- package/lib/engine/parser/index.js +0 -84
- package/lib/engine/parser/segments.js +0 -28
- package/lib/engine/transforms/matcherGroup.js +0 -54
- package/lib/engine/transforms/matchers.js +0 -124
- package/lib/engine/transforms/segment.js +0 -34
- package/lib/engine/transforms/set.js +0 -26
- package/lib/engine/transforms/unaryNumeric.js +0 -26
- package/lib/engine/transforms/whitelist.js +0 -28
- package/lib/engine/treatments/index.js +0 -73
- package/lib/engine/value/index.js +0 -64
- package/lib/engine/value/sanitize.js +0 -137
- package/lib/events/index.js +0 -80
- package/lib/factory/offline.js +0 -62
- package/lib/factory/online.js +0 -129
- package/lib/impressions/counter.js +0 -61
- package/lib/impressions/hasher/buildKey.js +0 -8
- package/lib/impressions/hasher/hashImpression128.js +0 -12
- package/lib/impressions/hasher/hashImpression32.js +0 -14
- package/lib/impressions/observer/browser.js +0 -19
- package/lib/impressions/observer/node.js +0 -19
- package/lib/impressions/observer/observer.js +0 -29
- package/lib/impressions/observer/package.json +0 -4
- package/lib/integrations/browser.js +0 -72
- package/lib/integrations/ga/GaToSplit.js +0 -267
- package/lib/integrations/ga/SplitToGa.js +0 -138
- package/lib/integrations/node.js +0 -9
- package/lib/integrations/package.json +0 -4
- package/lib/listeners/browser.js +0 -173
- package/lib/listeners/node.js +0 -74
- package/lib/listeners/package.json +0 -4
- package/lib/manager/index.js +0 -115
- package/lib/metrics/Collectors.js +0 -118
- package/lib/metrics/index.js +0 -182
- package/lib/producer/browser/Partial.js +0 -114
- package/lib/producer/browser.js +0 -82
- package/lib/producer/fetcher/MySegments.js +0 -59
- package/lib/producer/fetcher/SegmentChanges.js +0 -62
- package/lib/producer/fetcher/SplitChanges.js +0 -58
- package/lib/producer/node.js +0 -142
- package/lib/producer/offline/browser.js +0 -35
- package/lib/producer/offline/node.js +0 -35
- package/lib/producer/offline/package.json +0 -4
- package/lib/producer/package.json +0 -4
- package/lib/producer/task.js +0 -61
- package/lib/producer/updater/MySegments.js +0 -119
- package/lib/producer/updater/SegmentChanges.js +0 -148
- package/lib/producer/updater/SplitChanges.js +0 -145
- package/lib/producer/updater/SplitChangesFromFeatures.js +0 -30
- package/lib/producer/updater/SplitChangesFromFileSystem.js +0 -30
- package/lib/producer/updater/SplitChangesFromObject.js +0 -84
- package/lib/readiness/index.js +0 -132
- package/lib/readiness/statusManager.js +0 -124
- package/lib/services/auth/auth.js +0 -32
- package/lib/services/auth/index.js +0 -11
- package/lib/services/events/bulk.js +0 -31
- package/lib/services/events/index.js +0 -26
- package/lib/services/getEventSource/package.json +0 -4
- package/lib/services/getFetch/package.json +0 -4
- package/lib/services/impressions/bulk.js +0 -36
- package/lib/services/impressions/count.js +0 -16
- package/lib/services/impressions/dto.js +0 -81
- package/lib/services/impressions/index.js +0 -26
- package/lib/services/impressions/post.js +0 -31
- package/lib/services/metrics/counters.js +0 -33
- package/lib/services/metrics/dto.js +0 -46
- package/lib/services/metrics/index.js +0 -26
- package/lib/services/metrics/times.js +0 -33
- package/lib/services/mySegments/get.js +0 -35
- package/lib/services/mySegments/index.js +0 -26
- package/lib/services/request/index.js +0 -53
- package/lib/services/request/options/browser.js +0 -23
- package/lib/services/request/options/package.json +0 -4
- package/lib/services/segmentChanges/get.js +0 -29
- package/lib/services/segmentChanges/index.js +0 -26
- package/lib/services/splitChanges/get.js +0 -27
- package/lib/services/splitChanges/index.js +0 -26
- package/lib/services/splitChanges/offline/browser.js +0 -71
- package/lib/services/splitChanges/offline/node.js +0 -189
- package/lib/services/splitChanges/offline/package.json +0 -4
- package/lib/services/splitChanges/offline/parseCondition.js +0 -49
- package/lib/services/transport/index.js +0 -62
- package/lib/storage/AttributesCache/InMemory.js +0 -93
- package/lib/storage/BaseMetricsAsyncCache.js +0 -28
- package/lib/storage/CountCache/InMemory.js +0 -54
- package/lib/storage/CountCache/InRedis.js +0 -50
- package/lib/storage/EventsCache/InMemory.js +0 -118
- package/lib/storage/EventsCache/InRedis.js +0 -74
- package/lib/storage/ImpressionsCache/InMemory.js +0 -77
- package/lib/storage/ImpressionsCache/InRedis.js +0 -79
- package/lib/storage/Keys.js +0 -132
- package/lib/storage/KeysLocalStorage.js +0 -58
- package/lib/storage/LatencyCache/InMemory.js +0 -64
- package/lib/storage/LatencyCache/InRedis.js +0 -53
- package/lib/storage/LatencyCache/findIndex.js +0 -12
- package/lib/storage/Meta.js +0 -12
- package/lib/storage/RedisAdapter.js +0 -212
- package/lib/storage/SegmentCache/InLocalStorage/index.js +0 -147
- package/lib/storage/SegmentCache/InMemory/browser.js +0 -113
- package/lib/storage/SegmentCache/InMemory/node.js +0 -89
- package/lib/storage/SegmentCache/InMemory/package.json +0 -4
- package/lib/storage/SegmentCache/InRedis/index.js +0 -87
- package/lib/storage/SplitCache/InLocalStorage.js +0 -344
- package/lib/storage/SplitCache/InMemory.js +0 -172
- package/lib/storage/SplitCache/InRedis.js +0 -224
- package/lib/storage/SplitCache/killLocally.js +0 -42
- package/lib/storage/browser.js +0 -122
- package/lib/storage/node.js +0 -104
- package/lib/storage/package.json +0 -4
- package/lib/sync/AuthClient/index.js +0 -44
- package/lib/sync/PushManager/index.js +0 -340
- package/lib/sync/PushManager/mySegmentsV2utils.js +0 -87
- package/lib/sync/PushManager/pushRequirements/browser.js +0 -30
- package/lib/sync/PushManager/pushRequirements/node.js +0 -25
- package/lib/sync/PushManager/pushRequirements/package.json +0 -4
- package/lib/sync/SSEClient/index.js +0 -101
- package/lib/sync/SSEHandler/NotificationKeeper.js +0 -104
- package/lib/sync/SSEHandler/NotificationParser.js +0 -39
- package/lib/sync/SSEHandler/index.js +0 -121
- package/lib/sync/SegmentUpdateWorker/browser.js +0 -81
- package/lib/sync/SegmentUpdateWorker/node.js +0 -86
- package/lib/sync/SegmentUpdateWorker/package.json +0 -4
- package/lib/sync/SplitUpdateWorker/index.js +0 -93
- package/lib/sync/browser.js +0 -139
- package/lib/sync/constants.js +0 -59
- package/lib/sync/node.js +0 -71
- package/lib/sync/package.json +0 -4
- package/lib/trackers/event.js +0 -64
- package/lib/trackers/impressions.js +0 -146
- package/lib/utils/backoff/index.js +0 -57
- package/lib/utils/base64/browser.js +0 -26
- package/lib/utils/base64/node.js +0 -26
- package/lib/utils/base64/package.json +0 -4
- package/lib/utils/binarySearch/index.js +0 -56
- package/lib/utils/constants/index.js +0 -60
- package/lib/utils/context/constants.js +0 -49
- package/lib/utils/context/index.js +0 -111
- package/lib/utils/decompress/index.js +0 -483
- package/lib/utils/fn/repeat.js +0 -64
- package/lib/utils/inputValidation/apiKey.js +0 -51
- package/lib/utils/inputValidation/attribute.js +0 -32
- package/lib/utils/inputValidation/attributes.js +0 -32
- package/lib/utils/inputValidation/event.js +0 -33
- package/lib/utils/inputValidation/eventProperties.js +0 -78
- package/lib/utils/inputValidation/eventValue.js +0 -19
- package/lib/utils/inputValidation/index.js +0 -48
- package/lib/utils/inputValidation/isOperational.js +0 -25
- package/lib/utils/inputValidation/key.js +0 -59
- package/lib/utils/inputValidation/split.js +0 -60
- package/lib/utils/inputValidation/splitFilters.js +0 -134
- package/lib/utils/inputValidation/splits.js +0 -38
- package/lib/utils/inputValidation/trafficType.js +0 -68
- package/lib/utils/jwt/hashUserKey.js +0 -19
- package/lib/utils/jwt/index.js +0 -19
- package/lib/utils/key/factory.js +0 -46
- package/lib/utils/key/parser.js +0 -42
- package/lib/utils/labels/index.js +0 -18
- package/lib/utils/lang/Errors.js +0 -58
- package/lib/utils/lang/Sets.js +0 -127
- package/lib/utils/lang/index.js +0 -350
- package/lib/utils/localstorage/isAvailable.js +0 -31
- package/lib/utils/logger/LoggerFactory.js +0 -98
- package/lib/utils/logger/index.js +0 -109
- package/lib/utils/lrucache/linkedlist.js +0 -132
- package/lib/utils/lrucache/lru.spec.js +0 -30
- package/lib/utils/lrucache/lrucache.js +0 -88
- package/lib/utils/now/browser.js +0 -33
- package/lib/utils/now/node.js +0 -24
- package/lib/utils/now/package.json +0 -4
- package/lib/utils/promise/thenable.js +0 -10
- package/lib/utils/promise/timeout.js +0 -40
- package/lib/utils/promise/wrapper.js +0 -63
- package/lib/utils/settings/defaults/package.json +0 -4
- package/lib/utils/settings/impressionsMode.js +0 -26
- package/lib/utils/settings/index.js +0 -214
- package/lib/utils/settings/integrations/browser.js +0 -17
- package/lib/utils/settings/integrations/common.js +0 -40
- package/lib/utils/settings/integrations/node.js +0 -13
- package/lib/utils/settings/integrations/package.json +0 -4
- package/lib/utils/settings/language/browser.js +0 -22
- package/lib/utils/settings/language/node.js +0 -22
- package/lib/utils/settings/language/package.json +0 -4
- package/lib/utils/settings/mode.js +0 -16
- package/lib/utils/settings/runtime/browser.js +0 -26
- package/lib/utils/settings/runtime/package.json +0 -4
- package/lib/utils/settings/storage/package.json +0 -4
- package/lib/utils/splits/usesSegments.js +0 -27
- package/lib/utils/time/index.js +0 -12
- package/lib/utils/timeTracker/index.js +0 -213
- package/lib/utils/timeTracker/timer.js +0 -33
- package/src/client/attributesDecoration.js +0 -112
- package/src/client/browser.js +0 -41
- package/src/client/client.js +0 -131
- package/src/client/inputValidation.js +0 -130
- package/src/client/node.js +0 -8
- package/src/client/package.json +0 -4
- package/src/engine/combiners/and.js +0 -55
- package/src/engine/combiners/ifelseif.js +0 -74
- package/src/engine/condition/index.js +0 -65
- package/src/engine/convertions/index.js +0 -22
- package/src/engine/engine/index.js +0 -63
- package/src/engine/engine/legacy.js +0 -66
- package/src/engine/engine/murmur3/common.js +0 -54
- package/src/engine/engine/murmur3/murmur3.js +0 -79
- package/src/engine/engine/murmur3/murmur3_128.js +0 -273
- package/src/engine/engine/murmur3/murmur3_128_x86.js +0 -188
- package/src/engine/engine/murmur3/murmur3_64.js +0 -34
- package/src/engine/engine/murmur3/utfx.js +0 -111
- package/src/engine/evaluator/index.js +0 -148
- package/src/engine/index.js +0 -123
- package/src/engine/matchers/all.js +0 -29
- package/src/engine/matchers/between.js +0 -30
- package/src/engine/matchers/boolean.js +0 -29
- package/src/engine/matchers/cont_all.js +0 -40
- package/src/engine/matchers/cont_any.js +0 -35
- package/src/engine/matchers/cont_str.js +0 -31
- package/src/engine/matchers/dependency.js +0 -52
- package/src/engine/matchers/eq.js +0 -30
- package/src/engine/matchers/eq_set.js +0 -37
- package/src/engine/matchers/ew.js +0 -31
- package/src/engine/matchers/gte.js +0 -30
- package/src/engine/matchers/index.js +0 -71
- package/src/engine/matchers/lte.js +0 -30
- package/src/engine/matchers/part_of.js +0 -37
- package/src/engine/matchers/segment.js +0 -41
- package/src/engine/matchers/string.js +0 -39
- package/src/engine/matchers/sw.js +0 -31
- package/src/engine/matchers/types.js +0 -52
- package/src/engine/matchers/whitelist.js +0 -30
- package/src/engine/parser/index.js +0 -79
- package/src/engine/parser/segments.js +0 -31
- package/src/engine/transforms/matcherGroup.js +0 -45
- package/src/engine/transforms/matchers.js +0 -118
- package/src/engine/transforms/segment.js +0 -23
- package/src/engine/transforms/set.js +0 -20
- package/src/engine/transforms/unaryNumeric.js +0 -20
- package/src/engine/transforms/whitelist.js +0 -22
- package/src/engine/treatments/index.js +0 -67
- package/src/engine/value/index.js +0 -53
- package/src/engine/value/sanitize.js +0 -117
- package/src/events/index.js +0 -62
- package/src/factory/offline.js +0 -60
- package/src/factory/online.js +0 -127
- package/src/impressions/counter.js +0 -43
- package/src/impressions/hasher/buildKey.js +0 -3
- package/src/impressions/hasher/hashImpression128.js +0 -6
- package/src/impressions/hasher/hashImpression32.js +0 -6
- package/src/impressions/observer/browser.js +0 -8
- package/src/impressions/observer/node.js +0 -8
- package/src/impressions/observer/observer.js +0 -17
- package/src/impressions/observer/package.json +0 -4
- package/src/integrations/browser.js +0 -57
- package/src/integrations/ga/GaToSplit.js +0 -278
- package/src/integrations/ga/SplitToGa.js +0 -125
- package/src/integrations/node.js +0 -4
- package/src/integrations/package.json +0 -4
- package/src/listeners/browser.js +0 -137
- package/src/listeners/node.js +0 -59
- package/src/listeners/package.json +0 -4
- package/src/manager/index.js +0 -103
- package/src/metrics/Collectors.js +0 -77
- package/src/metrics/index.js +0 -174
- package/src/producer/browser/Partial.js +0 -104
- package/src/producer/browser.js +0 -82
- package/src/producer/fetcher/MySegments.js +0 -40
- package/src/producer/fetcher/SegmentChanges.js +0 -52
- package/src/producer/fetcher/SplitChanges.js +0 -39
- package/src/producer/node.js +0 -142
- package/src/producer/offline/browser.js +0 -28
- package/src/producer/offline/node.js +0 -28
- package/src/producer/offline/package.json +0 -4
- package/src/producer/package.json +0 -4
- package/src/producer/task.js +0 -57
- package/src/producer/updater/MySegments.js +0 -104
- package/src/producer/updater/SegmentChanges.js +0 -126
- package/src/producer/updater/SplitChanges.js +0 -138
- package/src/producer/updater/SplitChangesFromFeatures.js +0 -23
- package/src/producer/updater/SplitChangesFromFileSystem.js +0 -23
- package/src/producer/updater/SplitChangesFromObject.js +0 -81
- package/src/readiness/index.js +0 -125
- package/src/readiness/statusManager.js +0 -121
- package/src/services/.DS_Store +0 -0
- package/src/services/auth/auth.js +0 -21
- package/src/services/auth/index.js +0 -3
- package/src/services/events/bulk.js +0 -23
- package/src/services/events/index.js +0 -18
- package/src/services/getEventSource/package.json +0 -4
- package/src/services/getFetch/package.json +0 -4
- package/src/services/impressions/bulk.js +0 -26
- package/src/services/impressions/count.js +0 -8
- package/src/services/impressions/dto.js +0 -71
- package/src/services/impressions/index.js +0 -18
- package/src/services/impressions/post.js +0 -23
- package/src/services/metrics/counters.js +0 -25
- package/src/services/metrics/dto.js +0 -44
- package/src/services/metrics/index.js +0 -18
- package/src/services/metrics/times.js +0 -25
- package/src/services/mySegments/get.js +0 -27
- package/src/services/mySegments/index.js +0 -18
- package/src/services/request/index.js +0 -43
- package/src/services/request/options/browser.js +0 -18
- package/src/services/request/options/package.json +0 -4
- package/src/services/segmentChanges/get.js +0 -20
- package/src/services/segmentChanges/index.js +0 -18
- package/src/services/splitChanges/get.js +0 -20
- package/src/services/splitChanges/index.js +0 -18
- package/src/services/splitChanges/offline/browser.js +0 -66
- package/src/services/splitChanges/offline/node.js +0 -190
- package/src/services/splitChanges/offline/package.json +0 -4
- package/src/services/splitChanges/offline/parseCondition.js +0 -52
- package/src/services/transport/index.js +0 -44
- package/src/storage/AttributesCache/InMemory.js +0 -76
- package/src/storage/BaseMetricsAsyncCache.js +0 -14
- package/src/storage/CountCache/InMemory.js +0 -48
- package/src/storage/CountCache/InRedis.js +0 -32
- package/src/storage/EventsCache/InMemory.js +0 -99
- package/src/storage/EventsCache/InRedis.js +0 -62
- package/src/storage/ImpressionsCache/InMemory.js +0 -62
- package/src/storage/ImpressionsCache/InRedis.js +0 -65
- package/src/storage/Keys.js +0 -122
- package/src/storage/KeysLocalStorage.js +0 -40
- package/src/storage/LatencyCache/InMemory.js +0 -56
- package/src/storage/LatencyCache/InRedis.js +0 -35
- package/src/storage/LatencyCache/findIndex.js +0 -7
- package/src/storage/Meta.js +0 -7
- package/src/storage/RedisAdapter.js +0 -170
- package/src/storage/SegmentCache/InLocalStorage/index.js +0 -120
- package/src/storage/SegmentCache/InMemory/browser.js +0 -99
- package/src/storage/SegmentCache/InMemory/node.js +0 -84
- package/src/storage/SegmentCache/InMemory/package.json +0 -4
- package/src/storage/SegmentCache/InRedis/index.js +0 -71
- package/src/storage/SplitCache/InLocalStorage.js +0 -324
- package/src/storage/SplitCache/InMemory.js +0 -145
- package/src/storage/SplitCache/InRedis.js +0 -187
- package/src/storage/SplitCache/killLocally.js +0 -33
- package/src/storage/browser.js +0 -110
- package/src/storage/node.js +0 -83
- package/src/storage/package.json +0 -4
- package/src/sync/.DS_Store +0 -0
- package/src/sync/AuthClient/index.js +0 -31
- package/src/sync/PushManager/index.js +0 -328
- package/src/sync/PushManager/mySegmentsV2utils.js +0 -76
- package/src/sync/PushManager/pushRequirements/browser.js +0 -20
- package/src/sync/PushManager/pushRequirements/node.js +0 -16
- package/src/sync/PushManager/pushRequirements/package.json +0 -4
- package/src/sync/SSEClient/index.js +0 -92
- package/src/sync/SSEHandler/NotificationKeeper.js +0 -90
- package/src/sync/SSEHandler/NotificationParser.js +0 -35
- package/src/sync/SSEHandler/index.js +0 -110
- package/src/sync/SegmentUpdateWorker/browser.js +0 -67
- package/src/sync/SegmentUpdateWorker/node.js +0 -73
- package/src/sync/SegmentUpdateWorker/package.json +0 -4
- package/src/sync/SplitUpdateWorker/index.js +0 -79
- package/src/sync/browser.js +0 -130
- package/src/sync/constants.js +0 -43
- package/src/sync/node.js +0 -66
- package/src/sync/package.json +0 -4
- package/src/trackers/event.js +0 -47
- package/src/trackers/impressions.js +0 -123
- package/src/utils/backoff/index.js +0 -46
- package/src/utils/base64/browser.js +0 -19
- package/src/utils/base64/node.js +0 -19
- package/src/utils/base64/package.json +0 -4
- package/src/utils/binarySearch/index.js +0 -50
- package/src/utils/constants/index.js +0 -41
- package/src/utils/context/constants.js +0 -18
- package/src/utils/context/index.js +0 -84
- package/src/utils/decompress/index.js +0 -428
- package/src/utils/fn/repeat.js +0 -48
- package/src/utils/inputValidation/apiKey.js +0 -42
- package/src/utils/inputValidation/attribute.js +0 -22
- package/src/utils/inputValidation/attributes.js +0 -26
- package/src/utils/inputValidation/event.js +0 -23
- package/src/utils/inputValidation/eventProperties.js +0 -65
- package/src/utils/inputValidation/eventValue.js +0 -11
- package/src/utils/inputValidation/index.js +0 -11
- package/src/utils/inputValidation/isOperational.js +0 -16
- package/src/utils/inputValidation/key.js +0 -53
- package/src/utils/inputValidation/split.js +0 -42
- package/src/utils/inputValidation/splitFilters.js +0 -108
- package/src/utils/inputValidation/splits.js +0 -21
- package/src/utils/inputValidation/trafficType.js +0 -58
- package/src/utils/jwt/hashUserKey.js +0 -11
- package/src/utils/jwt/index.js +0 -15
- package/src/utils/key/factory.js +0 -34
- package/src/utils/key/parser.js +0 -34
- package/src/utils/labels/index.js +0 -7
- package/src/utils/lang/Errors.js +0 -19
- package/src/utils/lang/Sets.js +0 -94
- package/src/utils/lang/index.js +0 -291
- package/src/utils/localstorage/isAvailable.js +0 -26
- package/src/utils/logger/LoggerFactory.js +0 -90
- package/src/utils/logger/index.js +0 -93
- package/src/utils/lrucache/linkedlist.js +0 -116
- package/src/utils/lrucache/lru.spec.js +0 -26
- package/src/utils/lrucache/lrucache.js +0 -49
- package/src/utils/now/browser.js +0 -29
- package/src/utils/now/node.js +0 -21
- package/src/utils/now/package.json +0 -4
- package/src/utils/promise/thenable.js +0 -1
- package/src/utils/promise/timeout.js +0 -38
- package/src/utils/promise/wrapper.js +0 -60
- package/src/utils/settings/defaults/package.json +0 -4
- package/src/utils/settings/impressionsMode.js +0 -15
- package/src/utils/settings/index.js +0 -217
- package/src/utils/settings/integrations/browser.js +0 -8
- package/src/utils/settings/integrations/common.js +0 -32
- package/src/utils/settings/integrations/package.json +0 -4
- package/src/utils/settings/language/browser.js +0 -17
- package/src/utils/settings/language/node.js +0 -17
- package/src/utils/settings/language/package.json +0 -4
- package/src/utils/settings/mode.js +0 -12
- package/src/utils/settings/runtime/browser.js +0 -22
- package/src/utils/settings/runtime/package.json +0 -4
- package/src/utils/settings/storage/package.json +0 -4
- package/src/utils/splits/usesSegments.js +0 -17
- package/src/utils/time/index.js +0 -8
- package/src/utils/timeTracker/index.js +0 -223
- package/src/utils/timeTracker/timer.js +0 -27
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'events';
|
|
2
|
-
import objectAssign from 'object-assign';
|
|
3
|
-
|
|
4
|
-
import authenticate from '../AuthClient';
|
|
5
|
-
import { checkPushRequirements } from './pushRequirements';
|
|
6
|
-
import SegmentUpdateWorker from '../SegmentUpdateWorker';
|
|
7
|
-
import SplitUpdateWorker from '../SplitUpdateWorker';
|
|
8
|
-
import SSEClient from '../SSEClient';
|
|
9
|
-
import SSEHandlerFactory from '../SSEHandler';
|
|
10
|
-
|
|
11
|
-
import Backoff from '../../utils/backoff';
|
|
12
|
-
import { hashUserKey } from '../../utils/jwt/hashUserKey';
|
|
13
|
-
import logFactory from '../../utils/logger';
|
|
14
|
-
import { SECONDS_BEFORE_EXPIRATION, PUSH_SUBSYSTEM_DOWN, PUSH_SUBSYSTEM_UP, PUSH_NONRETRYABLE_ERROR, PUSH_RETRYABLE_ERROR, SPLIT_KILL, SPLIT_UPDATE, SEGMENT_UPDATE, MY_SEGMENTS_UPDATE, MY_SEGMENTS_UPDATE_V2, ControlTypes } from '../constants';
|
|
15
|
-
import { parseBitmap, parseKeyList, isInBitmap } from './mySegmentsV2utils';
|
|
16
|
-
import { forOwn } from '../../utils/lang';
|
|
17
|
-
import { _Set } from '../../utils/lang/Sets';
|
|
18
|
-
import { hash64 } from '../../engine/engine/murmur3/murmur3_64';
|
|
19
|
-
|
|
20
|
-
const log = logFactory('splitio-sync:push-manager');
|
|
21
|
-
|
|
22
|
-
// const UnboundedFetchRequest = 0;
|
|
23
|
-
const BoundedFetchRequest = 1;
|
|
24
|
-
const KeyList = 2;
|
|
25
|
-
const SegmentRemoval = 3;
|
|
26
|
-
|
|
27
|
-
function fallbackWarning(notificationType, e) {
|
|
28
|
-
return `Fetching MySegments due to an error processing ${notificationType} notification: ${e}`;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Factory of the push mode manager.
|
|
33
|
-
*
|
|
34
|
-
* @param {Object} context context of main client.
|
|
35
|
-
* @param {Object | undefined} clientContexts map of user keys to client contexts to handle sync of MySegments. undefined for node.
|
|
36
|
-
*/
|
|
37
|
-
export default function PushManagerFactory(context, clientContexts /* undefined for node */) {
|
|
38
|
-
|
|
39
|
-
// No return a PushManager if PUSH mode is not supported.
|
|
40
|
-
if (!checkPushRequirements(log)) return;
|
|
41
|
-
|
|
42
|
-
const pushEmitter = new EventEmitter();
|
|
43
|
-
const { splits: splitsEventEmitter } = context.get(context.constants.READINESS);
|
|
44
|
-
const settings = context.get(context.constants.SETTINGS);
|
|
45
|
-
const storage = context.get(context.constants.STORAGE);
|
|
46
|
-
const sseClient = SSEClient.getInstance(settings, clientContexts ? false : true);
|
|
47
|
-
const sseHandler = SSEHandlerFactory(pushEmitter);
|
|
48
|
-
sseClient.setEventHandler(sseHandler);
|
|
49
|
-
|
|
50
|
-
// map of hashes to user keys, to dispatch MY_SEGMENTS_UPDATE events to the corresponding MySegmentsUpdateWorker
|
|
51
|
-
const userKeyHashes = {};
|
|
52
|
-
// map of user keys to their corresponding hash64 and MySegmentsUpdateWorker.
|
|
53
|
-
// Hash64 is used to process MY_SEGMENTS_UPDATE_V2 events and dispatch actions to the corresponding worker.
|
|
54
|
-
const clients = {};
|
|
55
|
-
|
|
56
|
-
// variable used on browser to reconnect only when a new client was added, saving some authentication and sse connections.
|
|
57
|
-
let connectForNewClient = false;
|
|
58
|
-
// flag that indicates if `disconnectPush` was called, either by the SyncManager (when the client is destroyed) or by a PUSH_NONRETRYABLE_ERROR error
|
|
59
|
-
let disconnected;
|
|
60
|
-
|
|
61
|
-
/** PushManager functions related to initialization */
|
|
62
|
-
|
|
63
|
-
const connectPushRetryBackoff = new Backoff(connectPush, settings.scheduler.pushRetryBackoffBase);
|
|
64
|
-
|
|
65
|
-
let timeoutIdTokenRefresh;
|
|
66
|
-
let timeoutIdSseOpen;
|
|
67
|
-
|
|
68
|
-
function scheduleTokenRefreshAndSse(authData) {
|
|
69
|
-
// clear scheduled tasks if exist
|
|
70
|
-
if (timeoutIdTokenRefresh) clearTimeout(timeoutIdTokenRefresh);
|
|
71
|
-
if (timeoutIdSseOpen) clearTimeout(timeoutIdSseOpen);
|
|
72
|
-
|
|
73
|
-
// Set token refresh 10 minutes before expirationTime - issuedAt
|
|
74
|
-
const decodedToken = authData.decodedToken;
|
|
75
|
-
const refreshTokenDelay = decodedToken.exp - decodedToken.iat - SECONDS_BEFORE_EXPIRATION;
|
|
76
|
-
// Default connDelay of 60 secs
|
|
77
|
-
const connDelay = typeof authData.connDelay === 'number' && authData.connDelay >= 0 ? authData.connDelay : 60;
|
|
78
|
-
|
|
79
|
-
log.info(`Refreshing streaming token in ${refreshTokenDelay} seconds, and connecting streaming in ${connDelay} seconds`);
|
|
80
|
-
|
|
81
|
-
timeoutIdTokenRefresh = setTimeout(connectPush, refreshTokenDelay * 1000);
|
|
82
|
-
|
|
83
|
-
timeoutIdSseOpen = setTimeout(() => {
|
|
84
|
-
// halt if disconnected
|
|
85
|
-
if (disconnected) return;
|
|
86
|
-
sseClient.open(authData);
|
|
87
|
-
}, connDelay * 1000);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function connectPush() {
|
|
91
|
-
// Halt connecting in case `stop/disconnectPush` has been called
|
|
92
|
-
if (disconnected) return;
|
|
93
|
-
log.info(`${disconnected === undefined ? 'Connecting' : 'Re-connecting'} to push streaming.`);
|
|
94
|
-
disconnected = false;
|
|
95
|
-
|
|
96
|
-
const userKeys = clientContexts ? Object.keys(clientContexts) : undefined;
|
|
97
|
-
authenticate(settings, userKeys).then(
|
|
98
|
-
function (authData) {
|
|
99
|
-
if (disconnected) return;
|
|
100
|
-
|
|
101
|
-
// 'pushEnabled: false' is handled as a PUSH_NONRETRYABLE_ERROR instead of PUSH_SUBSYSTEM_DOWN, in order to
|
|
102
|
-
// close the sseClient in case the org has been bloqued while the instance was connected to streaming
|
|
103
|
-
if (!authData.pushEnabled) {
|
|
104
|
-
log.info('Streaming is not available. Switching to polling mode.');
|
|
105
|
-
pushEmitter.emit(PUSH_NONRETRYABLE_ERROR);
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// don't open SSE connection if a new shared client was added, since it means that a new authentication is taking place
|
|
110
|
-
if (userKeys && userKeys.length < Object.keys(clientContexts).length) return;
|
|
111
|
-
|
|
112
|
-
// Schedule SSE connection and refresh token
|
|
113
|
-
scheduleTokenRefreshAndSse(authData);
|
|
114
|
-
}
|
|
115
|
-
).catch(
|
|
116
|
-
function (error) {
|
|
117
|
-
if (disconnected) return;
|
|
118
|
-
|
|
119
|
-
log.error(`Failed to authenticate for streaming. Error: ${error.message}.`);
|
|
120
|
-
|
|
121
|
-
// Handle 4XX HTTP errors: 401 (invalid API Key) or 400 (using incorrect API Key, i.e., client-side API Key on server-side)
|
|
122
|
-
if (error.statusCode >= 400 && error.statusCode < 500) {
|
|
123
|
-
pushEmitter.emit(PUSH_NONRETRYABLE_ERROR);
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// Handle other HTTP and network errors as recoverable errors
|
|
128
|
-
pushEmitter.emit(PUSH_RETRYABLE_ERROR);
|
|
129
|
-
}
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// close SSE connection and cancel scheduled tasks
|
|
134
|
-
function disconnectPush() {
|
|
135
|
-
// Halt disconnecting, just to avoid redundant logs if called multiple times
|
|
136
|
-
if (disconnected) return;
|
|
137
|
-
disconnected = true;
|
|
138
|
-
|
|
139
|
-
sseClient.close();
|
|
140
|
-
log.info('Disconnecting from push streaming.');
|
|
141
|
-
|
|
142
|
-
if (timeoutIdTokenRefresh) clearTimeout(timeoutIdTokenRefresh);
|
|
143
|
-
if (timeoutIdSseOpen) clearTimeout(timeoutIdSseOpen);
|
|
144
|
-
connectPushRetryBackoff.reset();
|
|
145
|
-
|
|
146
|
-
stopWorkers();
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
pushEmitter.on(PUSH_SUBSYSTEM_DOWN, stopWorkers);
|
|
150
|
-
|
|
151
|
-
// Only required when streaming connects after a PUSH_RETRYABLE_ERROR.
|
|
152
|
-
// Otherwise it is unnecessary (e.g, STREAMING_RESUMED).
|
|
153
|
-
pushEmitter.on(PUSH_SUBSYSTEM_UP, () => {
|
|
154
|
-
connectPushRetryBackoff.reset();
|
|
155
|
-
stopWorkers();
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
/** Fallbacking without retry due to STREAMING_DISABLED control event, 'pushEnabled: false', and non-recoverable SSE and Authentication errors */
|
|
159
|
-
|
|
160
|
-
pushEmitter.on(PUSH_NONRETRYABLE_ERROR, function handleNonRetryableError() {
|
|
161
|
-
// Note: `stopWorkers` is been called twice, but it is not harmful
|
|
162
|
-
disconnectPush();
|
|
163
|
-
pushEmitter.emit(PUSH_SUBSYSTEM_DOWN); // no harm if polling already
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
/** Fallbacking with retry due to recoverable SSE and Authentication errors */
|
|
167
|
-
|
|
168
|
-
pushEmitter.on(PUSH_RETRYABLE_ERROR, function handleRetryableError() { // HTTP or network error in SSE connection
|
|
169
|
-
// SSE connection is closed to avoid repeated errors due to retries
|
|
170
|
-
sseClient.close();
|
|
171
|
-
|
|
172
|
-
// retry streaming reconnect with backoff algorithm
|
|
173
|
-
let delayInMillis = connectPushRetryBackoff.scheduleCall();
|
|
174
|
-
|
|
175
|
-
log.info(`Attempting to reconnect in ${delayInMillis / 1000} seconds.`);
|
|
176
|
-
|
|
177
|
-
pushEmitter.emit(PUSH_SUBSYSTEM_DOWN); // no harm if polling already
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
/** STREAMING_RESET notification. Unlike a PUSH_RETRYABLE_ERROR, it doesn't emit PUSH_SUBSYSTEM_DOWN to fallback polling */
|
|
181
|
-
|
|
182
|
-
pushEmitter.on(ControlTypes.STREAMING_RESET, function handleStreamingReset() {
|
|
183
|
-
if (disconnected) return; // should never happen
|
|
184
|
-
|
|
185
|
-
// Minimum required clean-up.
|
|
186
|
-
// `disconnectPush` cannot be called because it sets `disconnected` and thus `connectPush` will not execute
|
|
187
|
-
if (timeoutIdTokenRefresh) clearTimeout(timeoutIdTokenRefresh);
|
|
188
|
-
|
|
189
|
-
connectPush();
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
/** Functions related to synchronization (Queues and Workers in the spec) */
|
|
193
|
-
|
|
194
|
-
const producer = context.get(context.constants.PRODUCER);
|
|
195
|
-
const splitUpdateWorker = new SplitUpdateWorker(storage.splits, producer, splitsEventEmitter);
|
|
196
|
-
let segmentUpdateWorker; // used in Node
|
|
197
|
-
|
|
198
|
-
// cancel scheduled fetch retries of Split, Segment, and MySegment Update Workers
|
|
199
|
-
function stopWorkers() {
|
|
200
|
-
splitUpdateWorker.backoff.reset();
|
|
201
|
-
if (segmentUpdateWorker) segmentUpdateWorker.backoff.reset();
|
|
202
|
-
forOwn(clients, ({ worker }) => worker.backoff.reset());
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
pushEmitter.on(SPLIT_KILL, splitUpdateWorker.killSplit);
|
|
206
|
-
pushEmitter.on(SPLIT_UPDATE, splitUpdateWorker.put);
|
|
207
|
-
|
|
208
|
-
if (clientContexts) { // browser
|
|
209
|
-
pushEmitter.on(MY_SEGMENTS_UPDATE, function handleMySegmentsUpdate(parsedData, channel) {
|
|
210
|
-
const userKeyHash = channel.split('_')[2];
|
|
211
|
-
const userKey = userKeyHashes[userKeyHash];
|
|
212
|
-
if (userKey && clientContexts[userKey]) { // check context since it can be undefined if client has been destroyed
|
|
213
|
-
const mySegmentSync = clientContexts[userKey].get(context.constants.MY_SEGMENTS_CHANGE_WORKER, true);
|
|
214
|
-
mySegmentSync && mySegmentSync.put(
|
|
215
|
-
parsedData.changeNumber,
|
|
216
|
-
parsedData.includesPayload ? parsedData.segmentList ? parsedData.segmentList : [] : undefined);
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
pushEmitter.on(MY_SEGMENTS_UPDATE_V2, function handleMySegmentsUpdate(parsedData) {
|
|
221
|
-
switch (parsedData.u) {
|
|
222
|
-
case BoundedFetchRequest: {
|
|
223
|
-
let bitmap;
|
|
224
|
-
try {
|
|
225
|
-
bitmap = parseBitmap(parsedData.d, parsedData.c);
|
|
226
|
-
} catch (e) {
|
|
227
|
-
log.warn(fallbackWarning('BoundedFetchRequest', e));
|
|
228
|
-
break;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
forOwn(clients, ({ hash64, worker }) => {
|
|
232
|
-
if (isInBitmap(bitmap, hash64.hex)) {
|
|
233
|
-
worker.put(parsedData.changeNumber); // fetch mySegments
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
case KeyList: {
|
|
239
|
-
let keyList, added, removed;
|
|
240
|
-
try {
|
|
241
|
-
keyList = parseKeyList(parsedData.d, parsedData.c);
|
|
242
|
-
added = new _Set(keyList.a);
|
|
243
|
-
removed = new _Set(keyList.r);
|
|
244
|
-
} catch (e) {
|
|
245
|
-
log.warn(fallbackWarning('KeyList', e));
|
|
246
|
-
break;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
forOwn(clients, ({ hash64, worker }) => {
|
|
250
|
-
const add = added.has(hash64.dec) ? true : removed.has(hash64.dec) ? false : undefined;
|
|
251
|
-
if (add !== undefined) {
|
|
252
|
-
worker.put(parsedData.changeNumber, {
|
|
253
|
-
name: parsedData.segmentName,
|
|
254
|
-
add
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
case SegmentRemoval:
|
|
261
|
-
if (!parsedData.segmentName) {
|
|
262
|
-
log.warn(fallbackWarning('SegmentRemoval', 'No segment name was provided'));
|
|
263
|
-
break;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
forOwn(clients, ({ worker }) => {
|
|
267
|
-
worker.put(parsedData.changeNumber, {
|
|
268
|
-
name: parsedData.segmentName,
|
|
269
|
-
add: false
|
|
270
|
-
});
|
|
271
|
-
});
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// `UpdateStrategy.UnboundedFetchRequest` and fallbacks of other cases
|
|
276
|
-
forOwn(clients, ({ worker }) => {
|
|
277
|
-
worker.put(parsedData.changeNumber);
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
} else { // node
|
|
282
|
-
segmentUpdateWorker = new SegmentUpdateWorker(storage.segments, producer);
|
|
283
|
-
pushEmitter.on(SEGMENT_UPDATE, segmentUpdateWorker.put);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
return objectAssign(
|
|
287
|
-
// Expose Event Emitter functionality and Event constants
|
|
288
|
-
Object.create(pushEmitter),
|
|
289
|
-
{
|
|
290
|
-
// Expose functionality for starting and stoping push mode:
|
|
291
|
-
stop: disconnectPush, // `handleNonRetryableError` cannot be used as `stop`, because it emits PUSH_SUBSYSTEM_DOWN event, which start polling.
|
|
292
|
-
|
|
293
|
-
// used in node
|
|
294
|
-
start: connectPush,
|
|
295
|
-
|
|
296
|
-
// used in browser
|
|
297
|
-
startNewClient(userKey, context) {
|
|
298
|
-
const hash = hashUserKey(userKey);
|
|
299
|
-
const storage = context.get(context.constants.STORAGE);
|
|
300
|
-
const producer = context.get(context.constants.PRODUCER);
|
|
301
|
-
|
|
302
|
-
if (!userKeyHashes[hash]) {
|
|
303
|
-
userKeyHashes[hash] = userKey;
|
|
304
|
-
connectForNewClient = true; // we must reconnect on start, to listen the channel for the new user key
|
|
305
|
-
}
|
|
306
|
-
const mySegmentSync = new SegmentUpdateWorker(storage.segments, producer);
|
|
307
|
-
clients[userKey] = { worker: mySegmentSync, hash64: hash64(userKey) };
|
|
308
|
-
context.put(context.constants.MY_SEGMENTS_CHANGE_WORKER, mySegmentSync);
|
|
309
|
-
|
|
310
|
-
// Reconnects in case of a new client.
|
|
311
|
-
// Run in next event-loop cycle to save authentication calls
|
|
312
|
-
// in case the user is creating several clients in the current cycle.
|
|
313
|
-
setTimeout(function checkForReconnect() {
|
|
314
|
-
if (connectForNewClient) {
|
|
315
|
-
connectForNewClient = false;
|
|
316
|
-
connectPush();
|
|
317
|
-
}
|
|
318
|
-
}, 0);
|
|
319
|
-
|
|
320
|
-
},
|
|
321
|
-
removeClient(userKey) {
|
|
322
|
-
const hash = hashUserKey(userKey);
|
|
323
|
-
delete userKeyHashes[hash];
|
|
324
|
-
delete clients[userKey];
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
);
|
|
328
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { algorithms } from '../../utils/decompress';
|
|
2
|
-
import { decodeFromBase64 } from '../../utils/base64';
|
|
3
|
-
|
|
4
|
-
const GZIP = 1;
|
|
5
|
-
const ZLIB = 2;
|
|
6
|
-
|
|
7
|
-
function Uint8ArrayToString(myUint8Arr) {
|
|
8
|
-
return String.fromCharCode.apply(null, myUint8Arr);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function StringToUint8Array(myString) {
|
|
12
|
-
const charCodes = myString.split('').map((e) => e.charCodeAt());
|
|
13
|
-
return new Uint8Array(charCodes);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Decode and decompress 'data' with 'compression' algorithm
|
|
18
|
-
*
|
|
19
|
-
* @param {string} data
|
|
20
|
-
* @param {number} compression 1 GZIP, 2 ZLIB
|
|
21
|
-
* @returns {Uint8Array}
|
|
22
|
-
* @throws if data string cannot be decoded, decompressed or the provided compression value is invalid (not 1 or 2)
|
|
23
|
-
*/
|
|
24
|
-
function decompress(data, compression) {
|
|
25
|
-
let compressData = decodeFromBase64(data);
|
|
26
|
-
const binData = StringToUint8Array(compressData);
|
|
27
|
-
|
|
28
|
-
if (typeof algorithms === 'string') throw new Error(algorithms);
|
|
29
|
-
if (compression === GZIP) return algorithms.gunzipSync(binData);
|
|
30
|
-
if (compression === ZLIB) return algorithms.unzlibSync(binData);
|
|
31
|
-
throw new Error(`Invalid compression algorithm #${compression}`);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Decode, decompress and parse the provided 'data' into a KeyList object
|
|
36
|
-
*
|
|
37
|
-
* @param {string} data
|
|
38
|
-
* @param {number} compression
|
|
39
|
-
* @returns {{a?: string[], r?: string[] }}
|
|
40
|
-
* @throws if data string cannot be decoded, decompressed or parsed
|
|
41
|
-
*/
|
|
42
|
-
export function parseKeyList(data, compression) {
|
|
43
|
-
const binKeyList = decompress(data, compression);
|
|
44
|
-
const strKeyList = Uint8ArrayToString(binKeyList);
|
|
45
|
-
|
|
46
|
-
// replace numbers to strings, to avoid losing precision
|
|
47
|
-
return JSON.parse(strKeyList.replace(/\d+/g, '"$&"'));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Decode, decompress and parse the provided 'data' into a Bitmap object
|
|
52
|
-
*
|
|
53
|
-
* @param {string} data
|
|
54
|
-
* @param {number} compression
|
|
55
|
-
* @returns {Uint8Array}
|
|
56
|
-
* @throws if data string cannot be decoded or decompressed
|
|
57
|
-
*/
|
|
58
|
-
export function parseBitmap(data, compression) {
|
|
59
|
-
return decompress(data, compression);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Check if the 'bitmap' bit at 'hash64hex' position is 1
|
|
64
|
-
*
|
|
65
|
-
* @param {Uint8Array} bitmap
|
|
66
|
-
* @param {string} hash64hex 16-chars string, representing a number in hexa
|
|
67
|
-
* @returns {boolean}
|
|
68
|
-
*/
|
|
69
|
-
export function isInBitmap(bitmap, hash64hex) {
|
|
70
|
-
// using the lowest 32 bits as index, to avoid losing precision when converting to number
|
|
71
|
-
const index = parseInt(hash64hex.slice(8), 16) % (bitmap.length * 8);
|
|
72
|
-
|
|
73
|
-
const internal = Math.floor(index / 8);
|
|
74
|
-
const offset = index % 8;
|
|
75
|
-
return (bitmap[internal] & 1 << offset) > 0;
|
|
76
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import getEventSource from '../../../services/getEventSource/browser';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Check if the JS environment has the necessary features to run in PUSH mode,
|
|
5
|
-
* i.e., EventSource, base64 encoder and decoder.
|
|
6
|
-
*
|
|
7
|
-
* @return {boolean} if push is supported
|
|
8
|
-
*/
|
|
9
|
-
export function checkPushRequirements(logger) {
|
|
10
|
-
const esReference = getEventSource();
|
|
11
|
-
if (!esReference) {
|
|
12
|
-
logger.warn('EventSource API is not available. Falling back to polling mode.');
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
if (typeof atob !== 'function' || typeof btoa !== 'function') {
|
|
16
|
-
logger.warn('"atob" and "btoa" functions for Base64 encoding are not available. Falling back to polling mode.');
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import getEventSource from '../../../services/getEventSource/node';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Check if the Node environment has the necessary features to run in PUSH mode,
|
|
5
|
-
* i.e., EventSource, base64 encoder and decoder.
|
|
6
|
-
*
|
|
7
|
-
* @return {boolean} if push is supported
|
|
8
|
-
*/
|
|
9
|
-
export function checkPushRequirements(logger) {
|
|
10
|
-
const esReference = getEventSource();
|
|
11
|
-
if (!esReference) {
|
|
12
|
-
logger.warn('EventSource API is not available. Falling back to polling mode.');
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import getEventSource from '../../services/getEventSource';
|
|
2
|
-
|
|
3
|
-
const VERSION = '1.1';
|
|
4
|
-
|
|
5
|
-
const CONTROL_CHANNEL_REGEX = /^control_/;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Build metadata headers for SSE connection.
|
|
9
|
-
*
|
|
10
|
-
* @param {Object} settings Validated settings.
|
|
11
|
-
*/
|
|
12
|
-
function buildSSEHeaders(settings) {
|
|
13
|
-
const headers = {
|
|
14
|
-
SplitSDKClientKey: settings.core.authorizationKey.slice(-4),
|
|
15
|
-
SplitSDKVersion: settings.version,
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// ip and hostname are false if IPAddressesEnabled is false
|
|
19
|
-
const { ip, hostname } = settings.runtime;
|
|
20
|
-
if (ip) headers['SplitSDKMachineIP'] = ip;
|
|
21
|
-
if (hostname) headers['SplitSDKMachineName'] = hostname;
|
|
22
|
-
|
|
23
|
-
return headers;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export default class SSEClient {
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Returns a SSEClient instance, or undefined if EventSource is not available.
|
|
30
|
-
* @param {Object} settings Validated SDK settings.
|
|
31
|
-
* @param {boolean} useHeaders True for Node and false for Browser, used to send metadata as headers or query params respectively.
|
|
32
|
-
*/
|
|
33
|
-
static getInstance(settings, useHeaders) {
|
|
34
|
-
const EventSource = getEventSource();
|
|
35
|
-
if (EventSource)
|
|
36
|
-
return new SSEClient(EventSource, settings, useHeaders);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Instance properties:
|
|
40
|
-
// streamingUrl: string
|
|
41
|
-
// EventSource: EventSource constructor
|
|
42
|
-
// connection: EventSource | undefined
|
|
43
|
-
// handler: EventHandler for open, close, error and messages events
|
|
44
|
-
|
|
45
|
-
constructor(EventSource, settings, useHeaders) {
|
|
46
|
-
this.EventSource = EventSource;
|
|
47
|
-
this.streamingUrl = settings.url('/sse');
|
|
48
|
-
this.useHeaders = useHeaders;
|
|
49
|
-
this.headers = buildSSEHeaders(settings);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
setEventHandler(handler) {
|
|
53
|
-
this.handler = handler;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Open the connection with a given authToken
|
|
58
|
-
*
|
|
59
|
-
* @param {Object} authToken
|
|
60
|
-
* @throws {TypeError} Will throw an error if `authToken` is undefined
|
|
61
|
-
*/
|
|
62
|
-
open(authToken) {
|
|
63
|
-
this.close(); // it closes connection if previously opened
|
|
64
|
-
|
|
65
|
-
const channelsQueryParam = Object.keys(authToken.channels).map(
|
|
66
|
-
function (channel) {
|
|
67
|
-
const params = CONTROL_CHANNEL_REGEX.test(channel) ? '[?occupancy=metrics.publishers]' : '';
|
|
68
|
-
return encodeURIComponent(params + channel);
|
|
69
|
-
}
|
|
70
|
-
).join(',');
|
|
71
|
-
const url = `${this.streamingUrl}?channels=${channelsQueryParam}&accessToken=${authToken.token}&v=${VERSION}&heartbeats=true`; // same results using `&heartbeats=false`
|
|
72
|
-
|
|
73
|
-
this.connection = new this.EventSource(
|
|
74
|
-
// For Browser, SplitSDKClientKey and SplitSDKClientKey headers are passed as query params,
|
|
75
|
-
// because native EventSource implementations for browser doesn't support headers.
|
|
76
|
-
this.useHeaders ? url : url + `&SplitSDKVersion=${this.headers.SplitSDKVersion}&SplitSDKClientKey=${this.headers.SplitSDKClientKey}`,
|
|
77
|
-
// For Node, metadata headers are passed because 'eventsource' package supports them.
|
|
78
|
-
this.useHeaders ? { headers: this.headers } : undefined
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
if (this.handler) { // no need to check if SSEClient is used only by PushManager
|
|
82
|
-
this.connection.onopen = this.handler.handleOpen;
|
|
83
|
-
this.connection.onmessage = this.handler.handleMessage;
|
|
84
|
-
this.connection.onerror = this.handler.handleError;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/** Close connection */
|
|
89
|
-
close() {
|
|
90
|
-
if (this.connection) this.connection.close();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { PUSH_SUBSYSTEM_UP, PUSH_SUBSYSTEM_DOWN, PUSH_NONRETRYABLE_ERROR, ControlTypes } from '../constants';
|
|
2
|
-
|
|
3
|
-
const CONTROL_CHANNEL_REGEXS = [/control_pri$/, /control_sec$/];
|
|
4
|
-
|
|
5
|
-
export default function notificationKeeperFactory(feedbackLoopEmitter) {
|
|
6
|
-
|
|
7
|
-
let channels = CONTROL_CHANNEL_REGEXS.map(regex => ({
|
|
8
|
-
regex,
|
|
9
|
-
hasPublishers: true, // keep track of publishers presence per channel, in order to compute `hasPublishers`. Init with true, to emit PUSH_SUBSYSTEM_UP if initial OCCUPANCY notifications have 0 publishers
|
|
10
|
-
oTime: -1, // keep track of most recent occupancy notification timestamp per channel
|
|
11
|
-
cTime: -1 // keep track of most recent control notification timestamp per channel
|
|
12
|
-
}));
|
|
13
|
-
|
|
14
|
-
// false if the number of publishers is equal to 0 in all regions
|
|
15
|
-
let hasPublishers = true;
|
|
16
|
-
|
|
17
|
-
// false if last CONTROL event was STREAMING_PAUSED or STREAMING_DISABLED
|
|
18
|
-
let hasResumed = true;
|
|
19
|
-
|
|
20
|
-
function getHasPublishers() { // computes the value of `hasPublishers`
|
|
21
|
-
return channels.some(c => c.hasPublishers);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
handleOpen() {
|
|
26
|
-
feedbackLoopEmitter.emit(PUSH_SUBSYSTEM_UP);
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
isStreamingUp() {
|
|
30
|
-
return hasResumed && hasPublishers;
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
handleOccupancyEvent(publishers, channel, timestamp) {
|
|
34
|
-
for (let i = 0; i < channels.length; i++) {
|
|
35
|
-
const c = channels[i];
|
|
36
|
-
if (c.regex.test(channel)) {
|
|
37
|
-
if (timestamp > c.oTime) {
|
|
38
|
-
c.oTime = timestamp;
|
|
39
|
-
c.hasPublishers = publishers !== 0;
|
|
40
|
-
const hasPublishersNow = getHasPublishers();
|
|
41
|
-
if (hasResumed) {
|
|
42
|
-
if (!hasPublishersNow && hasPublishers) {
|
|
43
|
-
feedbackLoopEmitter.emit(PUSH_SUBSYSTEM_DOWN);
|
|
44
|
-
} else if (hasPublishersNow && !hasPublishers) {
|
|
45
|
-
feedbackLoopEmitter.emit(PUSH_SUBSYSTEM_UP);
|
|
46
|
-
}
|
|
47
|
-
// nothing to do when hasResumed === false:
|
|
48
|
-
// streaming is already down for `!hasPublishersNow`, and cannot be up for `hasPublishersNow`
|
|
49
|
-
}
|
|
50
|
-
hasPublishers = hasPublishersNow;
|
|
51
|
-
}
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
handleControlEvent(controlType, channel, timestamp) {
|
|
58
|
-
/* STREAMING_RESET event is handled by PushManager directly since it doesn't require
|
|
59
|
-
* tracking timestamp and state like OCCUPANCY or CONTROL. It also ignores previous
|
|
60
|
-
* OCCUPANCY and CONTROL notifications, and whether PUSH_SUBSYSTEM_DOWN has been emitted or not */
|
|
61
|
-
if (controlType === ControlTypes.STREAMING_RESET) {
|
|
62
|
-
feedbackLoopEmitter.emit(controlType);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
for (let i = 0; i < channels.length; i++) {
|
|
67
|
-
const c = channels[i];
|
|
68
|
-
if (c.regex.test(channel)) {
|
|
69
|
-
if (timestamp > c.cTime) {
|
|
70
|
-
c.cTime = timestamp;
|
|
71
|
-
if (controlType === ControlTypes.STREAMING_DISABLED) {
|
|
72
|
-
feedbackLoopEmitter.emit(PUSH_NONRETRYABLE_ERROR);
|
|
73
|
-
} else if (hasPublishers) {
|
|
74
|
-
if (controlType === ControlTypes.STREAMING_PAUSED && hasResumed) {
|
|
75
|
-
feedbackLoopEmitter.emit(PUSH_SUBSYSTEM_DOWN);
|
|
76
|
-
} else if (controlType === ControlTypes.STREAMING_RESUMED && !hasResumed) {
|
|
77
|
-
feedbackLoopEmitter.emit(PUSH_SUBSYSTEM_UP);
|
|
78
|
-
}
|
|
79
|
-
// nothing to do when hasPublishers === false:
|
|
80
|
-
// streaming is already down for `STREAMING_PAUSED`, and cannot be up for `STREAMING_RESUMED`
|
|
81
|
-
}
|
|
82
|
-
hasResumed = controlType === ControlTypes.STREAMING_RESUMED;
|
|
83
|
-
}
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
};
|
|
90
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { OCCUPANCY } from '../constants';
|
|
2
|
-
import { isString } from '../../utils/lang';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Parses the `data` JSON string, if exists, of a given SSE error notifications.
|
|
6
|
-
* HTTP errors handled by Ably (e.g., 400 due to invalid token, 401 due to expired token, 500) have the `data` property.
|
|
7
|
-
* Other network and HTTP errors do not have this property.
|
|
8
|
-
*
|
|
9
|
-
* @param {Object} error
|
|
10
|
-
* @throws {SyntaxError} if `error.data` is an invalid JSON string
|
|
11
|
-
*/
|
|
12
|
-
export function errorParser(error) {
|
|
13
|
-
if (isString(error.data))
|
|
14
|
-
error.parsedData = JSON.parse(error.data); // cannot assign to read only property 'data'
|
|
15
|
-
|
|
16
|
-
return error;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Parses the `data` JSON string of a given SSE message notifications.
|
|
21
|
-
* Also assigns the type OCCUPANCY, if it corresponds, so that all supported messages (e.g., SPLIT_UPDATE, CONTROL) have a type.
|
|
22
|
-
*
|
|
23
|
-
* @param {Object} message
|
|
24
|
-
* @throws {SyntaxError} if `message.data` or `JSON.parse(message.data).data` are invalid JSON strings
|
|
25
|
-
*/
|
|
26
|
-
export function messageParser(message) {
|
|
27
|
-
const messageData = JSON.parse(message.data);
|
|
28
|
-
messageData.parsedData = JSON.parse(messageData.data);
|
|
29
|
-
|
|
30
|
-
// set the event type to OCCUPANCY, to handle all events uniformely
|
|
31
|
-
if (messageData.name && messageData.name === '[meta]occupancy')
|
|
32
|
-
messageData.parsedData.type = OCCUPANCY;
|
|
33
|
-
|
|
34
|
-
return messageData;
|
|
35
|
-
}
|