@splitsoftware/splitio-commons 2.12.0 → 3.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.txt +14 -1
- package/cjs/evaluator/condition/engineUtils.js +2 -2
- package/cjs/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.js +70 -0
- package/cjs/evaluator/fallbackConfigsCalculator/index.js +25 -0
- package/cjs/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
- package/cjs/evaluator/fallbackTreatmentsCalculator/index.js +21 -32
- package/cjs/evaluator/index.js +67 -42
- package/cjs/evaluator/matchers/whitelist.js +1 -1
- package/cjs/integrations/pluggable.js +1 -1
- package/cjs/listeners/browser.js +4 -3
- package/cjs/listeners/node.js +4 -4
- package/cjs/logger/constants.js +14 -20
- package/cjs/logger/index.js +1 -1
- package/cjs/logger/messages/debug.js +6 -7
- package/cjs/logger/messages/error.js +4 -4
- package/cjs/logger/messages/info.js +2 -4
- package/cjs/logger/messages/warn.js +9 -9
- package/cjs/platform/browser.js +15 -0
- package/cjs/platform/getEventSource/browser.js +8 -0
- package/cjs/platform/getEventSource/eventsource.js +480 -0
- package/cjs/platform/getEventSource/node.js +26 -0
- package/cjs/platform/getFetch/browser.js +9 -0
- package/cjs/platform/getFetch/node.js +27 -0
- package/cjs/platform/getOptions/node.js +25 -0
- package/cjs/platform/node.js +17 -0
- package/cjs/readiness/constants.js +2 -1
- package/cjs/sdkClient/client.js +9 -35
- package/cjs/sdkClient/clientAttributesDecoration.js +3 -3
- package/cjs/sdkClient/clientInputValidation.js +38 -81
- package/cjs/sdkClient/identity.js +1 -1
- package/cjs/sdkClient/sdkClient.js +4 -49
- package/cjs/sdkClient/sdkLifecycle.js +70 -0
- package/cjs/sdkClient/trackMethod.js +56 -0
- package/cjs/sdkFactory/index.js +8 -45
- package/cjs/sdkManager/index.js +3 -3
- package/cjs/services/splitApi.js +18 -13
- package/cjs/services/splitHttpClient.js +1 -1
- package/cjs/storages/AbstractSplitsCacheAsync.js +1 -1
- package/cjs/storages/AbstractSplitsCacheSync.js +1 -1
- package/cjs/storages/KeyBuilder.js +12 -12
- package/cjs/storages/KeyBuilderCS.js +13 -13
- package/cjs/storages/KeyBuilderSS.js +15 -15
- package/cjs/storages/getRolloutPlan.js +1 -1
- package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -1
- package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +1 -1
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +1 -1
- package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/MySegmentsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +2 -2
- package/cjs/storages/inRedis/EventsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +5 -5
- package/cjs/storages/inRedis/ImpressionsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/RedisAdapter.js +8 -8
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +6 -6
- package/cjs/storages/inRedis/TelemetryCacheInRedis.js +7 -7
- package/cjs/storages/inRedis/UniqueKeysCacheInRedis.js +3 -3
- package/cjs/storages/pluggable/EventsCachePluggable.js +1 -1
- package/cjs/storages/pluggable/ImpressionCountsCachePluggable.js +6 -6
- package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
- package/cjs/storages/pluggable/SplitsCachePluggable.js +4 -4
- package/cjs/storages/pluggable/TelemetryCachePluggable.js +7 -7
- package/cjs/storages/pluggable/UniqueKeysCachePluggable.js +2 -2
- package/cjs/storages/pluggable/index.js +3 -3
- package/cjs/storages/pluggable/wrapperAdapter.js +1 -1
- package/cjs/storages/setRolloutPlan.js +1 -1
- package/cjs/storages/utils.js +6 -6
- package/cjs/sync/offline/splitsParser/parseCondition.js +1 -1
- package/cjs/sync/polling/fetchers/segmentChangesFetcher.js +1 -1
- package/cjs/sync/polling/fetchers/splitChangesFetcher.js +23 -14
- package/cjs/sync/polling/pollingManagerCS.js +11 -11
- package/cjs/sync/polling/pollingManagerSS.js +13 -13
- package/cjs/sync/polling/syncTasks/definitionsSyncTask.js +12 -0
- package/cjs/sync/polling/updaters/{splitChangesUpdater.js → definitionChangesUpdater.js} +67 -59
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +1 -1
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +6 -6
- package/cjs/sync/streaming/SSEClient/index.js +2 -2
- package/cjs/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +2 -2
- package/cjs/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +2 -2
- package/cjs/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +4 -4
- package/cjs/sync/streaming/parseUtils.js +12 -12
- package/cjs/sync/streaming/pushManager.js +2 -2
- package/cjs/sync/submitters/impressionsSubmitter.js +6 -6
- package/cjs/sync/submitters/submitter.js +1 -1
- package/cjs/sync/syncManagerOnline.js +5 -2
- package/cjs/trackers/eventTracker.js +10 -12
- package/cjs/trackers/impressionObserver/buildKey.js +1 -1
- package/cjs/trackers/impressionsTracker.js +37 -20
- package/cjs/trackers/uniqueKeysTracker.js +1 -1
- package/cjs/utils/EventEmitter.js +391 -0
- package/cjs/utils/filter/bloomFilter.js +37 -0
- package/cjs/utils/inputValidation/apiKey.js +1 -1
- package/cjs/utils/inputValidation/attribute.js +2 -2
- package/cjs/utils/inputValidation/{split.js → definition.js} +10 -10
- package/cjs/utils/inputValidation/{splitExistence.js → definitionExistence.js} +6 -6
- package/cjs/utils/inputValidation/definitions.js +25 -0
- package/cjs/utils/inputValidation/eventProperties.js +1 -1
- package/cjs/utils/inputValidation/index.js +7 -7
- package/cjs/utils/inputValidation/isOperational.js +4 -4
- package/cjs/utils/inputValidation/target.js +22 -0
- package/cjs/utils/labels/index.js +3 -3
- package/cjs/utils/lang/index.js +1 -1
- package/cjs/utils/promise/timeout.js +1 -1
- package/cjs/utils/settingsValidation/splitFilters.js +4 -4
- package/cjs/utils/settingsValidation/url.js +5 -5
- package/esm/evaluator/condition/engineUtils.js +2 -2
- package/esm/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.js +64 -0
- package/esm/evaluator/fallbackConfigsCalculator/index.js +21 -0
- package/esm/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
- package/esm/evaluator/fallbackTreatmentsCalculator/index.js +21 -33
- package/esm/evaluator/index.js +66 -42
- package/esm/evaluator/matchers/whitelist.js +1 -1
- package/esm/integrations/pluggable.js +1 -1
- package/esm/listeners/browser.js +4 -3
- package/esm/listeners/node.js +4 -4
- package/esm/logger/constants.js +11 -17
- package/esm/logger/index.js +1 -1
- package/esm/logger/messages/debug.js +5 -6
- package/esm/logger/messages/error.js +3 -3
- package/esm/logger/messages/info.js +1 -3
- package/esm/logger/messages/warn.js +8 -8
- package/esm/platform/browser.js +12 -0
- package/esm/platform/getEventSource/browser.js +4 -0
- package/esm/platform/getEventSource/eventsource.js +480 -0
- package/esm/platform/getEventSource/node.js +20 -0
- package/esm/platform/getFetch/browser.js +5 -0
- package/esm/platform/getFetch/node.js +22 -0
- package/esm/platform/getOptions/node.js +20 -0
- package/esm/platform/node.js +14 -0
- package/esm/readiness/constants.js +1 -0
- package/esm/sdkClient/client.js +10 -37
- package/esm/sdkClient/clientAttributesDecoration.js +3 -3
- package/esm/sdkClient/clientInputValidation.js +40 -83
- package/esm/sdkClient/identity.js +1 -1
- package/esm/sdkClient/sdkClient.js +4 -49
- package/esm/sdkClient/sdkLifecycle.js +66 -0
- package/esm/sdkClient/trackMethod.js +52 -0
- package/esm/sdkFactory/index.js +8 -45
- package/esm/sdkManager/index.js +4 -4
- package/esm/services/splitApi.js +18 -13
- package/esm/services/splitHttpClient.js +1 -1
- package/esm/storages/AbstractSplitsCacheAsync.js +1 -1
- package/esm/storages/AbstractSplitsCacheSync.js +1 -1
- package/esm/storages/KeyBuilder.js +12 -12
- package/esm/storages/KeyBuilderCS.js +12 -12
- package/esm/storages/KeyBuilderSS.js +14 -14
- package/esm/storages/getRolloutPlan.js +1 -1
- package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +1 -1
- package/esm/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -1
- package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +1 -1
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +2 -2
- package/esm/storages/inRedis/EventsCacheInRedis.js +1 -1
- package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +4 -4
- package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
- package/esm/storages/inRedis/RedisAdapter.js +7 -7
- package/esm/storages/inRedis/SplitsCacheInRedis.js +4 -4
- package/esm/storages/inRedis/TelemetryCacheInRedis.js +7 -7
- package/esm/storages/inRedis/UniqueKeysCacheInRedis.js +1 -1
- package/esm/storages/pluggable/EventsCachePluggable.js +1 -1
- package/esm/storages/pluggable/ImpressionCountsCachePluggable.js +5 -5
- package/esm/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
- package/esm/storages/pluggable/SplitsCachePluggable.js +2 -2
- package/esm/storages/pluggable/TelemetryCachePluggable.js +7 -7
- package/esm/storages/pluggable/UniqueKeysCachePluggable.js +1 -1
- package/esm/storages/pluggable/index.js +2 -2
- package/esm/storages/pluggable/wrapperAdapter.js +1 -1
- package/esm/storages/setRolloutPlan.js +1 -1
- package/esm/storages/utils.js +6 -6
- package/esm/sync/offline/splitsParser/parseCondition.js +1 -1
- package/esm/sync/polling/fetchers/splitChangesFetcher.js +24 -15
- package/esm/sync/polling/pollingManagerCS.js +11 -11
- package/esm/sync/polling/pollingManagerSS.js +13 -13
- package/esm/sync/polling/syncTasks/definitionsSyncTask.js +8 -0
- package/esm/sync/polling/updaters/{splitChangesUpdater.js → definitionChangesUpdater.js} +67 -59
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +2 -2
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +7 -7
- package/esm/sync/streaming/SSEClient/index.js +2 -2
- package/esm/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +2 -2
- package/esm/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +2 -2
- package/esm/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +4 -4
- package/esm/sync/streaming/parseUtils.js +10 -10
- package/esm/sync/streaming/pushManager.js +3 -3
- package/esm/sync/submitters/impressionsSubmitter.js +6 -6
- package/esm/sync/submitters/submitter.js +1 -1
- package/esm/sync/syncManagerOnline.js +5 -2
- package/esm/trackers/eventTracker.js +10 -12
- package/esm/trackers/impressionObserver/buildKey.js +1 -1
- package/esm/trackers/impressionsTracker.js +38 -21
- package/esm/trackers/uniqueKeysTracker.js +1 -1
- package/esm/utils/EventEmitter.js +387 -0
- package/esm/utils/filter/bloomFilter.js +33 -0
- package/esm/utils/inputValidation/apiKey.js +1 -1
- package/esm/utils/inputValidation/attribute.js +2 -2
- package/esm/utils/inputValidation/{split.js → definition.js} +8 -8
- package/esm/utils/inputValidation/definitionExistence.js +15 -0
- package/esm/utils/inputValidation/definitions.js +21 -0
- package/esm/utils/inputValidation/index.js +3 -3
- package/esm/utils/inputValidation/isOperational.js +4 -4
- package/esm/utils/inputValidation/target.js +18 -0
- package/esm/utils/labels/index.js +2 -2
- package/esm/utils/promise/timeout.js +1 -1
- package/esm/utils/settingsValidation/splitFilters.js +4 -4
- package/esm/utils/settingsValidation/url.js +5 -5
- package/package.json +15 -6
- package/src/dtos/types.ts +65 -70
- package/src/evaluator/Engine.ts +4 -4
- package/src/evaluator/combiners/and.ts +3 -3
- package/src/evaluator/combiners/ifelseif.ts +2 -2
- package/src/evaluator/condition/engineUtils.ts +2 -2
- package/src/evaluator/condition/index.ts +3 -3
- package/src/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.ts +76 -0
- package/src/evaluator/fallbackConfigsCalculator/index.ts +24 -0
- package/src/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.ts +5 -7
- package/src/evaluator/fallbackTreatmentsCalculator/index.ts +27 -41
- package/src/evaluator/index.ts +80 -45
- package/src/evaluator/matchers/dependency.ts +2 -2
- package/src/evaluator/matchers/matcherTypes.ts +2 -2
- package/src/evaluator/matchers/prerequisites.ts +4 -4
- package/src/evaluator/matchers/rbsegment.ts +2 -2
- package/src/evaluator/matchers/whitelist.ts +2 -2
- package/src/evaluator/matchersTransform/index.ts +2 -2
- package/src/evaluator/matchersTransform/whitelist.ts +2 -2
- package/src/evaluator/parser/index.ts +4 -4
- package/src/evaluator/treatments/index.ts +2 -2
- package/src/evaluator/types.ts +6 -6
- package/src/evaluator/value/index.ts +1 -1
- package/src/integrations/pluggable.ts +1 -1
- package/src/listeners/browser.ts +11 -8
- package/src/listeners/node.ts +2 -5
- package/src/logger/constants.ts +11 -17
- package/src/logger/messages/debug.ts +5 -6
- package/src/logger/messages/error.ts +3 -3
- package/src/logger/messages/info.ts +1 -3
- package/src/logger/messages/warn.ts +8 -8
- package/src/platform/browser.ts +14 -0
- package/src/platform/getEventSource/browser.ts +4 -0
- package/src/platform/getEventSource/eventsource.js +519 -0
- package/src/platform/getEventSource/node.ts +23 -0
- package/src/platform/getFetch/browser.ts +5 -0
- package/src/platform/getFetch/node.ts +27 -0
- package/src/platform/getOptions/node.ts +24 -0
- package/src/platform/node.ts +16 -0
- package/src/readiness/constants.ts +1 -0
- package/src/sdkClient/client.ts +11 -41
- package/src/sdkClient/clientInputValidation.ts +44 -84
- package/src/sdkClient/sdkClient.ts +5 -54
- package/src/sdkClient/sdkLifecycle.ts +78 -0
- package/src/sdkClient/trackMethod.ts +59 -0
- package/src/sdkFactory/index.ts +10 -54
- package/src/sdkFactory/types.ts +19 -16
- package/src/sdkManager/index.ts +9 -9
- package/src/services/splitApi.ts +6 -0
- package/src/services/types.ts +3 -2
- package/src/storages/AbstractSplitsCacheAsync.ts +7 -7
- package/src/storages/AbstractSplitsCacheSync.ts +10 -10
- package/src/storages/inLocalStorage/RBSegmentsCacheInLocal.ts +2 -2
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +6 -6
- package/src/storages/inMemory/RBSegmentsCacheInMemory.ts +2 -2
- package/src/storages/inMemory/SplitsCacheInMemory.ts +5 -5
- package/src/storages/inMemory/TelemetryCacheInMemory.ts +2 -2
- package/src/storages/inRedis/RBSegmentsCacheInRedis.ts +2 -2
- package/src/storages/inRedis/SplitsCacheInRedis.ts +9 -9
- package/src/storages/pluggable/RBSegmentsCachePluggable.ts +2 -2
- package/src/storages/pluggable/SplitsCachePluggable.ts +9 -9
- package/src/storages/types.ts +21 -16
- package/src/sync/offline/splitsParser/parseCondition.ts +2 -2
- package/src/sync/offline/splitsParser/splitsParserFromSettings.ts +3 -3
- package/src/sync/offline/splitsParser/types.ts +6 -3
- package/src/sync/offline/syncManagerOffline.ts +2 -2
- package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +6 -6
- package/src/sync/polling/fetchers/splitChangesFetcher.ts +57 -22
- package/src/sync/polling/fetchers/types.ts +5 -3
- package/src/sync/polling/pollingManagerCS.ts +12 -10
- package/src/sync/polling/pollingManagerSS.ts +15 -13
- package/src/sync/polling/syncTasks/{splitsSyncTask.ts → definitionsSyncTask.ts} +10 -11
- package/src/sync/polling/types.ts +3 -3
- package/src/sync/polling/updaters/{splitChangesUpdater.ts → definitionChangesUpdater.ts} +77 -68
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +2 -2
- package/src/sync/polling/updaters/segmentChangesUpdater.ts +7 -7
- package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +6 -6
- package/src/sync/streaming/parseUtils.ts +12 -12
- package/src/sync/streaming/pushManager.ts +3 -3
- package/src/sync/submitters/impressionsSubmitter.ts +9 -9
- package/src/sync/submitters/types.ts +3 -0
- package/src/sync/syncManagerOnline.ts +6 -2
- package/src/trackers/eventTracker.ts +7 -10
- package/src/trackers/impressionsTracker.ts +42 -26
- package/src/trackers/types.ts +3 -1
- package/src/utils/EventEmitter.js +444 -0
- package/src/utils/filter/bloomFilter.ts +38 -0
- package/src/utils/inputValidation/definition.ts +27 -0
- package/src/utils/inputValidation/definitionExistence.ts +19 -0
- package/src/utils/inputValidation/definitions.ts +21 -0
- package/src/utils/inputValidation/index.ts +3 -3
- package/src/utils/inputValidation/isOperational.ts +4 -4
- package/src/utils/inputValidation/target.ts +21 -0
- package/src/utils/labels/index.ts +2 -2
- package/src/utils/settingsValidation/splitFilters.ts +3 -3
- package/types/splitio.d.ts +202 -9
- package/cjs/sync/polling/syncTasks/splitsSyncTask.js +0 -13
- package/cjs/utils/inputValidation/splits.js +0 -25
- package/esm/sync/polling/syncTasks/splitsSyncTask.js +0 -9
- package/esm/utils/inputValidation/splitExistence.js +0 -15
- package/esm/utils/inputValidation/splits.js +0 -21
- package/src/utils/inputValidation/split.ts +0 -27
- package/src/utils/inputValidation/splitExistence.ts +0 -19
- package/src/utils/inputValidation/splits.ts +0 -21
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.codesError = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
-
var c =
|
|
5
|
+
var c = tslib_1.__importStar(require("../constants"));
|
|
6
6
|
exports.codesError = [
|
|
7
7
|
// evaluator
|
|
8
|
-
[c.ERROR_ENGINE_COMBINER_IFELSEIF, c.LOG_PREFIX_ENGINE_COMBINER + 'Invalid
|
|
8
|
+
[c.ERROR_ENGINE_COMBINER_IFELSEIF, c.LOG_PREFIX_ENGINE_COMBINER + 'Invalid definition, no valid rules or unsupported targeting rule type found'],
|
|
9
9
|
[c.ENGINE_MATCHER_ERROR, c.LOG_PREFIX_ENGINE_MATCHER + '[%s] %s'],
|
|
10
10
|
// SDK
|
|
11
11
|
[c.ERROR_LOGLEVEL_INVALID, 'logger: Invalid Log Level - No changes to the logs will be applied.'],
|
|
@@ -16,7 +16,7 @@ exports.codesError = [
|
|
|
16
16
|
// synchronizer
|
|
17
17
|
[c.ERROR_SYNC_OFFLINE_LOADING, c.LOG_PREFIX_SYNC_OFFLINE + 'There was an issue loading the mock feature flags data. No changes will be applied to the current cache. %s'],
|
|
18
18
|
[c.ERROR_STREAMING_SSE, c.LOG_PREFIX_SYNC_STREAMING + 'Failed to connect or error on streaming connection, with error message: %s'],
|
|
19
|
-
[c.ERROR_STREAMING_AUTH, c.LOG_PREFIX_SYNC_STREAMING + 'Failed to authenticate for streaming. Error: %s
|
|
19
|
+
[c.ERROR_STREAMING_AUTH, c.LOG_PREFIX_SYNC_STREAMING + 'Failed to authenticate for streaming. Error: %s'],
|
|
20
20
|
[c.ERROR_HTTP, 'HTTP request failed with %s. URL: %s. Message: %s'],
|
|
21
21
|
// client status
|
|
22
22
|
[c.ERROR_CLIENT_LISTENER, 'A listener was added for %s on the SDK, which has already fired and won\'t be emitted again. The callback won\'t be executed.'],
|
|
@@ -37,6 +37,6 @@ exports.codesError = [
|
|
|
37
37
|
[c.ERROR_INVALID_CONFIG_PARAM, c.LOG_PREFIX_SETTINGS + ': you passed an invalid "%s" config param. It should be one of the following values: %s. Defaulting to "%s".'],
|
|
38
38
|
[c.ERROR_STORAGE_INVALID, c.LOG_PREFIX_SETTINGS + ': the provided storage is invalid.%s Falling back into default MEMORY storage'],
|
|
39
39
|
[c.ERROR_MIN_CONFIG_PARAM, c.LOG_PREFIX_SETTINGS + ': the provided "%s" config param is lower than allowed. Setting to the minimum value %s seconds'],
|
|
40
|
-
[c.ERROR_TOO_MANY_SETS, c.LOG_PREFIX_SETTINGS + ': the
|
|
40
|
+
[c.ERROR_TOO_MANY_SETS, c.LOG_PREFIX_SETTINGS + ': the number of sets provided is too high, which causes a URI length error.'],
|
|
41
41
|
[c.ERROR_SETS_FILTER_EXCLUSIVE, c.LOG_PREFIX_SETTINGS + ': the Set filter is exclusive and cannot be used simultaneously with names or prefix filters. Ignoring names and prefixes.'],
|
|
42
42
|
];
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.codesInfo = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
-
var c =
|
|
5
|
+
var c = tslib_1.__importStar(require("../constants"));
|
|
6
6
|
var warn_1 = require("./warn");
|
|
7
7
|
var READY_MSG = 'Split SDK client is ready';
|
|
8
8
|
exports.codesInfo = warn_1.codesWarn.concat([
|
|
@@ -10,8 +10,7 @@ exports.codesInfo = warn_1.codesWarn.concat([
|
|
|
10
10
|
[c.CLIENT_READY_FROM_CACHE, READY_MSG + ' from cache'],
|
|
11
11
|
[c.CLIENT_READY, READY_MSG],
|
|
12
12
|
// SDK
|
|
13
|
-
[c.
|
|
14
|
-
[c.IMPRESSION_QUEUEING, c.LOG_PREFIX_IMPRESSIONS_TRACKER + 'Queueing corresponding impression.'],
|
|
13
|
+
[c.IMPRESSION_QUEUEING, c.LOG_PREFIX_IMPRESSIONS_TRACKER + 'Queueing impression. %s: %s. Key: %s. Evaluation: %s. Label: %s'],
|
|
15
14
|
[c.NEW_SHARED_CLIENT, 'New shared client instance created.'],
|
|
16
15
|
[c.NEW_FACTORY, 'New Split SDK instance created. %s'],
|
|
17
16
|
[c.EVENTS_TRACKER_SUCCESS, c.LOG_PREFIX_EVENTS_TRACKER + 'Successfully queued %s'],
|
|
@@ -23,7 +22,6 @@ exports.codesInfo = warn_1.codesWarn.concat([
|
|
|
23
22
|
[c.POLLING_SMART_PAUSING, c.LOG_PREFIX_SYNC_POLLING + 'Turning segments data polling %s.'],
|
|
24
23
|
[c.POLLING_START, c.LOG_PREFIX_SYNC_POLLING + 'Starting polling'],
|
|
25
24
|
[c.POLLING_STOP, c.LOG_PREFIX_SYNC_POLLING + 'Stopping polling'],
|
|
26
|
-
[c.SYNC_SPLITS_FETCH_RETRY, c.LOG_PREFIX_SYNC_SPLITS + 'Retrying fetch of feature flags (attempt #%s). Reason: %s'],
|
|
27
25
|
[c.SUBMITTERS_PUSH_FULL_QUEUE, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Flushing full %s queue and resetting timer.'],
|
|
28
26
|
[c.SUBMITTERS_PUSH, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Pushing %s.'],
|
|
29
27
|
[c.SUBMITTERS_PUSH_PAGE_HIDDEN, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Flushing %s because page became hidden.'],
|
|
@@ -2,31 +2,31 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.codesWarn = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
-
var c =
|
|
5
|
+
var c = tslib_1.__importStar(require("../constants"));
|
|
6
6
|
var error_1 = require("./error");
|
|
7
7
|
exports.codesWarn = error_1.codesError.concat([
|
|
8
8
|
// evaluator
|
|
9
9
|
[c.ENGINE_VALUE_INVALID, c.LOG_PREFIX_ENGINE_VALUE + 'Value %s doesn\'t match with expected type.'],
|
|
10
10
|
[c.ENGINE_VALUE_NO_ATTRIBUTES, c.LOG_PREFIX_ENGINE_VALUE + 'Defined attribute `%s`. No attributes received.'],
|
|
11
11
|
// synchronizer
|
|
12
|
-
[c.
|
|
13
|
-
[c.
|
|
12
|
+
[c.SYNC_FETCH_RETRY, c.LOG_PREFIX_SYNC + 'Retrying fetch of %s (attempt #%s). Reason: %s'],
|
|
13
|
+
[c.SYNC_FETCH_FAILS, c.LOG_PREFIX_SYNC + 'Error while doing fetch of %s. %s'],
|
|
14
14
|
[c.STREAMING_PARSING_ERROR_FAILS, c.LOG_PREFIX_SYNC_STREAMING + 'Error parsing SSE error notification: %s'],
|
|
15
15
|
[c.STREAMING_PARSING_MESSAGE_FAILS, c.LOG_PREFIX_SYNC_STREAMING + 'Error parsing SSE message notification: %s'],
|
|
16
16
|
[c.STREAMING_FALLBACK, c.LOG_PREFIX_SYNC_STREAMING + 'Falling back to polling mode. Reason: %s'],
|
|
17
|
-
[c.SUBMITTERS_PUSH_FAILS, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Dropping %s after retry. Reason: %s
|
|
18
|
-
[c.SUBMITTERS_PUSH_RETRY, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Failed to push %s, keeping data to retry on next iteration. Reason: %s
|
|
17
|
+
[c.SUBMITTERS_PUSH_FAILS, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Dropping %s after retry. Reason: %s'],
|
|
18
|
+
[c.SUBMITTERS_PUSH_RETRY, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Failed to push %s, keeping data to retry on next iteration. Reason: %s'],
|
|
19
19
|
// client status
|
|
20
|
-
[c.CLIENT_NOT_READY_FROM_CACHE, '%s: the SDK is not ready to evaluate. Results may be incorrect
|
|
20
|
+
[c.CLIENT_NOT_READY_FROM_CACHE, '%s: the SDK is not ready to evaluate. Results may be incorrect. Make sure to wait for SDK readiness before using this method.'],
|
|
21
21
|
[c.CLIENT_NO_LISTENER, 'No listeners for SDK_READY event detected. Incorrect control treatments could have been logged if you called getTreatment/s while the SDK was not yet synchronized with the backend.'],
|
|
22
22
|
// input validation
|
|
23
23
|
[c.WARN_SETTING_NULL, '%s: Property "%s" is of invalid type. Setting value to null.'],
|
|
24
24
|
[c.WARN_TRIMMING_PROPERTIES, '%s: more than 300 properties were provided. Some of them will be trimmed when processed.'],
|
|
25
25
|
[c.WARN_CONVERTING, '%s: %s "%s" is not of type string, converting.'],
|
|
26
26
|
[c.WARN_TRIMMING, '%s: %s "%s" has extra whitespace, trimming.'],
|
|
27
|
-
[c.
|
|
27
|
+
[c.WARN_NOT_EXISTENT_DEFINITION, '%s: "%s" does not exist in this environment. Please double check that it exists in Harness UI.'],
|
|
28
28
|
[c.WARN_LOWERCASE_TRAFFIC_TYPE, '%s: traffic_type_name should be all lowercase - converting string to lowercase.'],
|
|
29
|
-
[c.WARN_NOT_EXISTENT_TT, '%s: traffic type "%s" does not have any corresponding feature flag in this environment, make sure you\'re tracking your events to a valid traffic type defined in
|
|
29
|
+
[c.WARN_NOT_EXISTENT_TT, '%s: traffic type "%s" does not have any corresponding feature flag in this environment, make sure you\'re tracking your events to a valid traffic type defined in Harness UI.'],
|
|
30
30
|
[c.WARN_FLAGSET_NOT_CONFIGURED, '%s: you passed %s which is not part of the configured FlagSetsFilter, ignoring Flag Set.'],
|
|
31
31
|
// initialization / settings validation
|
|
32
32
|
[c.WARN_INTEGRATION_INVALID, c.LOG_PREFIX_SETTINGS + ': %s integration item(s) at settings is invalid. %s'],
|
|
@@ -38,5 +38,5 @@ exports.codesWarn = error_1.codesError.concat([
|
|
|
38
38
|
[c.STREAMING_PARSING_SPLIT_UPDATE, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching SplitChanges due to an error processing %s notification: %s'],
|
|
39
39
|
[c.WARN_INVALID_FLAGSET, '%s: you passed %s, flag set must adhere to the regular expressions %s. This means a flag set must start with a letter or number, be in lowercase, alphanumeric and have a max length of 50 characters. %s was discarded.'],
|
|
40
40
|
[c.WARN_LOWERCASE_FLAGSET, '%s: flag set %s should be all lowercase - converting string to lowercase.'],
|
|
41
|
-
[c.WARN_FLAGSET_WITHOUT_FLAGS, '%s: you passed %s flag set that does not contain cached feature flag names. Please double check what flag sets are in use in
|
|
41
|
+
[c.WARN_FLAGSET_WITHOUT_FLAGS, '%s: you passed %s flag set that does not contain cached feature flag names. Please double check what flag sets are in use in Harness UI.'],
|
|
42
42
|
]);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.platform = void 0;
|
|
4
|
+
var EventEmitter_1 = require("../utils/EventEmitter");
|
|
5
|
+
var browser_1 = require("../platform/getFetch/browser");
|
|
6
|
+
var browser_2 = require("../platform/getEventSource/browser");
|
|
7
|
+
var browser_3 = require("../listeners/browser");
|
|
8
|
+
var browser_4 = require("../utils/timeTracker/now/browser");
|
|
9
|
+
exports.platform = {
|
|
10
|
+
getFetch: browser_1.getFetch,
|
|
11
|
+
getEventSource: browser_2.getEventSource,
|
|
12
|
+
EventEmitter: EventEmitter_1.EventEmitter,
|
|
13
|
+
now: browser_4.now,
|
|
14
|
+
SignalListener: browser_3.BrowserSignalListener
|
|
15
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEventSource = void 0;
|
|
4
|
+
function getEventSource() {
|
|
5
|
+
// eslint-disable-next-line no-undef -- Feature detection for EventSource
|
|
6
|
+
return typeof EventSource === 'function' ? EventSource : undefined;
|
|
7
|
+
}
|
|
8
|
+
exports.getEventSource = getEventSource;
|
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable no-prototype-builtins */
|
|
3
|
+
/* eslint-disable no-restricted-syntax */
|
|
4
|
+
/*
|
|
5
|
+
Modified version of "eventsource" v1.1.2 package (https://www.npmjs.com/package/eventsource/v/1.1.2) that accepts a custom agent.
|
|
6
|
+
Requires CommonJS and Node.js globals (require, process, Buffer).
|
|
7
|
+
|
|
8
|
+
The MIT License
|
|
9
|
+
|
|
10
|
+
Copyright (c) EventSource GitHub organization
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
13
|
+
a copy of this software and associated documentation files (the
|
|
14
|
+
"Software"), to deal in the Software without restriction, including
|
|
15
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
16
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
17
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
18
|
+
the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be
|
|
21
|
+
included in all copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
24
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
25
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
26
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
27
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
28
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
29
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
30
|
+
*/
|
|
31
|
+
var parse = require('url').parse;
|
|
32
|
+
var events = require('events');
|
|
33
|
+
var https = require('https');
|
|
34
|
+
var http = require('http');
|
|
35
|
+
var util = require('util');
|
|
36
|
+
var httpsOptions = [
|
|
37
|
+
'pfx', 'key', 'passphrase', 'cert', 'ca', 'ciphers',
|
|
38
|
+
'rejectUnauthorized', 'secureProtocol', 'servername', 'checkServerIdentity'
|
|
39
|
+
];
|
|
40
|
+
var bom = [239, 187, 191];
|
|
41
|
+
var colon = 58;
|
|
42
|
+
var space = 32;
|
|
43
|
+
var lineFeed = 10;
|
|
44
|
+
var carriageReturn = 13;
|
|
45
|
+
function hasBom(buf) {
|
|
46
|
+
return bom.every(function (charCode, index) {
|
|
47
|
+
return buf[index] === charCode;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates a new EventSource object
|
|
52
|
+
*
|
|
53
|
+
* @param {String} url the URL to which to connect
|
|
54
|
+
* @param {Object} [eventSourceInitDict] extra init params. See README for details.
|
|
55
|
+
* @api public
|
|
56
|
+
**/
|
|
57
|
+
function EventSource(url, eventSourceInitDict) {
|
|
58
|
+
var readyState = EventSource.CONNECTING;
|
|
59
|
+
var headers = eventSourceInitDict && eventSourceInitDict.headers;
|
|
60
|
+
var hasNewOrigin = false;
|
|
61
|
+
Object.defineProperty(this, 'readyState', {
|
|
62
|
+
get: function () {
|
|
63
|
+
return readyState;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(this, 'url', {
|
|
67
|
+
get: function () {
|
|
68
|
+
return url;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
var self = this;
|
|
72
|
+
self.reconnectInterval = 1000;
|
|
73
|
+
self.connectionInProgress = false;
|
|
74
|
+
var reconnectUrl = null;
|
|
75
|
+
function onConnectionClosed(message) {
|
|
76
|
+
if (readyState === EventSource.CLOSED)
|
|
77
|
+
return;
|
|
78
|
+
readyState = EventSource.CONNECTING;
|
|
79
|
+
_emit('error', new Event('error', { message: message }));
|
|
80
|
+
// The url may have been changed by a temporary redirect. If that's the case,
|
|
81
|
+
// revert it now, and flag that we are no longer pointing to a new origin
|
|
82
|
+
if (reconnectUrl) {
|
|
83
|
+
url = reconnectUrl;
|
|
84
|
+
reconnectUrl = null;
|
|
85
|
+
hasNewOrigin = false;
|
|
86
|
+
}
|
|
87
|
+
setTimeout(function () {
|
|
88
|
+
if (readyState !== EventSource.CONNECTING || self.connectionInProgress) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
self.connectionInProgress = true;
|
|
92
|
+
connect();
|
|
93
|
+
}, self.reconnectInterval);
|
|
94
|
+
}
|
|
95
|
+
var req;
|
|
96
|
+
var lastEventId = '';
|
|
97
|
+
if (headers && headers['Last-Event-ID']) {
|
|
98
|
+
lastEventId = headers['Last-Event-ID'];
|
|
99
|
+
delete headers['Last-Event-ID'];
|
|
100
|
+
}
|
|
101
|
+
var discardTrailingNewline = false;
|
|
102
|
+
var data = '';
|
|
103
|
+
var eventName = '';
|
|
104
|
+
function connect() {
|
|
105
|
+
var options = parse(url);
|
|
106
|
+
var isSecure = options.protocol === 'https:';
|
|
107
|
+
options.headers = { 'Cache-Control': 'no-cache', 'Accept': 'text/event-stream' };
|
|
108
|
+
if (lastEventId)
|
|
109
|
+
options.headers['Last-Event-ID'] = lastEventId;
|
|
110
|
+
if (headers) {
|
|
111
|
+
var reqHeaders = hasNewOrigin ? removeUnsafeHeaders(headers) : headers;
|
|
112
|
+
for (var i in reqHeaders) {
|
|
113
|
+
var header = reqHeaders[i];
|
|
114
|
+
if (header) {
|
|
115
|
+
options.headers[i] = header;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// Legacy: this should be specified as `eventSourceInitDict.https.rejectUnauthorized`,
|
|
120
|
+
// but for now exists as a backwards-compatibility layer
|
|
121
|
+
options.rejectUnauthorized = !(eventSourceInitDict && !eventSourceInitDict.rejectUnauthorized);
|
|
122
|
+
if (eventSourceInitDict && eventSourceInitDict.createConnection !== undefined) {
|
|
123
|
+
options.createConnection = eventSourceInitDict.createConnection;
|
|
124
|
+
}
|
|
125
|
+
// If specify agent, use it.
|
|
126
|
+
if (eventSourceInitDict && eventSourceInitDict.agent !== undefined) {
|
|
127
|
+
options.agent = eventSourceInitDict.agent;
|
|
128
|
+
}
|
|
129
|
+
// If specify http proxy, make the request to sent to the proxy server,
|
|
130
|
+
// and include the original url in path and Host headers
|
|
131
|
+
var useProxy = eventSourceInitDict && eventSourceInitDict.proxy;
|
|
132
|
+
if (useProxy) {
|
|
133
|
+
var proxy = parse(eventSourceInitDict.proxy);
|
|
134
|
+
isSecure = proxy.protocol === 'https:';
|
|
135
|
+
options.protocol = isSecure ? 'https:' : 'http:';
|
|
136
|
+
options.path = url;
|
|
137
|
+
options.headers.Host = options.host;
|
|
138
|
+
options.hostname = proxy.hostname;
|
|
139
|
+
options.host = proxy.host;
|
|
140
|
+
options.port = proxy.port;
|
|
141
|
+
}
|
|
142
|
+
// If https options are specified, merge them into the request options
|
|
143
|
+
if (eventSourceInitDict && eventSourceInitDict.https) {
|
|
144
|
+
for (var optName in eventSourceInitDict.https) {
|
|
145
|
+
if (httpsOptions.indexOf(optName) === -1) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
var option = eventSourceInitDict.https[optName];
|
|
149
|
+
if (option !== undefined) {
|
|
150
|
+
options[optName] = option;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// Pass this on to the XHR
|
|
155
|
+
if (eventSourceInitDict && eventSourceInitDict.withCredentials !== undefined) {
|
|
156
|
+
options.withCredentials = eventSourceInitDict.withCredentials;
|
|
157
|
+
}
|
|
158
|
+
req = (isSecure ? https : http).request(options, function (res) {
|
|
159
|
+
self.connectionInProgress = false;
|
|
160
|
+
// Handle HTTP errors
|
|
161
|
+
if (res.statusCode === 500 || res.statusCode === 502 || res.statusCode === 503 || res.statusCode === 504) {
|
|
162
|
+
_emit('error', new Event('error', { status: res.statusCode, message: res.statusMessage }));
|
|
163
|
+
onConnectionClosed();
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
// Handle HTTP redirects
|
|
167
|
+
if (res.statusCode === 301 || res.statusCode === 302 || res.statusCode === 307) {
|
|
168
|
+
var location = res.headers.location;
|
|
169
|
+
if (!location) {
|
|
170
|
+
// Server sent redirect response without Location header.
|
|
171
|
+
_emit('error', new Event('error', { status: res.statusCode, message: res.statusMessage }));
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
var prevOrigin = getOrigin(url);
|
|
175
|
+
var nextOrigin = getOrigin(location);
|
|
176
|
+
hasNewOrigin = prevOrigin !== nextOrigin;
|
|
177
|
+
if (res.statusCode === 307)
|
|
178
|
+
reconnectUrl = url;
|
|
179
|
+
url = location;
|
|
180
|
+
process.nextTick(connect);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (res.statusCode !== 200) {
|
|
184
|
+
_emit('error', new Event('error', { status: res.statusCode, message: res.statusMessage }));
|
|
185
|
+
return self.close();
|
|
186
|
+
}
|
|
187
|
+
readyState = EventSource.OPEN;
|
|
188
|
+
res.on('close', function () {
|
|
189
|
+
res.removeAllListeners('close');
|
|
190
|
+
res.removeAllListeners('end');
|
|
191
|
+
onConnectionClosed();
|
|
192
|
+
});
|
|
193
|
+
res.on('end', function () {
|
|
194
|
+
res.removeAllListeners('close');
|
|
195
|
+
res.removeAllListeners('end');
|
|
196
|
+
onConnectionClosed();
|
|
197
|
+
});
|
|
198
|
+
_emit('open', new Event('open'));
|
|
199
|
+
// text/event-stream parser adapted from webkit's
|
|
200
|
+
// Source/WebCore/page/EventSource.cpp
|
|
201
|
+
var isFirst = true;
|
|
202
|
+
var buf;
|
|
203
|
+
var startingPos = 0;
|
|
204
|
+
var startingFieldLength = -1;
|
|
205
|
+
res.on('data', function (chunk) {
|
|
206
|
+
buf = buf ? Buffer.concat([buf, chunk]) : chunk;
|
|
207
|
+
if (isFirst && hasBom(buf)) {
|
|
208
|
+
buf = buf.slice(bom.length);
|
|
209
|
+
}
|
|
210
|
+
isFirst = false;
|
|
211
|
+
var pos = 0;
|
|
212
|
+
var length = buf.length;
|
|
213
|
+
while (pos < length) {
|
|
214
|
+
if (discardTrailingNewline) {
|
|
215
|
+
if (buf[pos] === lineFeed) {
|
|
216
|
+
++pos;
|
|
217
|
+
}
|
|
218
|
+
discardTrailingNewline = false;
|
|
219
|
+
}
|
|
220
|
+
var lineLength = -1;
|
|
221
|
+
var fieldLength = startingFieldLength;
|
|
222
|
+
var c;
|
|
223
|
+
for (var i = startingPos; lineLength < 0 && i < length; ++i) {
|
|
224
|
+
c = buf[i];
|
|
225
|
+
if (c === colon) {
|
|
226
|
+
if (fieldLength < 0) {
|
|
227
|
+
fieldLength = i - pos;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
else if (c === carriageReturn) {
|
|
231
|
+
discardTrailingNewline = true;
|
|
232
|
+
lineLength = i - pos;
|
|
233
|
+
}
|
|
234
|
+
else if (c === lineFeed) {
|
|
235
|
+
lineLength = i - pos;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (lineLength < 0) {
|
|
239
|
+
startingPos = length - pos;
|
|
240
|
+
startingFieldLength = fieldLength;
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
startingPos = 0;
|
|
245
|
+
startingFieldLength = -1;
|
|
246
|
+
}
|
|
247
|
+
parseEventStreamLine(buf, pos, fieldLength, lineLength);
|
|
248
|
+
pos += lineLength + 1;
|
|
249
|
+
}
|
|
250
|
+
if (pos === length) {
|
|
251
|
+
buf = void 0;
|
|
252
|
+
}
|
|
253
|
+
else if (pos > 0) {
|
|
254
|
+
buf = buf.slice(pos);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
req.on('error', function (err) {
|
|
259
|
+
self.connectionInProgress = false;
|
|
260
|
+
onConnectionClosed(err.message);
|
|
261
|
+
});
|
|
262
|
+
if (req.setNoDelay)
|
|
263
|
+
req.setNoDelay(true);
|
|
264
|
+
req.end();
|
|
265
|
+
}
|
|
266
|
+
connect();
|
|
267
|
+
function _emit() {
|
|
268
|
+
if (self.listeners(arguments[0]).length > 0) {
|
|
269
|
+
self.emit.apply(self, arguments);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
this._close = function () {
|
|
273
|
+
if (readyState === EventSource.CLOSED)
|
|
274
|
+
return;
|
|
275
|
+
readyState = EventSource.CLOSED;
|
|
276
|
+
if (req.abort)
|
|
277
|
+
req.abort();
|
|
278
|
+
if (req.xhr && req.xhr.abort)
|
|
279
|
+
req.xhr.abort();
|
|
280
|
+
};
|
|
281
|
+
function parseEventStreamLine(buf, pos, fieldLength, lineLength) {
|
|
282
|
+
if (lineLength === 0) {
|
|
283
|
+
if (data.length > 0) {
|
|
284
|
+
var type = eventName || 'message';
|
|
285
|
+
_emit(type, new MessageEvent(type, {
|
|
286
|
+
data: data.slice(0, -1),
|
|
287
|
+
lastEventId: lastEventId,
|
|
288
|
+
origin: getOrigin(url)
|
|
289
|
+
}));
|
|
290
|
+
data = '';
|
|
291
|
+
}
|
|
292
|
+
eventName = void 0;
|
|
293
|
+
}
|
|
294
|
+
else if (fieldLength > 0) {
|
|
295
|
+
var noValue = fieldLength < 0;
|
|
296
|
+
var step = 0;
|
|
297
|
+
var field = buf.slice(pos, pos + (noValue ? lineLength : fieldLength)).toString();
|
|
298
|
+
if (noValue) {
|
|
299
|
+
step = lineLength;
|
|
300
|
+
}
|
|
301
|
+
else if (buf[pos + fieldLength + 1] !== space) {
|
|
302
|
+
step = fieldLength + 1;
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
step = fieldLength + 2;
|
|
306
|
+
}
|
|
307
|
+
pos += step;
|
|
308
|
+
var valueLength = lineLength - step;
|
|
309
|
+
var value = buf.slice(pos, pos + valueLength).toString();
|
|
310
|
+
if (field === 'data') {
|
|
311
|
+
data += value + '\n';
|
|
312
|
+
}
|
|
313
|
+
else if (field === 'event') {
|
|
314
|
+
eventName = value;
|
|
315
|
+
}
|
|
316
|
+
else if (field === 'id') {
|
|
317
|
+
lastEventId = value;
|
|
318
|
+
}
|
|
319
|
+
else if (field === 'retry') {
|
|
320
|
+
var retry = parseInt(value, 10);
|
|
321
|
+
if (!Number.isNaN(retry)) {
|
|
322
|
+
self.reconnectInterval = retry;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
module.exports = EventSource;
|
|
329
|
+
util.inherits(EventSource, events.EventEmitter);
|
|
330
|
+
EventSource.prototype.constructor = EventSource; // make stacktraces readable
|
|
331
|
+
['open', 'error', 'message'].forEach(function (method) {
|
|
332
|
+
Object.defineProperty(EventSource.prototype, 'on' + method, {
|
|
333
|
+
/**
|
|
334
|
+
* Returns the current listener
|
|
335
|
+
*
|
|
336
|
+
* @return {Mixed} the set function or undefined
|
|
337
|
+
* @api private
|
|
338
|
+
*/
|
|
339
|
+
get: function get() {
|
|
340
|
+
var listener = this.listeners(method)[0];
|
|
341
|
+
return listener ? (listener._listener ? listener._listener : listener) : undefined;
|
|
342
|
+
},
|
|
343
|
+
/**
|
|
344
|
+
* Start listening for events
|
|
345
|
+
*
|
|
346
|
+
* @param {Function} listener the listener
|
|
347
|
+
* @return {Mixed} the set function or undefined
|
|
348
|
+
* @api private
|
|
349
|
+
*/
|
|
350
|
+
set: function set(listener) {
|
|
351
|
+
this.removeAllListeners(method);
|
|
352
|
+
this.addEventListener(method, listener);
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
/**
|
|
357
|
+
* Ready states
|
|
358
|
+
*/
|
|
359
|
+
Object.defineProperty(EventSource, 'CONNECTING', { enumerable: true, value: 0 });
|
|
360
|
+
Object.defineProperty(EventSource, 'OPEN', { enumerable: true, value: 1 });
|
|
361
|
+
Object.defineProperty(EventSource, 'CLOSED', { enumerable: true, value: 2 });
|
|
362
|
+
EventSource.prototype.CONNECTING = 0;
|
|
363
|
+
EventSource.prototype.OPEN = 1;
|
|
364
|
+
EventSource.prototype.CLOSED = 2;
|
|
365
|
+
/**
|
|
366
|
+
* Closes the connection, if one is made, and sets the readyState attribute to 2 (closed)
|
|
367
|
+
*
|
|
368
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/EventSource/close
|
|
369
|
+
* @api public
|
|
370
|
+
*/
|
|
371
|
+
EventSource.prototype.close = function () {
|
|
372
|
+
this._close();
|
|
373
|
+
};
|
|
374
|
+
/**
|
|
375
|
+
* Emulates the W3C Browser based WebSocket interface using addEventListener.
|
|
376
|
+
*
|
|
377
|
+
* @param {String} type A string representing the event type to listen out for
|
|
378
|
+
* @param {Function} listener callback
|
|
379
|
+
* @see https://developer.mozilla.org/en/DOM/element.addEventListener
|
|
380
|
+
* @see http://dev.w3.org/html5/websockets/#the-websocket-interface
|
|
381
|
+
* @api public
|
|
382
|
+
*/
|
|
383
|
+
EventSource.prototype.addEventListener = function addEventListener(type, listener) {
|
|
384
|
+
if (typeof listener === 'function') {
|
|
385
|
+
// store a reference so we can return the original function again
|
|
386
|
+
listener._listener = listener;
|
|
387
|
+
this.on(type, listener);
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
/**
|
|
391
|
+
* Emulates the W3C Browser based WebSocket interface using dispatchEvent.
|
|
392
|
+
*
|
|
393
|
+
* @param {Event} event An event to be dispatched
|
|
394
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent
|
|
395
|
+
* @api public
|
|
396
|
+
*/
|
|
397
|
+
EventSource.prototype.dispatchEvent = function dispatchEvent(event) {
|
|
398
|
+
if (!event.type) {
|
|
399
|
+
throw new Error('UNSPECIFIED_EVENT_TYPE_ERR');
|
|
400
|
+
}
|
|
401
|
+
// if event is instance of an CustomEvent (or has 'details' property),
|
|
402
|
+
// send the detail object as the payload for the event
|
|
403
|
+
this.emit(event.type, event.detail);
|
|
404
|
+
};
|
|
405
|
+
/**
|
|
406
|
+
* Emulates the W3C Browser based WebSocket interface using removeEventListener.
|
|
407
|
+
*
|
|
408
|
+
* @param {String} type A string representing the event type to remove
|
|
409
|
+
* @param {Function} listener callback
|
|
410
|
+
* @see https://developer.mozilla.org/en/DOM/element.removeEventListener
|
|
411
|
+
* @see http://dev.w3.org/html5/websockets/#the-websocket-interface
|
|
412
|
+
* @api public
|
|
413
|
+
*/
|
|
414
|
+
EventSource.prototype.removeEventListener = function removeEventListener(type, listener) {
|
|
415
|
+
if (typeof listener === 'function') {
|
|
416
|
+
listener._listener = undefined;
|
|
417
|
+
this.removeListener(type, listener);
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
/**
|
|
421
|
+
* W3C Event
|
|
422
|
+
*
|
|
423
|
+
* @see http://www.w3.org/TR/DOM-Level-3-Events/#interface-Event
|
|
424
|
+
* @api private
|
|
425
|
+
*/
|
|
426
|
+
function Event(type, optionalProperties) {
|
|
427
|
+
Object.defineProperty(this, 'type', { writable: false, value: type, enumerable: true });
|
|
428
|
+
if (optionalProperties) {
|
|
429
|
+
for (var f in optionalProperties) {
|
|
430
|
+
if (optionalProperties.hasOwnProperty(f)) {
|
|
431
|
+
Object.defineProperty(this, f, { writable: false, value: optionalProperties[f], enumerable: true });
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* W3C MessageEvent
|
|
438
|
+
*
|
|
439
|
+
* @see http://www.w3.org/TR/webmessaging/#event-definitions
|
|
440
|
+
* @api private
|
|
441
|
+
*/
|
|
442
|
+
function MessageEvent(type, eventInitDict) {
|
|
443
|
+
Object.defineProperty(this, 'type', { writable: false, value: type, enumerable: true });
|
|
444
|
+
for (var f in eventInitDict) {
|
|
445
|
+
if (eventInitDict.hasOwnProperty(f)) {
|
|
446
|
+
Object.defineProperty(this, f, { writable: false, value: eventInitDict[f], enumerable: true });
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Returns a new object of headers that does not include any authorization and cookie headers
|
|
452
|
+
*
|
|
453
|
+
* @param {Object} headers An object of headers ({[headerName]: headerValue})
|
|
454
|
+
* @return {Object} a new object of headers
|
|
455
|
+
* @api private
|
|
456
|
+
*/
|
|
457
|
+
function removeUnsafeHeaders(headers) {
|
|
458
|
+
var safe = {};
|
|
459
|
+
for (var key in headers) {
|
|
460
|
+
if (/^(cookie|authorization)$/i.test(key)) {
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
safe[key] = headers[key];
|
|
464
|
+
}
|
|
465
|
+
return safe;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Transform an URL to a valid origin value.
|
|
469
|
+
*
|
|
470
|
+
* @param {String|Object} url URL to transform to it's origin.
|
|
471
|
+
* @returns {String} The origin.
|
|
472
|
+
* @api private
|
|
473
|
+
*/
|
|
474
|
+
function getOrigin(url) {
|
|
475
|
+
if (typeof url === 'string')
|
|
476
|
+
url = parse(url);
|
|
477
|
+
if (!url.protocol || !url.hostname)
|
|
478
|
+
return 'null';
|
|
479
|
+
return (url.protocol + '//' + url.host).toLowerCase();
|
|
480
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEventSource = exports.__restore = exports.__setEventSource = void 0;
|
|
4
|
+
var __isCustom = false;
|
|
5
|
+
var __eventSource;
|
|
6
|
+
// This function is only exposed for testing purposes.
|
|
7
|
+
function __setEventSource(eventSource) {
|
|
8
|
+
__eventSource = eventSource;
|
|
9
|
+
__isCustom = true;
|
|
10
|
+
}
|
|
11
|
+
exports.__setEventSource = __setEventSource;
|
|
12
|
+
function __restore() {
|
|
13
|
+
__isCustom = false;
|
|
14
|
+
}
|
|
15
|
+
exports.__restore = __restore;
|
|
16
|
+
function getEventSource() {
|
|
17
|
+
// returns EventSource at `eventsource` package. If not available, return global EventSource or undefined
|
|
18
|
+
try {
|
|
19
|
+
return __isCustom ? __eventSource : require('./eventsource');
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
// eslint-disable-next-line no-undef -- Feature detection for EventSource
|
|
23
|
+
return typeof EventSource === 'function' ? EventSource : undefined;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.getEventSource = getEventSource;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFetch = void 0;
|
|
4
|
+
// It doesn't return a ponyfill if global fetch is not available
|
|
5
|
+
function getFetch() {
|
|
6
|
+
// eslint-disable-next-line no-undef
|
|
7
|
+
return typeof fetch === 'function' ? fetch : undefined;
|
|
8
|
+
}
|
|
9
|
+
exports.getFetch = getFetch;
|