@splitsoftware/splitio 10.17.3-rc.0 → 10.17.3-rc.1

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 (46) hide show
  1. package/client/package.json +5 -0
  2. package/es/factory/{clientSide.js → browser.js} +24 -11
  3. package/es/factory/{serverSide.js → node.js} +28 -11
  4. package/es/factory/package.json +2 -2
  5. package/es/platform/EventEmitter.js +412 -0
  6. package/es/platform/browser.js +2 -3
  7. package/es/platform/node.js +1 -2
  8. package/es/settings/{clientSide.js → browser.js} +0 -0
  9. package/es/settings/defaults/version.js +1 -1
  10. package/es/settings/{serverSide.js → node.js} +0 -0
  11. package/es/settings/package.json +2 -2
  12. package/es/settings/storage/browser.js +5 -4
  13. package/es/settings/storage/node.js +17 -9
  14. package/lib/factory/{clientSide.js → browser.js} +26 -12
  15. package/lib/factory/{serverSide.js → node.js} +30 -12
  16. package/lib/factory/package.json +2 -2
  17. package/lib/platform/EventEmitter.js +417 -0
  18. package/lib/platform/browser.js +5 -8
  19. package/lib/platform/node.js +3 -4
  20. package/lib/settings/{clientSide.js → browser.js} +0 -0
  21. package/lib/settings/defaults/version.js +1 -1
  22. package/lib/settings/{serverSide.js → node.js} +0 -0
  23. package/lib/settings/package.json +2 -2
  24. package/lib/settings/storage/browser.js +5 -4
  25. package/lib/settings/storage/node.js +17 -10
  26. package/package.json +5 -4
  27. package/server/package.json +5 -0
  28. package/src/.DS_Store +0 -0
  29. package/src/factory/{clientSide.js → browser.js} +31 -15
  30. package/src/factory/{serverSide.js → node.js} +34 -14
  31. package/src/factory/package.json +2 -2
  32. package/src/platform/EventEmitter.js +443 -0
  33. package/src/platform/browser.js +2 -3
  34. package/src/platform/node.js +1 -2
  35. package/src/settings/{clientSide.js → browser.js} +0 -0
  36. package/src/settings/defaults/version.js +1 -1
  37. package/src/settings/{serverSide.js → node.js} +0 -0
  38. package/src/settings/package.json +2 -2
  39. package/src/settings/storage/browser.js +4 -3
  40. package/src/settings/storage/node.js +15 -10
  41. package/types/client/index.d.ts +14 -0
  42. package/types/server/index.d.ts +20 -0
  43. package/types/splitio.d.ts +22 -5
  44. package/es/factory/commons.js +0 -16
  45. package/lib/factory/commons.js +0 -23
  46. package/src/factory/commons.js +0 -16
@@ -1,5 +1,4 @@
1
- // @TODO check 'events': it is a CommonJS module. Can have issues with ESM bundlers.
2
- import EventEmitter from 'events';
1
+ import { EventEmitter } from './EventEmitter';
3
2
  import { getFetch } from '../platform/getFetch/browser';
4
3
  import { getEventSource } from '../platform/getEventSource/browser';
5
4
  import { BrowserSignalListener } from '@splitsoftware/splitio-commons/src/listeners/browser';
@@ -10,4 +9,4 @@ export const platform = {
10
9
  EventEmitter
11
10
  };
12
11
 
13
- export const signalListener = BrowserSignalListener;
12
+ export const SignalListener = BrowserSignalListener;
@@ -1,4 +1,3 @@
1
- // @TODO check 'events': Node is using events API or the installed dependency?
2
1
  import EventEmitter from 'events';
3
2
  import { getFetch } from '../platform/getFetch/node';
4
3
  import { getEventSource } from '../platform/getEventSource/node';
@@ -12,4 +11,4 @@ export const platform = {
12
11
  EventEmitter
13
12
  };
14
13
 
15
- export const signalListener = NodeSignalListener;
14
+ export const SignalListener = NodeSignalListener;
File without changes
@@ -1 +1 @@
1
- export const packageVersion = '10.17.3-rc.0';
1
+ export const packageVersion = '10.17.3-rc.1';
File without changes
@@ -1,4 +1,4 @@
1
1
  {
2
- "main": "./serverSide.js",
3
- "browser": "./clientSide.js"
2
+ "main": "./node.js",
3
+ "browser": "./browser.js"
4
4
  }
@@ -21,6 +21,7 @@ const STORAGE_LOCALSTORAGE = 'LOCALSTORAGE';
21
21
 
22
22
  export function validateStorage(settings) {
23
23
  let {
24
+ log,
24
25
  mode,
25
26
  storage: {
26
27
  type,
@@ -41,8 +42,8 @@ export function validateStorage(settings) {
41
42
  type = STORAGE_MEMORY;
42
43
  };
43
44
 
44
- // In localhost mode, fallback to Memory storage and track original
45
- // type to emit SDK_READY_FROM_CACHE if corresponds
45
+ // In localhost mode, fallback to Memory storage and track original type to emit SDK_READY_FROM_CACHE if corresponds.
46
+ // ATM, other mode settings (e.g., 'consumer') are ignored in client-side API, and so treated as standalone.
46
47
  if (mode === LOCALHOST_MODE && type === STORAGE_LOCALSTORAGE) {
47
48
  fallbackToMemory();
48
49
  }
@@ -52,7 +53,7 @@ export function validateStorage(settings) {
52
53
  if (type !== STORAGE_MEMORY && type !== STORAGE_LOCALSTORAGE ||
53
54
  type === STORAGE_LOCALSTORAGE && !isLocalStorageAvailable()) {
54
55
  fallbackToMemory();
55
- settings.log.warn('Invalid or unavailable storage. Fallbacking into MEMORY storage');
56
+ log.error('Invalid or unavailable storage. Fallbacking into MEMORY storage');
56
57
  }
57
58
 
58
59
  return {
@@ -13,12 +13,11 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  **/
16
- import { LOCALHOST_MODE, STORAGE_MEMORY } from '@splitsoftware/splitio-commons/src/utils/constants';
17
-
18
- const STORAGE_REDIS = 'REDIS';
16
+ import { LOCALHOST_MODE, STORAGE_MEMORY, STORAGE_REDIS, CONSUMER_MODE, STANDALONE_MODE } from '@splitsoftware/splitio-commons/src/utils/constants';
19
17
 
20
18
  export function validateStorage(settings) {
21
19
  let {
20
+ log,
22
21
  mode,
23
22
  storage: {
24
23
  type,
@@ -33,15 +32,17 @@ export function validateStorage(settings) {
33
32
  prefix = 'SPLITIO';
34
33
  }
35
34
 
36
- // In localhost mode we should force the user to use the MEMORY storage
37
- if (mode === LOCALHOST_MODE) return {
38
- type: STORAGE_MEMORY,
39
- prefix
40
- };
41
-
42
- // In other cases we can have MEMORY or REDIS
35
+ // We can have MEMORY, REDIS or an invalid storage type
43
36
  switch (type) {
44
37
  case STORAGE_REDIS: {
38
+ // If passing REDIS storage in localhost or standalone mode, we log an error and fallback to MEMORY storage
39
+ if (mode === STANDALONE_MODE || mode === LOCALHOST_MODE) {
40
+ log.error('The provided REDIS storage is invalid for this mode. It requires consumer mode. Fallbacking into default MEMORY storage.');
41
+ return {
42
+ type: STORAGE_MEMORY,
43
+ prefix
44
+ };
45
+ }
45
46
  let {
46
47
  host,
47
48
  port,
@@ -86,6 +87,10 @@ export function validateStorage(settings) {
86
87
  // For now, we don't have modifiers or settings for MEMORY in NodeJS
87
88
  case STORAGE_MEMORY:
88
89
  default: {
90
+ // If passing MEMORY storage in consumer mode, throw an error (no way to fallback to REDIS storage)
91
+ if (mode === CONSUMER_MODE) throw new Error('A REDIS storage is required on consumer mode');
92
+ // If passing an invalid storage type, log an error
93
+ if (type !== STORAGE_MEMORY) log.error(`The provided '${type}' storage type is invalid. Fallbacking into default MEMORY storage.`);
89
94
  return {
90
95
  type: STORAGE_MEMORY,
91
96
  prefix
@@ -0,0 +1,14 @@
1
+ // Declaration file for Javascript Split Software SDK
2
+ // Project: http://www.split.io/
3
+
4
+ /// <reference path="../splitio.d.ts" />
5
+ export = JsSdk;
6
+
7
+ declare module JsSdk {
8
+ /**
9
+ * Split.io sdk factory function.
10
+ * The settings parameter should be an object that complies with the SplitIO.IBrowserSettings.
11
+ * For more information read the corresponding article: @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#configuration}
12
+ */
13
+ export function SplitFactory(settings: SplitIO.IBrowserSettings): SplitIO.IBrowserSDK;
14
+ }
@@ -0,0 +1,20 @@
1
+ // Declaration file for Javascript Split Software SDK
2
+ // Project: http://www.split.io/
3
+
4
+ /// <reference path="../splitio.d.ts" />
5
+ export = JsSdk;
6
+
7
+ declare module JsSdk {
8
+ /**
9
+ * Split.io sdk factory function.
10
+ * The settings parameter should be an object that complies with the SplitIO.INodeAsyncSettings.
11
+ * For more information read the corresponding article: @see {@link https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK#configuration}
12
+ */
13
+ export function SplitFactory(settings: SplitIO.INodeAsyncSettings): SplitIO.IAsyncSDK;
14
+ /**
15
+ * Split.io sdk factory function.
16
+ * The settings parameter should be an object that complies with the SplitIO.INodeSettings.
17
+ * For more information read the corresponding article: @see {@link https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK#configuration}
18
+ */
19
+ export function SplitFactory(settings: SplitIO.INodeSettings): SplitIO.ISDK;
20
+ }
@@ -1,4 +1,4 @@
1
- // Type definitions for Javascript and Node Split Software SDK v8.1.0
1
+ // Type definitions for Javascript and Node Split Software SDK
2
2
  // Project: http://www.split.io/
3
3
  // Definitions by: Nico Zelaya <https://github.com/NicoZelaya/>
4
4
 
@@ -336,7 +336,8 @@ interface INodeBasicSettings extends ISharedSettings {
336
336
  prefix?: string
337
337
  },
338
338
  /**
339
- * The SDK mode. Possible values are "standalone" (which is the default) and "consumer". For "localhost" mode, use "localhost" as authorizationKey.
339
+ * The SDK mode. Possible values are "standalone", which is the default when using a synchronous storage, like 'MEMORY' and 'LOCALSTORAGE',
340
+ * and "consumer", which must be set when using an asynchronous storage, like 'REDIS'. For "localhost" mode, use "localhost" as authorizationKey.
340
341
  * @property {SDKMode} mode
341
342
  * @default standalone
342
343
  */
@@ -1020,7 +1021,15 @@ declare namespace SplitIO {
1020
1021
  * @default SPLITIO
1021
1022
  */
1022
1023
  prefix?: string
1023
- }
1024
+ },
1025
+ /**
1026
+ * The SDK mode. When using the default 'MEMORY' storage, the only possible value is "standalone", which is the default.
1027
+ * For "localhost" mode, use "localhost" as authorizationKey.
1028
+ *
1029
+ * @property {'standalone'} mode
1030
+ * @default standalone
1031
+ */
1032
+ mode?: 'standalone'
1024
1033
  }
1025
1034
  /**
1026
1035
  * Settings interface with async storage for SDK instances created on NodeJS.
@@ -1032,7 +1041,7 @@ declare namespace SplitIO {
1032
1041
  interface INodeAsyncSettings extends INodeBasicSettings {
1033
1042
  storage: {
1034
1043
  /**
1035
- * Redis storage type to be instantiated by the SDK.
1044
+ * 'REDIS' storage type to be instantiated by the SDK.
1036
1045
  * @property {NodeAsyncStorage} type
1037
1046
  */
1038
1047
  type: NodeAsyncStorage,
@@ -1047,7 +1056,15 @@ declare namespace SplitIO {
1047
1056
  * @default SPLITIO
1048
1057
  */
1049
1058
  prefix?: string
1050
- }
1059
+ },
1060
+ /**
1061
+ * The SDK mode. When using 'REDIS' storage type, the only possible value is "consumer", which is required.
1062
+ *
1063
+ * @see {@link https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK#state-sharing-redis-integration}
1064
+ *
1065
+ * @property {'consumer'} mode
1066
+ */
1067
+ mode: 'consumer'
1051
1068
  }
1052
1069
  /**
1053
1070
  * This represents the interface for the SDK instance with synchronous storage.
@@ -1,16 +0,0 @@
1
- import { OPTIMIZED, PRODUCER_MODE, STANDALONE_MODE } from '@splitsoftware/splitio-commons/esm/utils/constants';
2
- /**
3
- * Checks if impressions previous time should be added or not.
4
- */
5
-
6
- export function shouldAddPt(settings) {
7
- return [PRODUCER_MODE, STANDALONE_MODE].indexOf(settings.mode) > -1 ? true : false;
8
- }
9
- /**
10
- * Checks if it should dedupe impressions or not.
11
- */
12
-
13
- export function shouldBeOptimized(settings) {
14
- if (!shouldAddPt(settings)) return false;
15
- return settings.sync.impressionsMode === OPTIMIZED ? true : false;
16
- }
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.shouldAddPt = shouldAddPt;
5
- exports.shouldBeOptimized = shouldBeOptimized;
6
-
7
- var _constants = require("@splitsoftware/splitio-commons/cjs/utils/constants");
8
-
9
- /**
10
- * Checks if impressions previous time should be added or not.
11
- */
12
- function shouldAddPt(settings) {
13
- return [_constants.PRODUCER_MODE, _constants.STANDALONE_MODE].indexOf(settings.mode) > -1 ? true : false;
14
- }
15
- /**
16
- * Checks if it should dedupe impressions or not.
17
- */
18
-
19
-
20
- function shouldBeOptimized(settings) {
21
- if (!shouldAddPt(settings)) return false;
22
- return settings.sync.impressionsMode === _constants.OPTIMIZED ? true : false;
23
- }
@@ -1,16 +0,0 @@
1
- import { OPTIMIZED, PRODUCER_MODE, STANDALONE_MODE } from '@splitsoftware/splitio-commons/src/utils/constants';
2
-
3
- /**
4
- * Checks if impressions previous time should be added or not.
5
- */
6
- export function shouldAddPt(settings) {
7
- return [PRODUCER_MODE, STANDALONE_MODE].indexOf(settings.mode) > -1 ? true : false;
8
- }
9
-
10
- /**
11
- * Checks if it should dedupe impressions or not.
12
- */
13
- export function shouldBeOptimized(settings) {
14
- if (!shouldAddPt(settings)) return false;
15
- return settings.sync.impressionsMode === OPTIMIZED ? true : false;
16
- }