@splitsoftware/splitio-commons 1.2.1-rc.8 → 1.3.1-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 (98) hide show
  1. package/CHANGES.txt +17 -0
  2. package/cjs/{utils/consent.js → consent/index.js} +1 -1
  3. package/cjs/consent/sdkUserConsent.js +58 -0
  4. package/cjs/listeners/browser.js +1 -1
  5. package/cjs/logger/constants.js +3 -2
  6. package/cjs/logger/messages/info.js +1 -0
  7. package/cjs/readiness/sdkReadinessManager.js +5 -3
  8. package/cjs/sdkClient/client.js +1 -1
  9. package/cjs/sdkClient/clientCS.js +1 -1
  10. package/cjs/sdkClient/sdkClient.js +3 -3
  11. package/cjs/sdkClient/sdkClientMethodCS.js +3 -9
  12. package/cjs/sdkClient/sdkClientMethodCSWithTT.js +3 -13
  13. package/cjs/sdkFactory/index.js +3 -2
  14. package/cjs/services/splitHttpClient.js +12 -11
  15. package/cjs/storages/inRedis/RedisAdapter.js +9 -2
  16. package/cjs/sync/syncManagerOnline.js +1 -1
  17. package/cjs/trackers/impressionsTracker.js +2 -2
  18. package/cjs/utils/inputValidation/attributes.js +1 -1
  19. package/cjs/utils/lang/index.js +4 -2
  20. package/cjs/utils/lang/maps.js +16 -2
  21. package/cjs/utils/settingsValidation/index.js +21 -3
  22. package/esm/{utils/consent.js → consent/index.js} +1 -1
  23. package/esm/consent/sdkUserConsent.js +54 -0
  24. package/esm/listeners/browser.js +1 -1
  25. package/esm/logger/constants.js +1 -0
  26. package/esm/logger/messages/info.js +1 -0
  27. package/esm/readiness/sdkReadinessManager.js +5 -3
  28. package/esm/sdkClient/client.js +1 -1
  29. package/esm/sdkClient/clientCS.js +1 -1
  30. package/esm/sdkClient/sdkClient.js +3 -3
  31. package/esm/sdkClient/sdkClientMethodCS.js +3 -9
  32. package/esm/sdkClient/sdkClientMethodCSWithTT.js +3 -13
  33. package/esm/sdkFactory/index.js +3 -2
  34. package/esm/services/splitHttpClient.js +12 -11
  35. package/esm/storages/inRedis/RedisAdapter.js +9 -2
  36. package/esm/sync/syncManagerOnline.js +1 -1
  37. package/esm/trackers/impressionsTracker.js +2 -2
  38. package/esm/utils/inputValidation/attributes.js +1 -1
  39. package/esm/utils/lang/index.js +4 -2
  40. package/esm/utils/lang/maps.js +14 -1
  41. package/esm/utils/settingsValidation/index.js +21 -3
  42. package/package.json +14 -2
  43. package/src/{utils/consent.ts → consent/index.ts} +1 -1
  44. package/src/consent/sdkUserConsent.ts +58 -0
  45. package/src/evaluator/parser/index.ts +1 -1
  46. package/src/evaluator/types.ts +2 -2
  47. package/src/evaluator/value/index.ts +2 -2
  48. package/src/evaluator/value/sanitize.ts +2 -2
  49. package/src/integrations/pluggable.ts +2 -2
  50. package/src/listeners/browser.ts +1 -1
  51. package/src/logger/constants.ts +1 -0
  52. package/src/logger/messages/info.ts +1 -0
  53. package/src/readiness/sdkReadinessManager.ts +7 -5
  54. package/src/sdkClient/client.ts +3 -4
  55. package/src/sdkClient/clientCS.ts +1 -1
  56. package/src/sdkClient/sdkClient.ts +4 -4
  57. package/src/sdkClient/sdkClientMethod.ts +2 -2
  58. package/src/sdkClient/sdkClientMethodCS.ts +5 -11
  59. package/src/sdkClient/sdkClientMethodCSWithTT.ts +6 -16
  60. package/src/sdkFactory/index.ts +3 -2
  61. package/src/sdkFactory/types.ts +13 -3
  62. package/src/services/splitHttpClient.ts +12 -10
  63. package/src/storages/inRedis/RedisAdapter.ts +8 -2
  64. package/src/sync/syncManagerOnline.ts +1 -1
  65. package/src/trackers/impressionsTracker.ts +4 -4
  66. package/src/types.ts +3 -3
  67. package/src/utils/inputValidation/attributes.ts +1 -2
  68. package/src/utils/lang/index.ts +7 -3
  69. package/src/utils/lang/maps.ts +15 -1
  70. package/src/utils/settingsValidation/index.ts +21 -3
  71. package/src/utils/settingsValidation/types.ts +5 -1
  72. package/types/consent/index.d.ts +2 -0
  73. package/types/consent/sdkUserConsent.d.ts +13 -0
  74. package/types/evaluator/types.d.ts +2 -2
  75. package/types/evaluator/value/index.d.ts +1 -1
  76. package/types/evaluator/value/sanitize.d.ts +1 -1
  77. package/types/logger/constants.d.ts +1 -0
  78. package/types/sdkClient/client.d.ts +2 -2
  79. package/types/sdkClient/sdkClient.d.ts +2 -2
  80. package/types/sdkClient/sdkClientMethod.d.ts +2 -2
  81. package/types/sdkClient/sdkClientMethodCS.d.ts +2 -2
  82. package/types/sdkClient/sdkClientMethodCSWithTT.d.ts +2 -2
  83. package/types/sdkFactory/types.d.ts +12 -3
  84. package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +8 -10
  85. package/types/storages/inRedis/RedisAdapter.d.ts +1 -1
  86. package/types/storages/inRedis/TelemetryCacheInRedis.d.ts +21 -0
  87. package/types/storages/pluggable/TelemetryCachePluggable.d.ts +19 -1
  88. package/types/sync/submitters/telemetrySyncTask.d.ts +16 -6
  89. package/types/types.d.ts +3 -3
  90. package/types/utils/lang/index.d.ts +2 -1
  91. package/types/utils/lang/maps.d.ts +7 -0
  92. package/types/utils/settingsValidation/types.d.ts +5 -1
  93. package/cjs/sdkClient/types.js +0 -2
  94. package/cjs/sdkFactory/userConsentProps.js +0 -37
  95. package/esm/sdkClient/types.js +0 -1
  96. package/esm/sdkFactory/userConsentProps.js +0 -33
  97. package/src/sdkClient/types.ts +0 -21
  98. package/src/sdkFactory/userConsentProps.ts +0 -40
@@ -1,17 +1,27 @@
1
1
  import { ISyncTask, ITimeTracker } from '../types';
2
- import { IPostMetricsUsage } from '../../services/types';
2
+ import { ISplitApi } from '../../services/types';
3
3
  import { IStorageSync, TelemetryCacheSync } from '../../storages/types';
4
- import { TelemetryStatsPayload } from './types';
5
- import { ILogger } from '../../logger/types';
4
+ import { TelemetryUsageStatsPayload, TelemetryConfigStatsPayload } from './types';
5
+ import { IReadinessManager } from '../../readiness/types';
6
+ import { ISettings } from '../../types';
6
7
  /**
7
8
  * Converts `impressions` data from cache into request payload.
8
9
  */
9
- export declare function telemetryCacheAdapter(telemetryCache: TelemetryCacheSync, storage: IStorageSync): {
10
+ export declare function telemetryCacheStatsAdapter({ splits, segments, telemetry }: IStorageSync & {
11
+ telemetry: TelemetryCacheSync;
12
+ }): {
10
13
  isEmpty(): boolean;
11
14
  clear(): void;
12
- state(): TelemetryStatsPayload;
15
+ state(): TelemetryUsageStatsPayload;
16
+ };
17
+ export declare function telemetryCacheConfigAdapter(settings: ISettings, telemetryCache: TelemetryCacheSync): {
18
+ isEmpty(): boolean;
19
+ clear(): void;
20
+ state(): TelemetryConfigStatsPayload;
13
21
  };
14
22
  /**
15
23
  * Sync task that periodically posts impressions data
16
24
  */
17
- export declare function telemetrySyncTaskFactory(log: ILogger, postMetricsUsage: IPostMetricsUsage, telemetryCache: TelemetryCacheSync, telemetryRefreshRate: number, latencyTracker: ITimeTracker, storage: IStorageSync): ISyncTask;
25
+ export declare function telemetrySyncTaskFactory(settings: ISettings, { postMetricsUsage, postMetricsConfig }: ISplitApi, storage: IStorageSync & {
26
+ telemetry: TelemetryCacheSync;
27
+ }, telemetryRefreshRate: number, readiness: IReadinessManager, latencyTracker?: ITimeTracker): ISyncTask;
package/types/types.d.ts CHANGED
@@ -389,7 +389,7 @@ interface IBasicClient extends IStatusInterface {
389
389
  * @returns {Promise<void>}
390
390
  */
391
391
  destroy(): Promise<void>;
392
- isBrowserClient: boolean;
392
+ isClientSide: boolean;
393
393
  }
394
394
  /**
395
395
  * Common definitions between SDK instances for different environments interface.
@@ -526,8 +526,8 @@ export declare namespace SplitIO {
526
526
  type ImpressionData = {
527
527
  impression: ImpressionDTO;
528
528
  attributes?: SplitIO.Attributes;
529
- ip: string;
530
- hostname: string;
529
+ ip: string | false;
530
+ hostname: string | false;
531
531
  sdkLanguageVersion: string;
532
532
  };
533
533
  /**
@@ -55,7 +55,8 @@ export declare function isIntegerNumber(val: any): boolean;
55
55
  */
56
56
  export declare function isNaNNumber(val: any): boolean;
57
57
  /**
58
- * Validates if a value is an object with the Object prototype (map object).
58
+ * Validates if a value is an object created by the Object constructor (plain object).
59
+ * It checks `constructor.name` to avoid false negatives when validating values on a separate VM context, which has its own global built-ins.
59
60
  */
60
61
  export declare function isObject(obj: any): boolean;
61
62
  /**
@@ -44,5 +44,12 @@ interface IMapConstructor {
44
44
  new <K, V>(entries?: readonly (readonly [K, V])[] | null): IMap<K, V>;
45
45
  readonly prototype: IMap<any, any>;
46
46
  }
47
+ /**
48
+ * return the Map constructor to use. If native Map is not available or it doesn't support the required features (e.g., IE11),
49
+ * a ponyfill with minimal features is returned instead.
50
+ *
51
+ * Exported for testing purposes only.
52
+ */
53
+ export declare function __getMapConstructor(): IMapConstructor;
47
54
  export declare const _Map: IMapConstructor;
48
55
  export {};
@@ -13,7 +13,11 @@ export interface ISettingsValidationParams {
13
13
  } & {
14
14
  startup: ISettings['startup'];
15
15
  };
16
- /** Function to define runtime values (`settings.runtime`) */
16
+ /** If true, validates core.key */
17
+ acceptKey?: boolean;
18
+ /** If true, validates core.trafficType */
19
+ acceptTT?: boolean;
20
+ /** Define runtime values (`settings.runtime`) */
17
21
  runtime: (settings: ISettings) => ISettings['runtime'];
18
22
  /** Storage validator (`settings.storage`) */
19
23
  storage?: (settings: ISettings) => ISettings['storage'];
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.userConsentProps = void 0;
4
- var constants_1 = require("../logger/constants");
5
- var constants_2 = require("../utils/constants");
6
- var lang_1 = require("../utils/lang");
7
- // Extend client-side factory instances with user consent getter/setter
8
- function userConsentProps(settings, syncManager) {
9
- var log = settings.log;
10
- return {
11
- setUserConsent: function (consent) {
12
- var _a, _b;
13
- // validate input param
14
- if (!(0, lang_1.isBoolean)(consent)) {
15
- log.warn(constants_1.ERROR_NOT_BOOLEAN, ['setUserConsent']);
16
- return false;
17
- }
18
- var newConsentStatus = consent ? constants_2.CONSENT_GRANTED : constants_2.CONSENT_DECLINED;
19
- if (settings.userConsent !== newConsentStatus) { // @ts-ignore, modify readonly prop
20
- settings.userConsent = newConsentStatus;
21
- if (consent)
22
- (_a = syncManager === null || syncManager === void 0 ? void 0 : syncManager.submitter) === null || _a === void 0 ? void 0 : _a.start(); // resumes submitters if transitioning to GRANTED
23
- else
24
- (_b = syncManager === null || syncManager === void 0 ? void 0 : syncManager.submitter) === null || _b === void 0 ? void 0 : _b.stop(); // pauses submitters if transitioning to DECLINED
25
- log.info(constants_1.USER_CONSENT_UPDATED, [settings.userConsent, newConsentStatus]);
26
- }
27
- else {
28
- log.info(constants_1.USER_CONSENT_NOT_UPDATED, [newConsentStatus]);
29
- }
30
- return true;
31
- },
32
- getUserConsent: function () {
33
- return settings.userConsent;
34
- }
35
- };
36
- }
37
- exports.userConsentProps = userConsentProps;
@@ -1 +0,0 @@
1
- export {};
@@ -1,33 +0,0 @@
1
- import { ERROR_NOT_BOOLEAN, USER_CONSENT_UPDATED, USER_CONSENT_NOT_UPDATED } from '../logger/constants';
2
- import { CONSENT_GRANTED, CONSENT_DECLINED } from '../utils/constants';
3
- import { isBoolean } from '../utils/lang';
4
- // Extend client-side factory instances with user consent getter/setter
5
- export function userConsentProps(settings, syncManager) {
6
- var log = settings.log;
7
- return {
8
- setUserConsent: function (consent) {
9
- var _a, _b;
10
- // validate input param
11
- if (!isBoolean(consent)) {
12
- log.warn(ERROR_NOT_BOOLEAN, ['setUserConsent']);
13
- return false;
14
- }
15
- var newConsentStatus = consent ? CONSENT_GRANTED : CONSENT_DECLINED;
16
- if (settings.userConsent !== newConsentStatus) { // @ts-ignore, modify readonly prop
17
- settings.userConsent = newConsentStatus;
18
- if (consent)
19
- (_a = syncManager === null || syncManager === void 0 ? void 0 : syncManager.submitter) === null || _a === void 0 ? void 0 : _a.start(); // resumes submitters if transitioning to GRANTED
20
- else
21
- (_b = syncManager === null || syncManager === void 0 ? void 0 : syncManager.submitter) === null || _b === void 0 ? void 0 : _b.stop(); // pauses submitters if transitioning to DECLINED
22
- log.info(USER_CONSENT_UPDATED, [settings.userConsent, newConsentStatus]);
23
- }
24
- else {
25
- log.info(USER_CONSENT_NOT_UPDATED, [newConsentStatus]);
26
- }
27
- return true;
28
- },
29
- getUserConsent: function () {
30
- return settings.userConsent;
31
- }
32
- };
33
- }
@@ -1,21 +0,0 @@
1
- import { ISignalListener } from '../listeners/types';
2
- import { ISdkReadinessManager } from '../readiness/types';
3
- import { IStorageAsync, IStorageSync } from '../storages/types';
4
- import { ISyncManager } from '../sync/types';
5
- import { IEventTracker, IImpressionsTracker } from '../trackers/types';
6
- import { ISettings } from '../types';
7
-
8
- export interface IClientFactoryParams {
9
- storage: IStorageSync | IStorageAsync,
10
- sdkReadinessManager: ISdkReadinessManager,
11
- settings: ISettings
12
- impressionsTracker: IImpressionsTracker,
13
- eventTracker: IEventTracker,
14
- // @TODO add time tracker and metricCollectors (a.k.a metricTracker)?
15
- }
16
-
17
- export interface ISdkClientFactoryParams extends IClientFactoryParams {
18
- signalListener?: ISignalListener
19
- syncManager?: ISyncManager,
20
- sharedClient?: boolean
21
- }
@@ -1,40 +0,0 @@
1
- import { ERROR_NOT_BOOLEAN, USER_CONSENT_UPDATED, USER_CONSENT_NOT_UPDATED } from '../logger/constants';
2
- import { ISyncManager } from '../sync/types';
3
- import { ISettings } from '../types';
4
- import { CONSENT_GRANTED, CONSENT_DECLINED } from '../utils/constants';
5
- import { isBoolean } from '../utils/lang';
6
-
7
- // Extend client-side factory instances with user consent getter/setter
8
- export function userConsentProps(settings: ISettings, syncManager?: ISyncManager) {
9
-
10
- const log = settings.log;
11
-
12
- return {
13
- setUserConsent(consent: unknown) {
14
- // validate input param
15
- if (!isBoolean(consent)) {
16
- log.warn(ERROR_NOT_BOOLEAN, ['setUserConsent']);
17
- return false;
18
- }
19
-
20
- const newConsentStatus = consent ? CONSENT_GRANTED : CONSENT_DECLINED;
21
-
22
- if (settings.userConsent !== newConsentStatus) { // @ts-ignore, modify readonly prop
23
- settings.userConsent = newConsentStatus;
24
-
25
- if (consent) syncManager?.submitter?.start(); // resumes submitters if transitioning to GRANTED
26
- else syncManager?.submitter?.stop(); // pauses submitters if transitioning to DECLINED
27
-
28
- log.info(USER_CONSENT_UPDATED, [settings.userConsent, newConsentStatus]);
29
- } else {
30
- log.info(USER_CONSENT_NOT_UPDATED, [newConsentStatus]);
31
- }
32
-
33
- return true;
34
- },
35
-
36
- getUserConsent() {
37
- return settings.userConsent;
38
- }
39
- };
40
- }