@splitsoftware/splitio-commons 1.5.0 → 1.5.1-rc.2

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 (129) hide show
  1. package/CHANGES.txt +5 -0
  2. package/cjs/listeners/browser.js +35 -15
  3. package/cjs/services/splitApi.js +4 -4
  4. package/cjs/sync/polling/fetchers/segmentChangesFetcher.js +5 -5
  5. package/cjs/sync/polling/fetchers/splitChangesFetcher.js +2 -2
  6. package/cjs/sync/polling/updaters/segmentChangesUpdater.js +34 -34
  7. package/cjs/sync/polling/updaters/splitChangesUpdater.js +4 -3
  8. package/cjs/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +46 -46
  9. package/cjs/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +82 -64
  10. package/cjs/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +74 -58
  11. package/cjs/sync/streaming/UpdateWorkers/constants.js +6 -0
  12. package/cjs/sync/streaming/pushManager.js +6 -7
  13. package/cjs/sync/syncTask.js +13 -16
  14. package/cjs/utils/Backoff.js +3 -2
  15. package/esm/listeners/browser.js +35 -15
  16. package/esm/services/splitApi.js +4 -4
  17. package/esm/sync/polling/fetchers/segmentChangesFetcher.js +5 -5
  18. package/esm/sync/polling/fetchers/splitChangesFetcher.js +2 -2
  19. package/esm/sync/polling/updaters/segmentChangesUpdater.js +34 -34
  20. package/esm/sync/polling/updaters/splitChangesUpdater.js +4 -3
  21. package/esm/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +46 -47
  22. package/esm/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +82 -65
  23. package/esm/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +74 -59
  24. package/esm/sync/streaming/UpdateWorkers/constants.js +3 -0
  25. package/esm/sync/streaming/pushManager.js +6 -7
  26. package/esm/sync/syncTask.js +13 -16
  27. package/esm/utils/Backoff.js +3 -2
  28. package/package.json +1 -5
  29. package/src/listeners/browser.ts +34 -14
  30. package/src/logger/.DS_Store +0 -0
  31. package/src/services/splitApi.ts +4 -4
  32. package/src/services/types.ts +2 -2
  33. package/src/sync/polling/fetchers/segmentChangesFetcher.ts +5 -4
  34. package/src/sync/polling/fetchers/splitChangesFetcher.ts +2 -1
  35. package/src/sync/polling/fetchers/types.ts +2 -0
  36. package/src/sync/polling/pollingManagerCS.ts +5 -5
  37. package/src/sync/polling/syncTasks/mySegmentsSyncTask.ts +2 -2
  38. package/src/sync/polling/types.ts +14 -6
  39. package/src/sync/polling/updaters/mySegmentsUpdater.ts +4 -4
  40. package/src/sync/polling/updaters/segmentChangesUpdater.ts +34 -32
  41. package/src/sync/polling/updaters/splitChangesUpdater.ts +5 -4
  42. package/src/sync/streaming/SSEHandler/types.ts +0 -7
  43. package/src/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.ts +45 -54
  44. package/src/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.ts +78 -63
  45. package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +73 -61
  46. package/src/sync/streaming/UpdateWorkers/constants.ts +3 -0
  47. package/src/sync/streaming/UpdateWorkers/types.ts +2 -4
  48. package/src/sync/streaming/pushManager.ts +12 -12
  49. package/src/sync/streaming/types.ts +2 -2
  50. package/src/sync/syncTask.ts +16 -18
  51. package/src/utils/Backoff.ts +7 -2
  52. package/types/integrations/ga/GaToSplitPlugin.d.ts +3 -0
  53. package/types/integrations/ga/SplitToGaPlugin.d.ts +4 -0
  54. package/types/integrations/ga/autoRequire.d.ts +4 -0
  55. package/types/listeners/browser.d.ts +6 -6
  56. package/types/logger/browser/{DebugLogger.d.ts → debugLogger.d.ts} +0 -0
  57. package/types/logger/browser/{ErrorLogger.d.ts → errorLogger.d.ts} +0 -0
  58. package/types/logger/browser/{InfoLogger.d.ts → infoLogger.d.ts} +0 -0
  59. package/types/logger/browser/{WarnLogger.d.ts → warnLogger.d.ts} +0 -0
  60. package/types/logger/codes.d.ts +2 -0
  61. package/types/logger/codesConstants.d.ts +117 -0
  62. package/types/logger/codesConstantsBrowser.d.ts +2 -0
  63. package/types/logger/codesConstantsNode.d.ts +14 -0
  64. package/types/logger/codesDebug.d.ts +1 -0
  65. package/types/logger/codesDebugBrowser.d.ts +1 -0
  66. package/types/logger/codesDebugNode.d.ts +1 -0
  67. package/types/logger/codesError.d.ts +1 -0
  68. package/types/logger/codesErrorNode.d.ts +1 -0
  69. package/types/logger/codesInfo.d.ts +1 -0
  70. package/types/logger/codesWarn.d.ts +1 -0
  71. package/types/logger/codesWarnNode.d.ts +1 -0
  72. package/types/logger/debugLogger.d.ts +2 -0
  73. package/types/logger/errorLogger.d.ts +2 -0
  74. package/types/logger/infoLogger.d.ts +2 -0
  75. package/types/logger/messages/debugBrowser.d.ts +1 -0
  76. package/types/logger/messages/debugNode.d.ts +1 -0
  77. package/types/logger/messages/errorNode.d.ts +1 -0
  78. package/types/logger/messages/warnNode.d.ts +1 -0
  79. package/types/logger/noopLogger.d.ts +2 -0
  80. package/types/logger/warnLogger.d.ts +2 -0
  81. package/types/sdkFactory/userConsentProps.d.ts +6 -0
  82. package/types/sdkManager/sdkManagerMethod.d.ts +6 -0
  83. package/types/services/types.d.ts +2 -2
  84. package/types/storages/getRegisteredSegments.d.ts +10 -0
  85. package/types/storages/inMemory/index.d.ts +10 -0
  86. package/types/storages/parseSegments.d.ts +6 -0
  87. package/types/sync/polling/fetchers/types.d.ts +2 -2
  88. package/types/sync/polling/syncTasks/mySegmentsSyncTask.d.ts +2 -2
  89. package/types/sync/polling/syncTasks/splitsSyncTask.copy.d.ts +35 -0
  90. package/types/sync/polling/syncTasks/splitsSyncTask.morelikeoriginal.d.ts +35 -0
  91. package/types/sync/polling/types.d.ts +11 -6
  92. package/types/sync/polling/updaters/segmentChangesUpdater.d.ts +1 -1
  93. package/types/sync/polling/updaters/splitChangesUpdater.d.ts +1 -1
  94. package/types/sync/streaming/AuthClient/indexV1.d.ts +12 -0
  95. package/types/sync/streaming/AuthClient/indexV2.d.ts +8 -0
  96. package/types/sync/streaming/SSEHandler/types.d.ts +0 -4
  97. package/types/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.d.ts +3 -24
  98. package/types/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.d.ts +3 -23
  99. package/types/sync/streaming/UpdateWorkers/SplitsUpdateWorker.d.ts +6 -33
  100. package/types/sync/streaming/UpdateWorkers/constants.d.ts +3 -0
  101. package/types/sync/streaming/UpdateWorkers/types.d.ts +1 -2
  102. package/types/sync/streaming/pushManagerCS.d.ts +1 -0
  103. package/types/sync/streaming/pushManagerNoUsers.d.ts +13 -0
  104. package/types/sync/streaming/pushManagerSS.d.ts +1 -0
  105. package/types/sync/streaming/types.d.ts +2 -2
  106. package/types/sync/submitters/telemetrySyncTask.d.ts +0 -0
  107. package/types/sync/syncManagerFromFile.d.ts +2 -0
  108. package/types/sync/syncManagerFromObject.d.ts +2 -0
  109. package/types/sync/syncManagerOffline.d.ts +9 -0
  110. package/types/sync/syncTask.d.ts +2 -3
  111. package/types/trackers/telemetryRecorder.d.ts +0 -0
  112. package/types/utils/Backoff.d.ts +2 -0
  113. package/types/utils/EventEmitter.d.ts +4 -0
  114. package/types/utils/consent.d.ts +2 -0
  115. package/types/utils/lang/errors.d.ts +10 -0
  116. package/types/utils/murmur3/commons.d.ts +12 -0
  117. package/types/utils/settingsValidation/buildMetadata.d.ts +3 -0
  118. package/types/utils/settingsValidation/localhost/index.d.ts +9 -0
  119. package/types/utils/settingsValidation/logger.d.ts +11 -0
  120. package/types/utils/settingsValidation/runtime/browser.d.ts +2 -0
  121. package/types/utils/settingsValidation/runtime/node.d.ts +2 -0
  122. package/types/utils/settingsValidation/userConsent.d.ts +5 -0
  123. package/types/utils/timeTracker/index.d.ts +1 -70
  124. package/cjs/sync/offline/LocalhostFromFile.js +0 -13
  125. package/cjs/sync/offline/splitsParser/splitsParserFromFile.js +0 -151
  126. package/esm/sync/offline/LocalhostFromFile.js +0 -9
  127. package/esm/sync/offline/splitsParser/splitsParserFromFile.js +0 -146
  128. package/src/sync/offline/LocalhostFromFile.ts +0 -12
  129. package/src/sync/offline/splitsParser/splitsParserFromFile.ts +0 -182
@@ -1,182 +0,0 @@
1
- /* eslint-disable no-undef */
2
- // @TODO consider moving it to Node-SDK and remove js-yaml dependency from Js-commons
3
- import fs from 'fs';
4
- import path from 'path';
5
- // @ts-ignore
6
- import yaml from 'js-yaml';
7
- import { isString, endsWith, find, forOwn, uniq, } from '../../../utils/lang';
8
- import { parseCondition, IMockSplitEntry } from './parseCondition';
9
- import { ISplitPartial } from '../../../dtos/types';
10
- import { ISettings, SplitIO } from '../../../types';
11
- import { ILogger } from '../../../logger/types';
12
- import { ISplitsParser } from './types';
13
-
14
- const logPrefix = 'sync:offline:splits-fetcher: ';
15
-
16
- type IYamlSplitEntry = Record<string, IMockSplitEntry>
17
-
18
- const DEFAULT_FILENAME = '.split';
19
-
20
- function configFilesPath(configFilePath?: SplitIO.MockedFeaturesFilePath): SplitIO.MockedFeaturesFilePath {
21
- if (configFilePath === DEFAULT_FILENAME || !isString(configFilePath)) {
22
- let root = process.env.HOME;
23
-
24
- if (process.env.SPLIT_CONFIG_ROOT) root = process.env.SPLIT_CONFIG_ROOT;
25
-
26
- if (!root) throw new Error('Missing split mock configuration root.');
27
-
28
- configFilePath = path.join(root, DEFAULT_FILENAME);
29
- }
30
-
31
- // Validate the extensions
32
- if (!(endsWith(configFilePath, '.yaml', true) || endsWith(configFilePath, '.yml', true) || endsWith(configFilePath, '.split', true)))
33
- throw new Error(`Invalid extension specified for Splits mock file. Accepted extensions are ".yml" and ".yaml". Your specified file is ${configFilePath}`);
34
-
35
- if (!fs.existsSync(configFilePath as SplitIO.MockedFeaturesFilePath))
36
- throw new Error(`Split configuration not found in ${configFilePath} - Please review your Split file location.`);
37
-
38
- return configFilePath as SplitIO.MockedFeaturesFilePath;
39
- }
40
-
41
- // This function is not pure nor meant to be. Here we apply modifications to cover
42
- // for behaviour that's ensured by the BE.
43
- function arrangeConditions(mocksData: Record<string, Required<ISplitPartial> & { treatments: string[] }>) {
44
- // Iterate through each Split data
45
- forOwn(mocksData, data => {
46
- const conditions = data.conditions;
47
-
48
- // On the manager, as the split jsons come with all treatments on the partitions prop,
49
- // we'll add all the treatments to the first condition.
50
- const firstRolloutCondition = find(conditions, cond => cond.conditionType === 'ROLLOUT');
51
- // Malformed mocks may have
52
- const treatments = uniq(data.treatments);
53
- // If they're only specifying a whitelist we add the treatments there.
54
- const allTreatmentsCondition = firstRolloutCondition ? firstRolloutCondition : conditions[0];
55
-
56
- const fullyAllocatedTreatment = allTreatmentsCondition.partitions[0].treatment;
57
-
58
- treatments.forEach(treatment => {
59
- if (treatment !== fullyAllocatedTreatment) {
60
- allTreatmentsCondition.partitions.push({
61
- treatment, size: 0
62
- });
63
- }
64
- });
65
-
66
- // Don't need these anymore
67
- // @ts-expect-error
68
- delete data.treatments;
69
- });
70
- }
71
-
72
- export function splitsParserFromFileFactory(): ISplitsParser {
73
-
74
- let previousMock = 'NO_MOCK_LOADED';
75
-
76
- // Parse `.split` configuration file and return a map of "Split Objects"
77
- function readSplitConfigFile(log: ILogger, filePath: SplitIO.MockedFeaturesFilePath): false | Record<string, ISplitPartial> {
78
- const SPLIT_POSITION = 0;
79
- const TREATMENT_POSITION = 1;
80
- let data;
81
-
82
- try {
83
- data = fs.readFileSync(filePath, 'utf-8');
84
- } catch (e) {
85
- log.error(e && (e as Error).message);
86
-
87
- return {};
88
- }
89
-
90
- if (data === previousMock) return false;
91
- previousMock = data;
92
-
93
- const splitObjects = data.split(/\r?\n/).reduce((accum, line, index) => {
94
- let tuple: string | string[] = line.trim();
95
-
96
- if (tuple === '' || tuple.charAt(0) === '#') {
97
- log.debug(logPrefix + `Ignoring empty line or comment at #${index}`);
98
- } else {
99
- tuple = tuple.split(/\s+/);
100
-
101
- if (tuple.length !== 2) {
102
- log.debug(logPrefix + `Ignoring line since it does not have exactly two columns #${index}`);
103
- } else {
104
- const splitName = tuple[SPLIT_POSITION];
105
- const condition = parseCondition({ treatment: tuple[TREATMENT_POSITION] });
106
- accum[splitName] = { conditions: [condition], configurations: {}, trafficTypeName: 'localhost' };
107
- }
108
- }
109
-
110
- return accum;
111
- }, {} as Record<string, ISplitPartial>);
112
-
113
- return splitObjects;
114
- }
115
-
116
- // Parse `.yml` or `.yaml` configuration files and return a map of "Split Objects"
117
- function readYAMLConfigFile(log: ILogger, filePath: SplitIO.MockedFeaturesFilePath): false | Record<string, ISplitPartial> {
118
- let data = '';
119
- let yamldoc = null;
120
-
121
- try {
122
- data = fs.readFileSync(filePath, 'utf8');
123
-
124
- if (data === previousMock) return false;
125
- previousMock = data;
126
-
127
- yamldoc = yaml.safeLoad(data);
128
- } catch (e) {
129
- log.error(e);
130
-
131
- return {};
132
- }
133
-
134
- // Each entry will be mapped to a condition, but we'll also keep the configurations map.
135
- const mocksData = (yamldoc as IYamlSplitEntry[]).reduce((accum, splitEntry) => {
136
- const splitName = Object.keys(splitEntry)[0];
137
-
138
- if (!splitName || !isString(splitEntry[splitName].treatment))
139
- log.error(logPrefix + 'Ignoring entry on YAML since the format is incorrect.');
140
-
141
- const mockData = splitEntry[splitName];
142
-
143
- // "Template" for each split accumulated data
144
- if (!accum[splitName]) {
145
- accum[splitName] = {
146
- configurations: {}, conditions: [], treatments: [], trafficTypeName: 'localhost'
147
- };
148
- }
149
-
150
- // Assign the config if there is one on the mock
151
- if (mockData.config) accum[splitName].configurations[mockData.treatment] = mockData.config;
152
- // Parse the condition from the entry.
153
- const condition = parseCondition(mockData);
154
- accum[splitName].conditions[condition.conditionType === 'ROLLOUT' ? 'push' : 'unshift'](condition);
155
- // Also keep track of the treatments, will be useful for manager functionality.
156
- accum[splitName].treatments.push(mockData.treatment);
157
-
158
- return accum;
159
- }, {} as Record<string, Required<ISplitPartial> & { treatments: string[] }>);
160
-
161
- arrangeConditions(mocksData);
162
-
163
- return mocksData;
164
- }
165
-
166
- // Load the content of a configuration file into an Object
167
- return function splitsParserFromFile({ features, log }: ISettings): false | Record<string, ISplitPartial> {
168
- const filePath = configFilesPath(features as string);
169
- let mockData: false | Record<string, ISplitPartial>;
170
-
171
- // If we have a filePath, it means the extension is correct, choose the parser.
172
- if (endsWith(filePath, '.split')) {
173
- log.warn(logPrefix + '.split mocks will be deprecated soon in favor of YAML files, which provide more targeting power. Take a look in our documentation.');
174
- mockData = readSplitConfigFile(log, filePath);
175
- } else {
176
- mockData = readYAMLConfigFile(log, filePath);
177
- }
178
-
179
- return mockData;
180
- };
181
-
182
- }