@splitsoftware/splitio-commons 1.17.1-rc.2 → 2.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.
Files changed (195) hide show
  1. package/CHANGES.txt +7 -3
  2. package/cjs/evaluator/index.js +2 -2
  3. package/cjs/evaluator/matchers/semver_inlist.js +1 -2
  4. package/cjs/evaluator/matchers/whitelist.js +1 -2
  5. package/cjs/listeners/browser.js +1 -2
  6. package/cjs/logger/browser/DebugLogger.js +1 -2
  7. package/cjs/logger/browser/ErrorLogger.js +1 -2
  8. package/cjs/logger/browser/InfoLogger.js +1 -2
  9. package/cjs/logger/browser/WarnLogger.js +1 -2
  10. package/cjs/logger/index.js +1 -2
  11. package/cjs/sdkClient/clientCS.js +5 -8
  12. package/cjs/sdkClient/sdkClientMethodCS.js +1 -1
  13. package/cjs/sdkFactory/index.js +1 -3
  14. package/cjs/services/decorateHeaders.js +1 -2
  15. package/cjs/storages/AbstractSplitsCacheAsync.js +7 -0
  16. package/cjs/storages/AbstractSplitsCacheSync.js +7 -0
  17. package/cjs/storages/KeyBuilderCS.js +0 -9
  18. package/cjs/storages/dataLoader.js +32 -65
  19. package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -21
  20. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +14 -7
  21. package/cjs/storages/inLocalStorage/index.js +1 -4
  22. package/cjs/storages/inMemory/InMemoryStorageCS.js +4 -16
  23. package/cjs/storages/inMemory/SegmentsCacheInMemory.js +3 -4
  24. package/cjs/storages/inMemory/SplitsCacheInMemory.js +2 -3
  25. package/cjs/storages/inMemory/UniqueKeysCacheInMemory.js +2 -3
  26. package/cjs/storages/inMemory/UniqueKeysCacheInMemoryCS.js +2 -3
  27. package/cjs/storages/inRedis/RedisAdapter.js +2 -3
  28. package/cjs/storages/inRedis/SplitsCacheInRedis.js +1 -1
  29. package/cjs/storages/inRedis/TelemetryCacheInRedis.js +3 -4
  30. package/cjs/storages/inRedis/UniqueKeysCacheInRedis.js +1 -2
  31. package/cjs/storages/pluggable/SplitsCachePluggable.js +1 -1
  32. package/cjs/storages/pluggable/TelemetryCachePluggable.js +6 -7
  33. package/cjs/storages/pluggable/UniqueKeysCachePluggable.js +1 -2
  34. package/cjs/storages/pluggable/inMemoryWrapper.js +7 -8
  35. package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +7 -2
  36. package/cjs/sync/polling/pollingManagerSS.js +3 -3
  37. package/cjs/sync/polling/updaters/splitChangesUpdater.js +13 -5
  38. package/cjs/sync/streaming/parseUtils.js +0 -1
  39. package/cjs/sync/streaming/pushManager.js +2 -3
  40. package/cjs/utils/LRUCache/index.js +1 -2
  41. package/cjs/utils/constants/browser.js +1 -4
  42. package/cjs/utils/lang/index.js +6 -9
  43. package/cjs/utils/lang/objectAssign.js +12 -77
  44. package/cjs/utils/lang/sets.js +3 -110
  45. package/cjs/utils/settingsValidation/index.js +0 -9
  46. package/cjs/utils/settingsValidation/logger/builtinLogger.js +1 -2
  47. package/cjs/utils/settingsValidation/storage/storageCS.js +12 -1
  48. package/esm/evaluator/index.js +3 -3
  49. package/esm/evaluator/matchers/semver_inlist.js +1 -2
  50. package/esm/evaluator/matchers/whitelist.js +1 -2
  51. package/esm/listeners/browser.js +1 -2
  52. package/esm/logger/browser/DebugLogger.js +1 -2
  53. package/esm/logger/browser/ErrorLogger.js +1 -2
  54. package/esm/logger/browser/InfoLogger.js +1 -2
  55. package/esm/logger/browser/WarnLogger.js +1 -2
  56. package/esm/logger/index.js +1 -2
  57. package/esm/sdkClient/clientCS.js +5 -8
  58. package/esm/sdkClient/sdkClientMethodCS.js +1 -1
  59. package/esm/sdkFactory/index.js +2 -4
  60. package/esm/services/decorateHeaders.js +1 -2
  61. package/esm/storages/AbstractSplitsCacheAsync.js +7 -0
  62. package/esm/storages/AbstractSplitsCacheSync.js +7 -0
  63. package/esm/storages/KeyBuilderCS.js +0 -9
  64. package/esm/storages/dataLoader.js +30 -62
  65. package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -21
  66. package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +14 -7
  67. package/esm/storages/inLocalStorage/index.js +2 -5
  68. package/esm/storages/inMemory/InMemoryStorageCS.js +4 -16
  69. package/esm/storages/inMemory/SegmentsCacheInMemory.js +3 -4
  70. package/esm/storages/inMemory/SplitsCacheInMemory.js +2 -3
  71. package/esm/storages/inMemory/UniqueKeysCacheInMemory.js +2 -3
  72. package/esm/storages/inMemory/UniqueKeysCacheInMemoryCS.js +2 -3
  73. package/esm/storages/inRedis/RedisAdapter.js +2 -3
  74. package/esm/storages/inRedis/SplitsCacheInRedis.js +2 -2
  75. package/esm/storages/inRedis/TelemetryCacheInRedis.js +3 -4
  76. package/esm/storages/inRedis/UniqueKeysCacheInRedis.js +1 -2
  77. package/esm/storages/pluggable/SplitsCachePluggable.js +2 -2
  78. package/esm/storages/pluggable/TelemetryCachePluggable.js +6 -7
  79. package/esm/storages/pluggable/UniqueKeysCachePluggable.js +1 -2
  80. package/esm/storages/pluggable/inMemoryWrapper.js +7 -8
  81. package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +8 -3
  82. package/esm/sync/polling/pollingManagerSS.js +3 -3
  83. package/esm/sync/polling/updaters/splitChangesUpdater.js +14 -6
  84. package/esm/sync/streaming/parseUtils.js +0 -1
  85. package/esm/sync/streaming/pushManager.js +2 -3
  86. package/esm/utils/LRUCache/index.js +1 -2
  87. package/esm/utils/constants/browser.js +0 -3
  88. package/esm/utils/lang/index.js +6 -9
  89. package/esm/utils/lang/objectAssign.js +12 -77
  90. package/esm/utils/lang/sets.js +2 -107
  91. package/esm/utils/settingsValidation/index.js +0 -9
  92. package/esm/utils/settingsValidation/logger/builtinLogger.js +1 -2
  93. package/esm/utils/settingsValidation/storage/storageCS.js +10 -0
  94. package/package.json +2 -2
  95. package/src/evaluator/index.ts +5 -5
  96. package/src/evaluator/matchers/semver_inlist.ts +1 -2
  97. package/src/evaluator/matchers/whitelist.ts +1 -3
  98. package/src/listeners/browser.ts +1 -2
  99. package/src/logger/browser/DebugLogger.ts +1 -2
  100. package/src/logger/browser/ErrorLogger.ts +1 -2
  101. package/src/logger/browser/InfoLogger.ts +1 -2
  102. package/src/logger/browser/WarnLogger.ts +1 -2
  103. package/src/logger/index.ts +3 -4
  104. package/src/sdkClient/clientCS.ts +5 -8
  105. package/src/sdkClient/sdkClientMethodCS.ts +1 -1
  106. package/src/sdkFactory/index.ts +2 -5
  107. package/src/sdkFactory/types.ts +1 -1
  108. package/src/services/decorateHeaders.ts +1 -2
  109. package/src/storages/AbstractSplitsCacheAsync.ts +9 -2
  110. package/src/storages/AbstractSplitsCacheSync.ts +9 -2
  111. package/src/storages/KeyBuilderCS.ts +0 -13
  112. package/src/storages/dataLoader.ts +32 -63
  113. package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +1 -21
  114. package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +16 -8
  115. package/src/storages/inLocalStorage/index.ts +2 -6
  116. package/src/storages/inMemory/InMemoryStorageCS.ts +4 -19
  117. package/src/storages/inMemory/SegmentsCacheInMemory.ts +4 -5
  118. package/src/storages/inMemory/SplitsCacheInMemory.ts +4 -5
  119. package/src/storages/inMemory/UniqueKeysCacheInMemory.ts +4 -5
  120. package/src/storages/inMemory/UniqueKeysCacheInMemoryCS.ts +4 -5
  121. package/src/storages/inRedis/RedisAdapter.ts +3 -4
  122. package/src/storages/inRedis/SplitsCacheInRedis.ts +3 -3
  123. package/src/storages/inRedis/TelemetryCacheInRedis.ts +3 -4
  124. package/src/storages/inRedis/UniqueKeysCacheInRedis.ts +1 -2
  125. package/src/storages/pluggable/SegmentsCachePluggable.ts +0 -1
  126. package/src/storages/pluggable/SplitsCachePluggable.ts +3 -3
  127. package/src/storages/pluggable/TelemetryCachePluggable.ts +6 -7
  128. package/src/storages/pluggable/UniqueKeysCachePluggable.ts +1 -2
  129. package/src/storages/pluggable/inMemoryWrapper.ts +8 -9
  130. package/src/storages/types.ts +9 -5
  131. package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +7 -3
  132. package/src/sync/polling/pollingManagerSS.ts +2 -3
  133. package/src/sync/polling/updaters/splitChangesUpdater.ts +15 -8
  134. package/src/sync/streaming/parseUtils.ts +0 -1
  135. package/src/sync/streaming/pushManager.ts +3 -4
  136. package/src/sync/submitters/types.ts +3 -4
  137. package/src/types.ts +9 -18
  138. package/src/utils/LRUCache/index.ts +2 -3
  139. package/src/utils/constants/browser.ts +0 -4
  140. package/src/utils/lang/index.ts +6 -7
  141. package/src/utils/lang/objectAssign.ts +13 -92
  142. package/src/utils/lang/sets.ts +3 -125
  143. package/src/utils/settingsValidation/index.ts +0 -10
  144. package/src/utils/settingsValidation/logger/builtinLogger.ts +1 -2
  145. package/src/utils/settingsValidation/storage/storageCS.ts +13 -0
  146. package/src/utils/settingsValidation/types.ts +0 -2
  147. package/types/logger/index.d.ts +1 -2
  148. package/types/sdkClient/clientCS.d.ts +2 -3
  149. package/types/sdkFactory/types.d.ts +1 -1
  150. package/types/storages/AbstractSplitsCacheAsync.d.ts +6 -2
  151. package/types/storages/AbstractSplitsCacheSync.d.ts +6 -2
  152. package/types/storages/KeyBuilderCS.d.ts +0 -2
  153. package/types/storages/dataLoader.d.ts +6 -17
  154. package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +7 -2
  155. package/types/storages/inMemory/SplitsCacheInMemory.d.ts +1 -2
  156. package/types/storages/inMemory/UniqueKeysCacheInMemory.d.ts +2 -3
  157. package/types/storages/inRedis/SplitsCacheInRedis.d.ts +1 -2
  158. package/types/storages/pluggable/SplitsCachePluggable.d.ts +1 -2
  159. package/types/storages/pluggable/inMemoryWrapper.d.ts +1 -2
  160. package/types/storages/types.d.ts +7 -5
  161. package/types/sync/polling/updaters/splitChangesUpdater.d.ts +1 -2
  162. package/types/sync/submitters/types.d.ts +3 -4
  163. package/types/types.d.ts +9 -17
  164. package/types/utils/LRUCache/index.d.ts +1 -2
  165. package/types/utils/constants/browser.d.ts +0 -2
  166. package/types/utils/lang/objectAssign.d.ts +3 -0
  167. package/types/utils/lang/sets.d.ts +1 -61
  168. package/types/utils/settingsValidation/index.d.ts +0 -1
  169. package/types/utils/settingsValidation/storage/storageCS.d.ts +5 -0
  170. package/types/utils/settingsValidation/types.d.ts +0 -2
  171. package/cjs/integrations/browser.js +0 -31
  172. package/cjs/integrations/ga/GaToSplit.js +0 -257
  173. package/cjs/integrations/ga/GoogleAnalyticsToSplit.js +0 -14
  174. package/cjs/integrations/ga/SplitToGa.js +0 -123
  175. package/cjs/integrations/ga/SplitToGoogleAnalytics.js +0 -14
  176. package/cjs/integrations/ga/types.js +0 -2
  177. package/cjs/sdkClient/sdkClientMethodCSWithTT.js +0 -76
  178. package/cjs/utils/lang/maps.js +0 -96
  179. package/esm/integrations/browser.js +0 -27
  180. package/esm/integrations/ga/GaToSplit.js +0 -250
  181. package/esm/integrations/ga/GoogleAnalyticsToSplit.js +0 -10
  182. package/esm/integrations/ga/SplitToGa.js +0 -120
  183. package/esm/integrations/ga/SplitToGoogleAnalytics.js +0 -10
  184. package/esm/integrations/ga/types.js +0 -1
  185. package/esm/sdkClient/sdkClientMethodCSWithTT.js +0 -72
  186. package/esm/utils/lang/maps.js +0 -92
  187. package/src/integrations/browser.ts +0 -35
  188. package/src/integrations/ga/GaToSplit.ts +0 -299
  189. package/src/integrations/ga/GoogleAnalyticsToSplit.ts +0 -14
  190. package/src/integrations/ga/SplitToGa.ts +0 -135
  191. package/src/integrations/ga/SplitToGoogleAnalytics.ts +0 -14
  192. package/src/integrations/ga/autoRequire.js +0 -33
  193. package/src/integrations/ga/types.ts +0 -153
  194. package/src/sdkClient/sdkClientMethodCSWithTT.ts +0 -98
  195. package/src/utils/lang/maps.ts +0 -108
@@ -1,96 +0,0 @@
1
- "use strict";
2
- /**
3
- * Map implementation based on es6-map polyfill (https://github.com/medikoo/es6-map/blob/master/polyfill.js),
4
- * with the minimal features used by the SDK.
5
-
6
- Copyright (C) 2013 Mariusz Nowak (www.medikoo.com)
7
-
8
- Permission is hereby granted, free of charge, to any person obtaining a copy
9
- of this software and associated documentation files (the "Software"), to deal
10
- in the Software without restriction, including without limitation the rights
11
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- copies of the Software, and to permit persons to whom the Software is
13
- furnished to do so, subject to the following conditions:
14
-
15
- The above copyright notice and this permission notice shall be included in
16
- all copies or substantial portions of the Software.
17
-
18
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
- THE SOFTWARE.
25
- **/
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- exports._Map = exports.__getMapConstructor = exports.MapPoly = void 0;
28
- var MapPoly = /** @class */ (function () {
29
- // unlike ES6 `Map`, it only accepts an array as first argument iterable
30
- function MapPoly(entries) {
31
- var _this = this;
32
- this.__mapKeysData__ = [];
33
- this.__mapValuesData__ = [];
34
- if (Array.isArray(entries))
35
- entries.forEach(function (entry) { _this.set(entry[0], entry[1]); });
36
- }
37
- MapPoly.prototype.clear = function () {
38
- if (!this.__mapKeysData__.length)
39
- return;
40
- this.__mapKeysData__.length = 0;
41
- this.__mapValuesData__.length = 0;
42
- };
43
- MapPoly.prototype.delete = function (key) {
44
- var index = this.__mapKeysData__.indexOf(key);
45
- if (index === -1)
46
- return false;
47
- this.__mapKeysData__.splice(index, 1);
48
- this.__mapValuesData__.splice(index, 1);
49
- return true;
50
- };
51
- MapPoly.prototype.forEach = function (callbackfn, thisArg) {
52
- for (var i = 0; i < this.__mapKeysData__.length; i++) {
53
- callbackfn.call(thisArg, this.__mapValuesData__[i], this.__mapKeysData__[i], this);
54
- }
55
- };
56
- MapPoly.prototype.get = function (key) {
57
- var index = this.__mapKeysData__.indexOf(key);
58
- if (index === -1)
59
- return;
60
- return this.__mapValuesData__[index];
61
- };
62
- MapPoly.prototype.has = function (key) {
63
- return this.__mapKeysData__.indexOf(key) !== -1;
64
- };
65
- MapPoly.prototype.set = function (key, value) {
66
- var index = this.__mapKeysData__.indexOf(key);
67
- if (index === -1)
68
- index = this.__mapKeysData__.push(key) - 1;
69
- this.__mapValuesData__[index] = value;
70
- return this;
71
- };
72
- Object.defineProperty(MapPoly.prototype, "size", {
73
- get: function () {
74
- return this.__mapKeysData__.length;
75
- },
76
- enumerable: false,
77
- configurable: true
78
- });
79
- return MapPoly;
80
- }());
81
- exports.MapPoly = MapPoly;
82
- /**
83
- * return the Map constructor to use. If native Map is not available or it doesn't support the required features (e.g., IE11),
84
- * a ponyfill with minimal features is returned instead.
85
- *
86
- * Exported for testing purposes only.
87
- */
88
- function __getMapConstructor() {
89
- // eslint-disable-next-line compat/compat
90
- if (typeof Array.from === 'function' && typeof Map === 'function' && Map.prototype && Map.prototype.values) {
91
- return Map;
92
- }
93
- return MapPoly;
94
- }
95
- exports.__getMapConstructor = __getMapConstructor;
96
- exports._Map = __getMapConstructor();
@@ -1,27 +0,0 @@
1
- import { GOOGLE_ANALYTICS_TO_SPLIT, SPLIT_TO_GOOGLE_ANALYTICS } from '../utils/constants/browser';
2
- import { pluggableIntegrationsManagerFactory } from './pluggable';
3
- import { GoogleAnalyticsToSplit } from './ga/GoogleAnalyticsToSplit';
4
- import { SplitToGoogleAnalytics } from './ga/SplitToGoogleAnalytics';
5
- /**
6
- * IntegrationsManager factory for the browser variant of the isomorphic JS SDK.
7
- * The integrations manager instantiates integration modules, and bypass tracked events and impressions to them.
8
- *
9
- * @param integrations valid integration settings object for browser sdk
10
- * @param params information of the Sdk factory instance that integrations can access to
11
- *
12
- * @returns integration manager or undefined if `integrations` are not present in settings.
13
- */
14
- export function integrationsManagerFactory(integrations, params) {
15
- // maps integration config items into integration factories to reuse the pluggable integration manager
16
- var integrationFactories = integrations
17
- .map(function (integrationOptions) {
18
- switch (integrationOptions.type) {
19
- case GOOGLE_ANALYTICS_TO_SPLIT: return GoogleAnalyticsToSplit(integrationOptions);
20
- case SPLIT_TO_GOOGLE_ANALYTICS: return SplitToGoogleAnalytics(integrationOptions);
21
- }
22
- })
23
- .filter(function (integrationFactory) {
24
- return integrationFactory && typeof integrationFactory === 'function';
25
- });
26
- return pluggableIntegrationsManagerFactory(integrationFactories, params);
27
- }
@@ -1,250 +0,0 @@
1
- import { objectAssign } from '../../utils/lang/objectAssign';
2
- import { isString, isFiniteNumber, uniqAsStrings } from '../../utils/lang';
3
- import { validateEvent, validateEventValue, validateEventProperties, validateKey, validateTrafficType } from '../../utils/inputValidation';
4
- var logPrefix = 'ga-to-split: ';
5
- var logNameMapper = 'ga-to-split:mapper';
6
- /**
7
- * Provides a plugin to use with analytics.js, accounting for the possibility
8
- * that the global command queue has been renamed or not yet defined.
9
- * @param window Reference to global object.
10
- * @param pluginName The plugin name identifier.
11
- * @param pluginConstructor The plugin constructor function.
12
- * @param log Logger instance.
13
- * @param autoRequire If true, log error when auto-require script is not detected
14
- */
15
- function providePlugin(window, pluginName, pluginConstructor, log, autoRequire, telemetryTracker) {
16
- // get reference to global command queue. Init it if not defined yet.
17
- var gaAlias = window.GoogleAnalyticsObject || 'ga';
18
- window[gaAlias] = window[gaAlias] || function () {
19
- (window[gaAlias].q = window[gaAlias].q || []).push(arguments);
20
- };
21
- // provides the plugin for use with analytics.js.
22
- window[gaAlias]('provide', pluginName, pluginConstructor);
23
- var hasAutoRequire = window[gaAlias].q && window[gaAlias].q.push !== [].push;
24
- if (autoRequire && !hasAutoRequire) { // Expecting spy on ga.q push method but not found
25
- log.error(logPrefix + 'integration is configured to autorequire the splitTracker plugin, but the necessary script does not seem to have run. Please check the docs.');
26
- }
27
- if (telemetryTracker && hasAutoRequire) {
28
- telemetryTracker.addTag('integration:ga-autorequire');
29
- }
30
- }
31
- // Default mapping: object used for building the default mapper from hits to Split events
32
- var defaultMapping = {
33
- eventTypeId: {
34
- event: 'eventAction',
35
- social: 'socialAction',
36
- },
37
- eventValue: {
38
- event: 'eventValue',
39
- timing: 'timingValue',
40
- },
41
- eventProperties: {
42
- pageview: ['page'],
43
- screenview: ['screenName'],
44
- event: ['eventCategory', 'eventLabel'],
45
- social: ['socialNetwork', 'socialTarget'],
46
- timing: ['timingCategory', 'timingVar', 'timingLabel'],
47
- exception: ['exDescription', 'exFatal'],
48
- }
49
- };
50
- /**
51
- * Build a mapper function based on a mapping object
52
- *
53
- * @param {object} mapping
54
- */
55
- function mapperBuilder(mapping) {
56
- return function (model) {
57
- var hitType = model.get('hitType');
58
- // @ts-expect-error
59
- var eventTypeId = model.get(mapping.eventTypeId[hitType] || 'hitType');
60
- // @ts-expect-error
61
- var value = model.get(mapping.eventValue[hitType]);
62
- var properties = {}; // @ts-expect-error
63
- var fields = mapping.eventProperties[hitType];
64
- if (fields) {
65
- for (var i = 0; i < fields.length; i++) {
66
- var fieldValue = model.get(fields[i]);
67
- if (fieldValue !== undefined)
68
- properties[fields[i]] = fieldValue;
69
- }
70
- }
71
- return {
72
- eventTypeId: eventTypeId,
73
- value: value,
74
- properties: properties,
75
- timestamp: Date.now(),
76
- };
77
- };
78
- }
79
- // exposed for unit testing purposses.
80
- export var defaultMapper = mapperBuilder(defaultMapping);
81
- export var defaultPrefix = 'ga';
82
- /**
83
- * Return a new list of identities removing invalid and duplicated ones.
84
- *
85
- * @param {Array} identities list of identities
86
- * @returns list of valid and unique identities. The list might be empty if `identities` is not an array or all its elements are invalid.
87
- */
88
- export function validateIdentities(identities) {
89
- if (!Array.isArray(identities))
90
- return [];
91
- // Remove duplicated identities
92
- var uniqueIdentities = uniqAsStrings(identities);
93
- // Filter based on rum-agent identities validator
94
- return uniqueIdentities.filter(function (identity) {
95
- if (!identity)
96
- return false;
97
- var maybeKey = identity.key;
98
- var maybeTT = identity.trafficType;
99
- if (!isString(maybeKey) && !isFiniteNumber(maybeKey))
100
- return false;
101
- if (!isString(maybeTT))
102
- return false;
103
- return true;
104
- });
105
- }
106
- /**
107
- * Checks if EventData fields (except EventTypeId) are valid, and logs corresponding warnings.
108
- * EventTypeId is validated separately.
109
- *
110
- * @param {EventData} data event data instance to validate. Precondition: data != undefined
111
- * @returns {boolean} Whether the data instance is a valid EventData or not.
112
- */
113
- export function validateEventData(log, eventData) {
114
- if (!validateEvent(log, eventData.eventTypeId, logNameMapper))
115
- return false;
116
- if (validateEventValue(log, eventData.value, logNameMapper) === false)
117
- return false;
118
- var properties = validateEventProperties(log, eventData.properties, logNameMapper).properties;
119
- if (properties === false)
120
- return false;
121
- if (eventData.timestamp && !isFiniteNumber(eventData.timestamp))
122
- return false;
123
- if (eventData.key && validateKey(log, eventData.key, logNameMapper) === false)
124
- return false;
125
- if (eventData.trafficTypeName && validateTrafficType(log, eventData.trafficTypeName, logNameMapper) === false)
126
- return false;
127
- return true;
128
- }
129
- var INVALID_PREFIX_REGEX = /^[^a-zA-Z0-9]+/;
130
- var INVALID_SUBSTRING_REGEX = /[^-_.:a-zA-Z0-9]+/g;
131
- /**
132
- * Fixes the passed string value to comply with EventTypeId format, by removing invalid characters and truncating if necessary.
133
- *
134
- * @param {object} log factory logger
135
- * @param {string} eventTypeId string value to fix.
136
- * @returns {string} Fixed version of `eventTypeId`.
137
- */
138
- export function fixEventTypeId(log, eventTypeId) {
139
- // return the input eventTypeId if it cannot be fixed
140
- if (!isString(eventTypeId) || eventTypeId.length === 0) {
141
- return eventTypeId;
142
- }
143
- // replace invalid substrings and truncate
144
- var fixed = eventTypeId
145
- .replace(INVALID_PREFIX_REGEX, '')
146
- .replace(INVALID_SUBSTRING_REGEX, '_');
147
- var truncated = fixed.slice(0, 80);
148
- if (truncated.length < fixed.length)
149
- log.warn(logPrefix + 'EventTypeId was truncated because it cannot be more than 80 characters long.');
150
- return truncated;
151
- }
152
- /**
153
- * GaToSplit integration.
154
- * This function provides the SplitTracker plugin to ga command queue.
155
- *
156
- * @param {object} sdkOptions options passed at the SDK integrations settings (isomorphic SDK) or the GoogleAnalyticsToSplit plugin (pluggable browser SDK)
157
- * @param {object} storage SDK storage passed to track events
158
- * @param {object} coreSettings core settings used to define an identity if no one provided as SDK or plugin options
159
- * @param {object} log factory logger
160
- */
161
- export function GaToSplit(sdkOptions, params) {
162
- var storage = params.storage, _a = params.settings, coreSettings = _a.core, log = _a.log, telemetryTracker = params.telemetryTracker;
163
- var defaultOptions = {
164
- prefix: defaultPrefix,
165
- // We set default identities if key and TT are present in settings.core
166
- identities: (coreSettings.key && coreSettings.trafficType) ?
167
- [{ key: coreSettings.key, trafficType: coreSettings.trafficType }] :
168
- undefined
169
- };
170
- var SplitTracker = /** @class */ (function () {
171
- // Constructor for the SplitTracker plugin.
172
- function SplitTracker(tracker, pluginOptions) {
173
- // precedence of options: SDK options (config.integrations) overwrite pluginOptions (`ga('require', 'splitTracker', pluginOptions)`)
174
- var opts = objectAssign({}, defaultOptions, sdkOptions, pluginOptions);
175
- this.tracker = tracker;
176
- // Validate identities
177
- var validIdentities = validateIdentities(opts.identities);
178
- if (validIdentities.length === 0) {
179
- log.warn(logPrefix + 'No valid identities were provided. Please check that you are passing a valid list of identities or providing a traffic type at the SDK configuration.');
180
- return;
181
- }
182
- var invalids = validIdentities.length - opts.identities.length;
183
- if (invalids) {
184
- log.warn(logPrefix + (invalids + " identities were discarded because they are invalid or duplicated. Identities must be an array of objects with key and trafficType."));
185
- }
186
- opts.identities = validIdentities;
187
- // Validate prefix
188
- if (!isString(opts.prefix)) {
189
- log.warn(logPrefix + 'The provided `prefix` was ignored since it is invalid. Please check that you are passing a string object as `prefix`.');
190
- opts.prefix = undefined;
191
- }
192
- // Overwrite sendHitTask to perform plugin tasks:
193
- // 1) filter hits
194
- // 2) map hits to Split events
195
- // 3) handle events, i.e., validate and send them to Split BE
196
- var originalSendHitTask = tracker.get('sendHitTask');
197
- tracker.set('sendHitTask', function (model) {
198
- originalSendHitTask(model);
199
- // filter hit if `hits` flag is false or if it comes from Split-to-GA integration
200
- if (opts.hits === false || model.get('splitHit'))
201
- return;
202
- try {
203
- if (opts.filter && !opts.filter(model))
204
- return;
205
- }
206
- catch (err) {
207
- log.warn(logPrefix + ("custom filter threw: " + err));
208
- return;
209
- }
210
- // map hit into an EventData instance
211
- var eventData = defaultMapper(model);
212
- if (opts.mapper) {
213
- try {
214
- eventData = opts.mapper(model, eventData);
215
- }
216
- catch (err) {
217
- log.warn(logPrefix + ("custom mapper threw: " + err));
218
- return;
219
- }
220
- if (!eventData)
221
- return;
222
- }
223
- // Add prefix. Nothing is appended if the prefix is falsy, e.g. undefined or ''.
224
- if (opts.prefix)
225
- eventData.eventTypeId = opts.prefix + "." + eventData.eventTypeId;
226
- eventData.eventTypeId = fixEventTypeId(log, eventData.eventTypeId);
227
- if (!validateEventData(log, eventData))
228
- return;
229
- // Store the event
230
- if (eventData.key && eventData.trafficTypeName) {
231
- storage.events.track(eventData);
232
- }
233
- else { // Store the event for each Key-TT pair (identities), if key and TT is not present in eventData
234
- opts.identities.forEach(function (identity) {
235
- var event = objectAssign({
236
- key: identity.key,
237
- trafficTypeName: identity.trafficType,
238
- }, eventData);
239
- storage.events.track(event);
240
- });
241
- }
242
- });
243
- log.info(logPrefix + 'integration started');
244
- }
245
- return SplitTracker;
246
- }());
247
- // Register the plugin, even if config is invalid, since, if not provided, it will block `ga` command queue.
248
- // eslint-disable-next-line no-undef
249
- providePlugin(window, 'splitTracker', SplitTracker, log, sdkOptions.autoRequire === true, telemetryTracker);
250
- }
@@ -1,10 +0,0 @@
1
- import { GaToSplit } from './GaToSplit';
2
- export function GoogleAnalyticsToSplit(options) {
3
- if (options === void 0) { options = {}; }
4
- // GaToSplit integration factory
5
- function GoogleAnalyticsToSplitFactory(params) {
6
- return GaToSplit(options, params);
7
- }
8
- GoogleAnalyticsToSplitFactory.type = 'GOOGLE_ANALYTICS_TO_SPLIT';
9
- return GoogleAnalyticsToSplitFactory;
10
- }
@@ -1,120 +0,0 @@
1
- /* eslint-disable no-undef */
2
- import { uniq } from '../../utils/lang';
3
- import { SPLIT_IMPRESSION, SPLIT_EVENT } from '../../utils/constants';
4
- var logPrefix = 'split-to-ga: ';
5
- var noGaWarning = '`ga` command queue not found.';
6
- var noHit = 'No hit was sent.';
7
- var SplitToGa = /** @class */ (function () {
8
- /**
9
- * constructor description
10
- * @param {object} options options passed at the SDK integrations settings (isomorphic SDK) or the SplitToGoogleAnalytics plugin (pluggable browser SDK)
11
- */
12
- function SplitToGa(log, options) {
13
- this.trackerNames = SplitToGa.defaultTrackerNames;
14
- this.log = log;
15
- if (options) {
16
- if (typeof options.filter === 'function')
17
- this.filter = options.filter;
18
- if (typeof options.mapper === 'function')
19
- this.mapper = options.mapper;
20
- // We strip off duplicated values if we received a `trackerNames` param.
21
- // We don't warn if a tracker does not exist, since the user might create it after the SDK is initialized.
22
- // Note: GA allows to create and get trackers using a string or number as tracker name, and does nothing if other types are used.
23
- if (Array.isArray(options.trackerNames))
24
- this.trackerNames = uniq(options.trackerNames);
25
- // No need to validate `impressions` and `events` flags. Any other value than `false` is ignored (considered true by default).
26
- this.impressions = options.impressions;
27
- this.events = options.events;
28
- }
29
- log.info(logPrefix + 'integration started');
30
- if (typeof SplitToGa.getGa() !== 'function')
31
- log.warn(logPrefix + (noGaWarning + " No hits will be sent until it is available."));
32
- }
33
- // Default mapper function.
34
- SplitToGa.defaultMapper = function (_a) {
35
- var type = _a.type, payload = _a.payload;
36
- switch (type) {
37
- case SPLIT_IMPRESSION:
38
- return {
39
- hitType: 'event',
40
- eventCategory: 'split-impression',
41
- eventAction: 'Evaluate ' + payload.impression.feature,
42
- eventLabel: 'Treatment: ' + payload.impression.treatment + '. Targeting rule: ' + payload.impression.label + '.',
43
- nonInteraction: true,
44
- };
45
- case SPLIT_EVENT:
46
- return {
47
- hitType: 'event',
48
- eventCategory: 'split-event',
49
- eventAction: payload.eventTypeId,
50
- eventValue: payload.value,
51
- nonInteraction: true,
52
- };
53
- }
54
- };
55
- // Util to access ga command queue, accounting for the possibility that it has been renamed.
56
- SplitToGa.getGa = function () {
57
- return typeof window !== 'undefined' ? window[window['GoogleAnalyticsObject'] || 'ga'] : undefined;
58
- };
59
- /**
60
- * Validates if a given object is a UniversalAnalytics.FieldsObject instance, and logs a warning if not.
61
- * It checks that the object contains a `hitType`, since it is the minimal field required to send the hit
62
- * and avoid the GA error `No hit type specified. Aborting hit.`.
63
- * Other validations (e.g., an `event` hitType must have a `eventCategory` and `eventAction`) are handled
64
- * and logged (as warnings or errors depending the case) by GA debugger, but the hit is sent anyway.
65
- *
66
- * @param {object} log factory logger
67
- * @param {UniversalAnalytics.FieldsObject} fieldsObject object to validate.
68
- * @returns {boolean} Whether the data instance is a valid FieldsObject or not.
69
- */
70
- SplitToGa.validateFieldsObject = function (log, fieldsObject) {
71
- if (fieldsObject && fieldsObject.hitType)
72
- return true;
73
- log.warn(logPrefix + 'your custom mapper returned an invalid FieldsObject instance. It must be an object with at least a `hitType` field.');
74
- return false;
75
- };
76
- SplitToGa.prototype.queue = function (data) {
77
- // access ga command queue via `getGa` method, accounting for the possibility that
78
- // the global `ga` reference was not yet mutated by analytics.js.
79
- var ga = SplitToGa.getGa();
80
- if (ga) {
81
- if (this.impressions === false && data.type === SPLIT_IMPRESSION)
82
- return;
83
- if (this.events === false && data.type === SPLIT_EVENT)
84
- return;
85
- var fieldsObject_1;
86
- try { // only try/catch filter and mapper, which might be defined by the user
87
- // filter
88
- if (this.filter && !this.filter(data))
89
- return;
90
- // map data into a FieldsObject instance
91
- fieldsObject_1 = SplitToGa.defaultMapper(data);
92
- if (this.mapper) {
93
- fieldsObject_1 = this.mapper(data, fieldsObject_1);
94
- // don't send the hit if it is falsy or invalid
95
- if (!fieldsObject_1 || !SplitToGa.validateFieldsObject(this.log, fieldsObject_1))
96
- return;
97
- }
98
- }
99
- catch (err) {
100
- this.log.warn(logPrefix + ("queue method threw: " + err + ". " + noHit));
101
- return;
102
- }
103
- // send the hit
104
- this.trackerNames.forEach(function (trackerName) {
105
- var sendCommand = trackerName ? trackerName + ".send" : 'send';
106
- // mark the hit as a Split one to avoid the loop.
107
- fieldsObject_1.splitHit = true;
108
- // Send to GA using our reference to the GA object.
109
- ga(sendCommand, fieldsObject_1);
110
- });
111
- }
112
- else {
113
- this.log.warn(logPrefix + (noGaWarning + " " + noHit));
114
- }
115
- };
116
- // A falsy object represents the default tracker
117
- SplitToGa.defaultTrackerNames = [''];
118
- return SplitToGa;
119
- }());
120
- export { SplitToGa };
@@ -1,10 +0,0 @@
1
- import { SplitToGa } from './SplitToGa';
2
- export function SplitToGoogleAnalytics(options) {
3
- if (options === void 0) { options = {}; }
4
- // SplitToGa integration factory
5
- function SplitToGoogleAnalyticsFactory(params) {
6
- return new SplitToGa(params.settings.log, options);
7
- }
8
- SplitToGoogleAnalyticsFactory.type = 'SPLIT_TO_GOOGLE_ANALYTICS';
9
- return SplitToGoogleAnalyticsFactory;
10
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,72 +0,0 @@
1
- import { clientCSDecorator } from './clientCS';
2
- import { validateKey } from '../utils/inputValidation/key';
3
- import { validateTrafficType } from '../utils/inputValidation/trafficType';
4
- import { getMatching, keyParser } from '../utils/key';
5
- import { sdkClientFactory } from './sdkClient';
6
- import { objectAssign } from '../utils/lang/objectAssign';
7
- import { RETRIEVE_CLIENT_DEFAULT, NEW_SHARED_CLIENT, RETRIEVE_CLIENT_EXISTING, LOG_PREFIX_CLIENT_INSTANTIATION } from '../logger/constants';
8
- import { SDK_SEGMENTS_ARRIVED } from '../readiness/constants';
9
- import { buildInstanceId } from './identity';
10
- /**
11
- * Factory of client method for the client-side (browser) variant of the Isomorphic JS SDK,
12
- * where clients can have a bound TT for the track method, which is provided via the settings
13
- * (default client) or the client method (shared clients).
14
- */
15
- export function sdkClientMethodCSFactory(params) {
16
- var clients = params.clients, storage = params.storage, syncManager = params.syncManager, sdkReadinessManager = params.sdkReadinessManager, _a = params.settings, _b = _a.core, key = _b.key, trafficType = _b.trafficType, log = _a.log;
17
- var mainClientInstance = clientCSDecorator(log, sdkClientFactory(params), key, trafficType);
18
- var parsedDefaultKey = keyParser(key);
19
- var defaultInstanceId = buildInstanceId(parsedDefaultKey, trafficType);
20
- // Cache instances created per factory.
21
- clients[defaultInstanceId] = mainClientInstance;
22
- return function client(key, trafficType) {
23
- if (key === undefined) {
24
- log.debug(RETRIEVE_CLIENT_DEFAULT);
25
- return mainClientInstance;
26
- }
27
- // Validate the key value
28
- var validKey = validateKey(log, key, LOG_PREFIX_CLIENT_INSTANTIATION);
29
- if (validKey === false) {
30
- throw new Error('Shared Client needs a valid key.');
31
- }
32
- var validTrafficType;
33
- if (trafficType !== undefined) {
34
- validTrafficType = validateTrafficType(log, trafficType, LOG_PREFIX_CLIENT_INSTANTIATION);
35
- if (validTrafficType === false) {
36
- throw new Error('Shared Client needs a valid traffic type or no traffic type at all.');
37
- }
38
- }
39
- var instanceId = buildInstanceId(validKey, validTrafficType);
40
- if (!clients[instanceId]) {
41
- var matchingKey = getMatching(validKey);
42
- var sharedSdkReadiness_1 = sdkReadinessManager.shared();
43
- var sharedStorage = storage.shared && storage.shared(matchingKey, function (err) {
44
- if (err) {
45
- sharedSdkReadiness_1.readinessManager.timeout();
46
- return;
47
- }
48
- // Emit SDK_READY in consumer mode for shared clients
49
- sharedSdkReadiness_1.readinessManager.segments.emit(SDK_SEGMENTS_ARRIVED);
50
- });
51
- // 3 possibilities:
52
- // - Standalone mode: both syncManager and sharedSyncManager are defined
53
- // - Consumer mode: both syncManager and sharedSyncManager are undefined
54
- // - Consumer partial mode: syncManager is defined (only for submitters) but sharedSyncManager is undefined
55
- // @ts-ignore
56
- var sharedSyncManager = syncManager && sharedStorage && syncManager.shared(matchingKey, sharedSdkReadiness_1.readinessManager, sharedStorage);
57
- // As shared clients reuse all the storage information, we don't need to check here if we
58
- // will use offline or online mode. We should stick with the original decision.
59
- clients[instanceId] = clientCSDecorator(log, sdkClientFactory(objectAssign({}, params, {
60
- sdkReadinessManager: sharedSdkReadiness_1,
61
- storage: sharedStorage || storage,
62
- syncManager: sharedSyncManager,
63
- }), true), validKey, validTrafficType);
64
- sharedSyncManager && sharedSyncManager.start();
65
- log.info(NEW_SHARED_CLIENT);
66
- }
67
- else {
68
- log.debug(RETRIEVE_CLIENT_EXISTING);
69
- }
70
- return clients[instanceId];
71
- };
72
- }