@splitsoftware/splitio-commons 1.2.1-rc.11 → 1.2.1-rc.12

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 (42) hide show
  1. package/cjs/{utils/consent.js → consent/index.js} +1 -1
  2. package/cjs/consent/sdkUserConsent.js +58 -0
  3. package/cjs/listeners/browser.js +1 -1
  4. package/cjs/sdkClient/sdkClient.js +3 -3
  5. package/cjs/sdkClient/sdkClientMethodCS.js +3 -5
  6. package/cjs/sdkClient/sdkClientMethodCSWithTT.js +3 -5
  7. package/cjs/sdkFactory/index.js +3 -2
  8. package/cjs/sync/syncManagerOnline.js +1 -1
  9. package/esm/{utils/consent.js → consent/index.js} +1 -1
  10. package/esm/consent/sdkUserConsent.js +54 -0
  11. package/esm/listeners/browser.js +1 -1
  12. package/esm/sdkClient/sdkClient.js +3 -3
  13. package/esm/sdkClient/sdkClientMethodCS.js +3 -5
  14. package/esm/sdkClient/sdkClientMethodCSWithTT.js +3 -5
  15. package/esm/sdkFactory/index.js +3 -2
  16. package/esm/sync/syncManagerOnline.js +1 -1
  17. package/package.json +1 -1
  18. package/src/{utils/consent.ts → consent/index.ts} +1 -1
  19. package/src/consent/sdkUserConsent.ts +58 -0
  20. package/src/listeners/browser.ts +1 -1
  21. package/src/sdkClient/client.ts +2 -3
  22. package/src/sdkClient/sdkClient.ts +4 -4
  23. package/src/sdkClient/sdkClientMethod.ts +2 -2
  24. package/src/sdkClient/sdkClientMethodCS.ts +4 -5
  25. package/src/sdkClient/sdkClientMethodCSWithTT.ts +4 -5
  26. package/src/sdkFactory/index.ts +3 -2
  27. package/src/sdkFactory/types.ts +13 -3
  28. package/src/sync/syncManagerOnline.ts +1 -1
  29. package/types/consent/index.d.ts +2 -0
  30. package/types/consent/sdkUserConsent.d.ts +13 -0
  31. package/types/sdkClient/client.d.ts +2 -2
  32. package/types/sdkClient/sdkClient.d.ts +2 -2
  33. package/types/sdkClient/sdkClientMethod.d.ts +2 -2
  34. package/types/sdkClient/sdkClientMethodCS.d.ts +2 -2
  35. package/types/sdkClient/sdkClientMethodCSWithTT.d.ts +2 -2
  36. package/types/sdkFactory/types.d.ts +12 -3
  37. package/cjs/sdkClient/types.js +0 -2
  38. package/cjs/sdkFactory/userConsentProps.js +0 -40
  39. package/esm/sdkClient/types.js +0 -1
  40. package/esm/sdkFactory/userConsentProps.js +0 -36
  41. package/src/sdkClient/types.ts +0 -21
  42. package/src/sdkFactory/userConsentProps.ts +0 -42
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isConsentGranted = void 0;
4
- var constants_1 = require("./constants");
4
+ var constants_1 = require("../utils/constants");
5
5
  function isConsentGranted(settings) {
6
6
  var userConsent = settings.userConsent;
7
7
  // undefined userConsent is handled as granted (default)
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createUserConsentAPI = void 0;
4
+ var constants_1 = require("../logger/constants");
5
+ var index_1 = require("./index");
6
+ var constants_2 = require("../utils/constants");
7
+ var lang_1 = require("../utils/lang");
8
+ // User consent enum
9
+ var ConsentStatus = {
10
+ GRANTED: constants_2.CONSENT_GRANTED,
11
+ DECLINED: constants_2.CONSENT_DECLINED,
12
+ UNKNOWN: constants_2.CONSENT_UNKNOWN,
13
+ };
14
+ /**
15
+ * The public user consent API exposed via SplitFactory, used to control if the SDK tracks and sends impressions and events or not.
16
+ */
17
+ function createUserConsentAPI(params) {
18
+ var settings = params.settings, log = params.settings.log, syncManager = params.syncManager, _a = params.storage, events = _a.events, impressions = _a.impressions, impressionCounts = _a.impressionCounts;
19
+ if (!(0, index_1.isConsentGranted)(settings))
20
+ log.info(constants_1.USER_CONSENT_INITIAL, [settings.userConsent]);
21
+ return {
22
+ setStatus: function (consent) {
23
+ var _a, _b;
24
+ // validate input param
25
+ if (!(0, lang_1.isBoolean)(consent)) {
26
+ log.warn(constants_1.ERROR_NOT_BOOLEAN, ['setUserConsent']);
27
+ return false;
28
+ }
29
+ var newConsentStatus = consent ? constants_2.CONSENT_GRANTED : constants_2.CONSENT_DECLINED;
30
+ if (settings.userConsent !== newConsentStatus) {
31
+ log.info(constants_1.USER_CONSENT_UPDATED, [settings.userConsent, newConsentStatus]); // @ts-ignore, modify readonly prop
32
+ settings.userConsent = newConsentStatus;
33
+ if (consent) { // resumes submitters if transitioning to GRANTED
34
+ (_a = syncManager === null || syncManager === void 0 ? void 0 : syncManager.submitter) === null || _a === void 0 ? void 0 : _a.start();
35
+ }
36
+ else { // pauses submitters and drops tracked data if transitioning to DECLINED
37
+ (_b = syncManager === null || syncManager === void 0 ? void 0 : syncManager.submitter) === null || _b === void 0 ? void 0 : _b.stop();
38
+ // @ts-ignore, clear method is present in storage for standalone and partial consumer mode
39
+ if (events.clear)
40
+ events.clear(); // @ts-ignore
41
+ if (impressions.clear)
42
+ impressions.clear();
43
+ if (impressionCounts)
44
+ impressionCounts.clear();
45
+ }
46
+ }
47
+ else {
48
+ log.info(constants_1.USER_CONSENT_NOT_UPDATED, [newConsentStatus]);
49
+ }
50
+ return true;
51
+ },
52
+ getStatus: function () {
53
+ return settings.userConsent;
54
+ },
55
+ Status: ConsentStatus
56
+ };
57
+ }
58
+ exports.createUserConsentAPI = createUserConsentAPI;
@@ -6,7 +6,7 @@ var impressionCountsSyncTask_1 = require("../sync/submitters/impressionCountsSyn
6
6
  var constants_1 = require("../utils/constants");
7
7
  var objectAssign_1 = require("../utils/lang/objectAssign");
8
8
  var constants_2 = require("../logger/constants");
9
- var consent_1 = require("../utils/consent");
9
+ var consent_1 = require("../consent");
10
10
  // 'unload' event is used instead of 'beforeunload', since 'unload' is not a cancelable event, so no other listeners can stop the event from occurring.
11
11
  var UNLOAD_DOM_EVENT = 'unload';
12
12
  var EVENT_NAME = 'for unload page event.';
@@ -8,8 +8,8 @@ var clientInputValidation_1 = require("./clientInputValidation");
8
8
  /**
9
9
  * Creates an Sdk client, i.e., a base client with status and destroy interface
10
10
  */
11
- function sdkClientFactory(params) {
12
- var sdkReadinessManager = params.sdkReadinessManager, syncManager = params.syncManager, storage = params.storage, signalListener = params.signalListener, settings = params.settings, sharedClient = params.sharedClient;
11
+ function sdkClientFactory(params, isSharedClient) {
12
+ var sdkReadinessManager = params.sdkReadinessManager, syncManager = params.syncManager, storage = params.storage, signalListener = params.signalListener, settings = params.settings;
13
13
  return (0, objectAssign_1.objectAssign)(
14
14
  // Proto-linkage of the readiness Event Emitter
15
15
  Object.create(sdkReadinessManager.sdkStatus),
@@ -26,7 +26,7 @@ function sdkClientFactory(params) {
26
26
  sdkReadinessManager.readinessManager.destroy();
27
27
  signalListener && signalListener.stop();
28
28
  // Release the API Key if it is the main client
29
- if (!sharedClient)
29
+ if (!isSharedClient)
30
30
  (0, apiKey_1.releaseApiKey)(settings.core.authorizationKey);
31
31
  // Cleanup storage
32
32
  return storage.destroy();
@@ -19,8 +19,7 @@ var method = 'Client instantiation';
19
19
  */
20
20
  function sdkClientMethodCSFactory(params) {
21
21
  var storage = params.storage, syncManager = params.syncManager, sdkReadinessManager = params.sdkReadinessManager, _a = params.settings, key = _a.core.key, readyTimeout = _a.startup.readyTimeout, log = _a.log;
22
- var mainClientInstance = (0, clientCS_1.clientCSDecorator)(log, (0, sdkClient_1.sdkClientFactory)(params), // @ts-ignore
23
- key);
22
+ var mainClientInstance = (0, clientCS_1.clientCSDecorator)(log, (0, sdkClient_1.sdkClientFactory)(params), key);
24
23
  var parsedDefaultKey = (0, key_2.keyParser)(key);
25
24
  var defaultInstanceId = buildInstanceId(parsedDefaultKey);
26
25
  // Cache instances created per factory.
@@ -58,9 +57,8 @@ function sdkClientMethodCSFactory(params) {
58
57
  sdkReadinessManager: sharedSdkReadiness_1,
59
58
  storage: sharedStorage || storage,
60
59
  syncManager: sharedSyncManager,
61
- signalListener: undefined,
62
- sharedClient: true
63
- })), validKey);
60
+ signalListener: undefined, // only the main client "destroy" method stops the signal listener
61
+ }), true), validKey);
64
62
  sharedSyncManager && sharedSyncManager.start();
65
63
  log.info(constants_1.NEW_SHARED_CLIENT);
66
64
  }
@@ -21,8 +21,7 @@ var method = 'Client instantiation';
21
21
  */
22
22
  function sdkClientMethodCSFactory(params) {
23
23
  var storage = params.storage, syncManager = params.syncManager, sdkReadinessManager = params.sdkReadinessManager, _a = params.settings, _b = _a.core, key = _b.key, trafficType = _b.trafficType, readyTimeout = _a.startup.readyTimeout, log = _a.log;
24
- var mainClientInstance = (0, clientCS_1.clientCSDecorator)(log, (0, sdkClient_1.sdkClientFactory)(params), // @ts-ignore
25
- key, trafficType);
24
+ var mainClientInstance = (0, clientCS_1.clientCSDecorator)(log, (0, sdkClient_1.sdkClientFactory)(params), key, trafficType);
26
25
  var parsedDefaultKey = (0, key_2.keyParser)(key);
27
26
  var defaultInstanceId = buildInstanceId(parsedDefaultKey, trafficType);
28
27
  // Cache instances created per factory.
@@ -67,9 +66,8 @@ function sdkClientMethodCSFactory(params) {
67
66
  sdkReadinessManager: sharedSdkReadiness_1,
68
67
  storage: sharedStorage || storage,
69
68
  syncManager: sharedSyncManager,
70
- signalListener: undefined,
71
- sharedClient: true
72
- })), validKey, validTrafficType);
69
+ signalListener: undefined, // only the main client "destroy" method stops the signal listener
70
+ }), true), validKey, validTrafficType);
73
71
  sharedSyncManager && sharedSyncManager.start();
74
72
  log.info(constants_1.NEW_SHARED_CLIENT);
75
73
  }
@@ -64,7 +64,8 @@ function sdkFactory(params) {
64
64
  // signal listener
65
65
  var signalListener = SignalListener && new SignalListener(syncManager, settings, storage, splitApi);
66
66
  // Sdk client and manager
67
- var clientMethod = sdkClientMethodFactory({ eventTracker: eventTracker, impressionsTracker: impressionsTracker, sdkReadinessManager: sdkReadinessManager, settings: settings, storage: storage, syncManager: syncManager, signalListener: signalListener });
67
+ var ctx = { eventTracker: eventTracker, impressionsTracker: impressionsTracker, sdkReadinessManager: sdkReadinessManager, settings: settings, storage: storage, syncManager: syncManager, signalListener: signalListener };
68
+ var clientMethod = sdkClientMethodFactory(ctx);
68
69
  var managerInstance = sdkManagerFactory(log, storage.splits, sdkReadinessManager);
69
70
  syncManager && syncManager.start();
70
71
  signalListener && signalListener.start();
@@ -81,6 +82,6 @@ function sdkFactory(params) {
81
82
  // Logger wrapper API
82
83
  Logger: (0, sdkLogger_1.createLoggerAPI)(settings.log),
83
84
  settings: settings,
84
- }, extraProps && extraProps(settings, syncManager));
85
+ }, extraProps && extraProps(ctx));
85
86
  }
86
87
  exports.sdkFactory = sdkFactory;
@@ -4,7 +4,7 @@ exports.syncManagerOnlineFactory = void 0;
4
4
  var submitterManager_1 = require("./submitters/submitterManager");
5
5
  var constants_1 = require("./streaming/constants");
6
6
  var constants_2 = require("../logger/constants");
7
- var consent_1 = require("../utils/consent");
7
+ var consent_1 = require("../consent");
8
8
  /**
9
9
  * Online SyncManager factory.
10
10
  * Can be used for server-side API, and client-side API with or without multiple clients.
@@ -1,4 +1,4 @@
1
- import { CONSENT_GRANTED } from './constants';
1
+ import { CONSENT_GRANTED } from '../utils/constants';
2
2
  export function isConsentGranted(settings) {
3
3
  var userConsent = settings.userConsent;
4
4
  // undefined userConsent is handled as granted (default)
@@ -0,0 +1,54 @@
1
+ import { ERROR_NOT_BOOLEAN, USER_CONSENT_UPDATED, USER_CONSENT_NOT_UPDATED, USER_CONSENT_INITIAL } from '../logger/constants';
2
+ import { isConsentGranted } from './index';
3
+ import { CONSENT_GRANTED, CONSENT_DECLINED, CONSENT_UNKNOWN } from '../utils/constants';
4
+ import { isBoolean } from '../utils/lang';
5
+ // User consent enum
6
+ var ConsentStatus = {
7
+ GRANTED: CONSENT_GRANTED,
8
+ DECLINED: CONSENT_DECLINED,
9
+ UNKNOWN: CONSENT_UNKNOWN,
10
+ };
11
+ /**
12
+ * The public user consent API exposed via SplitFactory, used to control if the SDK tracks and sends impressions and events or not.
13
+ */
14
+ export function createUserConsentAPI(params) {
15
+ var settings = params.settings, log = params.settings.log, syncManager = params.syncManager, _a = params.storage, events = _a.events, impressions = _a.impressions, impressionCounts = _a.impressionCounts;
16
+ if (!isConsentGranted(settings))
17
+ log.info(USER_CONSENT_INITIAL, [settings.userConsent]);
18
+ return {
19
+ setStatus: function (consent) {
20
+ var _a, _b;
21
+ // validate input param
22
+ if (!isBoolean(consent)) {
23
+ log.warn(ERROR_NOT_BOOLEAN, ['setUserConsent']);
24
+ return false;
25
+ }
26
+ var newConsentStatus = consent ? CONSENT_GRANTED : CONSENT_DECLINED;
27
+ if (settings.userConsent !== newConsentStatus) {
28
+ log.info(USER_CONSENT_UPDATED, [settings.userConsent, newConsentStatus]); // @ts-ignore, modify readonly prop
29
+ settings.userConsent = newConsentStatus;
30
+ if (consent) { // resumes submitters if transitioning to GRANTED
31
+ (_a = syncManager === null || syncManager === void 0 ? void 0 : syncManager.submitter) === null || _a === void 0 ? void 0 : _a.start();
32
+ }
33
+ else { // pauses submitters and drops tracked data if transitioning to DECLINED
34
+ (_b = syncManager === null || syncManager === void 0 ? void 0 : syncManager.submitter) === null || _b === void 0 ? void 0 : _b.stop();
35
+ // @ts-ignore, clear method is present in storage for standalone and partial consumer mode
36
+ if (events.clear)
37
+ events.clear(); // @ts-ignore
38
+ if (impressions.clear)
39
+ impressions.clear();
40
+ if (impressionCounts)
41
+ impressionCounts.clear();
42
+ }
43
+ }
44
+ else {
45
+ log.info(USER_CONSENT_NOT_UPDATED, [newConsentStatus]);
46
+ }
47
+ return true;
48
+ },
49
+ getStatus: function () {
50
+ return settings.userConsent;
51
+ },
52
+ Status: ConsentStatus
53
+ };
54
+ }
@@ -3,7 +3,7 @@ import { fromImpressionCountsCollector } from '../sync/submitters/impressionCoun
3
3
  import { OPTIMIZED, DEBUG } from '../utils/constants';
4
4
  import { objectAssign } from '../utils/lang/objectAssign';
5
5
  import { CLEANUP_REGISTERING, CLEANUP_DEREGISTERING } from '../logger/constants';
6
- import { isConsentGranted } from '../utils/consent';
6
+ import { isConsentGranted } from '../consent';
7
7
  // 'unload' event is used instead of 'beforeunload', since 'unload' is not a cancelable event, so no other listeners can stop the event from occurring.
8
8
  var UNLOAD_DOM_EVENT = 'unload';
9
9
  var EVENT_NAME = 'for unload page event.';
@@ -5,8 +5,8 @@ import { clientInputValidationDecorator } from './clientInputValidation';
5
5
  /**
6
6
  * Creates an Sdk client, i.e., a base client with status and destroy interface
7
7
  */
8
- export function sdkClientFactory(params) {
9
- var sdkReadinessManager = params.sdkReadinessManager, syncManager = params.syncManager, storage = params.storage, signalListener = params.signalListener, settings = params.settings, sharedClient = params.sharedClient;
8
+ export function sdkClientFactory(params, isSharedClient) {
9
+ var sdkReadinessManager = params.sdkReadinessManager, syncManager = params.syncManager, storage = params.storage, signalListener = params.signalListener, settings = params.settings;
10
10
  return objectAssign(
11
11
  // Proto-linkage of the readiness Event Emitter
12
12
  Object.create(sdkReadinessManager.sdkStatus),
@@ -23,7 +23,7 @@ export function sdkClientFactory(params) {
23
23
  sdkReadinessManager.readinessManager.destroy();
24
24
  signalListener && signalListener.stop();
25
25
  // Release the API Key if it is the main client
26
- if (!sharedClient)
26
+ if (!isSharedClient)
27
27
  releaseApiKey(settings.core.authorizationKey);
28
28
  // Cleanup storage
29
29
  return storage.destroy();
@@ -16,8 +16,7 @@ var method = 'Client instantiation';
16
16
  */
17
17
  export function sdkClientMethodCSFactory(params) {
18
18
  var storage = params.storage, syncManager = params.syncManager, sdkReadinessManager = params.sdkReadinessManager, _a = params.settings, key = _a.core.key, readyTimeout = _a.startup.readyTimeout, log = _a.log;
19
- var mainClientInstance = clientCSDecorator(log, sdkClientFactory(params), // @ts-ignore
20
- key);
19
+ var mainClientInstance = clientCSDecorator(log, sdkClientFactory(params), key);
21
20
  var parsedDefaultKey = keyParser(key);
22
21
  var defaultInstanceId = buildInstanceId(parsedDefaultKey);
23
22
  // Cache instances created per factory.
@@ -55,9 +54,8 @@ export function sdkClientMethodCSFactory(params) {
55
54
  sdkReadinessManager: sharedSdkReadiness_1,
56
55
  storage: sharedStorage || storage,
57
56
  syncManager: sharedSyncManager,
58
- signalListener: undefined,
59
- sharedClient: true
60
- })), validKey);
57
+ signalListener: undefined, // only the main client "destroy" method stops the signal listener
58
+ }), true), validKey);
61
59
  sharedSyncManager && sharedSyncManager.start();
62
60
  log.info(NEW_SHARED_CLIENT);
63
61
  }
@@ -18,8 +18,7 @@ var method = 'Client instantiation';
18
18
  */
19
19
  export function sdkClientMethodCSFactory(params) {
20
20
  var storage = params.storage, syncManager = params.syncManager, sdkReadinessManager = params.sdkReadinessManager, _a = params.settings, _b = _a.core, key = _b.key, trafficType = _b.trafficType, readyTimeout = _a.startup.readyTimeout, log = _a.log;
21
- var mainClientInstance = clientCSDecorator(log, sdkClientFactory(params), // @ts-ignore
22
- key, trafficType);
21
+ var mainClientInstance = clientCSDecorator(log, sdkClientFactory(params), key, trafficType);
23
22
  var parsedDefaultKey = keyParser(key);
24
23
  var defaultInstanceId = buildInstanceId(parsedDefaultKey, trafficType);
25
24
  // Cache instances created per factory.
@@ -64,9 +63,8 @@ export function sdkClientMethodCSFactory(params) {
64
63
  sdkReadinessManager: sharedSdkReadiness_1,
65
64
  storage: sharedStorage || storage,
66
65
  syncManager: sharedSyncManager,
67
- signalListener: undefined,
68
- sharedClient: true
69
- })), validKey, validTrafficType);
66
+ signalListener: undefined, // only the main client "destroy" method stops the signal listener
67
+ }), true), validKey, validTrafficType);
70
68
  sharedSyncManager && sharedSyncManager.start();
71
69
  log.info(NEW_SHARED_CLIENT);
72
70
  }
@@ -61,7 +61,8 @@ export function sdkFactory(params) {
61
61
  // signal listener
62
62
  var signalListener = SignalListener && new SignalListener(syncManager, settings, storage, splitApi);
63
63
  // Sdk client and manager
64
- var clientMethod = sdkClientMethodFactory({ eventTracker: eventTracker, impressionsTracker: impressionsTracker, sdkReadinessManager: sdkReadinessManager, settings: settings, storage: storage, syncManager: syncManager, signalListener: signalListener });
64
+ var ctx = { eventTracker: eventTracker, impressionsTracker: impressionsTracker, sdkReadinessManager: sdkReadinessManager, settings: settings, storage: storage, syncManager: syncManager, signalListener: signalListener };
65
+ var clientMethod = sdkClientMethodFactory(ctx);
65
66
  var managerInstance = sdkManagerFactory(log, storage.splits, sdkReadinessManager);
66
67
  syncManager && syncManager.start();
67
68
  signalListener && signalListener.start();
@@ -78,5 +79,5 @@ export function sdkFactory(params) {
78
79
  // Logger wrapper API
79
80
  Logger: createLoggerAPI(settings.log),
80
81
  settings: settings,
81
- }, extraProps && extraProps(settings, syncManager));
82
+ }, extraProps && extraProps(ctx));
82
83
  }
@@ -1,7 +1,7 @@
1
1
  import { submitterManagerFactory } from './submitters/submitterManager';
2
2
  import { PUSH_SUBSYSTEM_UP, PUSH_SUBSYSTEM_DOWN } from './streaming/constants';
3
3
  import { SYNC_START_POLLING, SYNC_CONTINUE_POLLING, SYNC_STOP_POLLING } from '../logger/constants';
4
- import { isConsentGranted } from '../utils/consent';
4
+ import { isConsentGranted } from '../consent';
5
5
  /**
6
6
  * Online SyncManager factory.
7
7
  * Can be used for server-side API, and client-side API with or without multiple clients.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splitsoftware/splitio-commons",
3
- "version": "1.2.1-rc.11",
3
+ "version": "1.2.1-rc.12",
4
4
  "description": "Split Javascript SDK common components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -1,5 +1,5 @@
1
1
  import { ISettings } from '../types';
2
- import { CONSENT_GRANTED } from './constants';
2
+ import { CONSENT_GRANTED } from '../utils/constants';
3
3
 
4
4
  export function isConsentGranted(settings: ISettings) {
5
5
  const userConsent = settings.userConsent;
@@ -0,0 +1,58 @@
1
+ import { ERROR_NOT_BOOLEAN, USER_CONSENT_UPDATED, USER_CONSENT_NOT_UPDATED, USER_CONSENT_INITIAL } from '../logger/constants';
2
+ import { isConsentGranted } from './index';
3
+ import { CONSENT_GRANTED, CONSENT_DECLINED, CONSENT_UNKNOWN } from '../utils/constants';
4
+ import { isBoolean } from '../utils/lang';
5
+ import { ISdkFactoryContext } from '../sdkFactory/types';
6
+
7
+ // User consent enum
8
+ const ConsentStatus = {
9
+ GRANTED: CONSENT_GRANTED,
10
+ DECLINED: CONSENT_DECLINED,
11
+ UNKNOWN: CONSENT_UNKNOWN,
12
+ };
13
+
14
+ /**
15
+ * The public user consent API exposed via SplitFactory, used to control if the SDK tracks and sends impressions and events or not.
16
+ */
17
+ export function createUserConsentAPI(params: ISdkFactoryContext) {
18
+ const { settings, settings: { log }, syncManager, storage: { events, impressions, impressionCounts } } = params;
19
+
20
+ if (!isConsentGranted(settings)) log.info(USER_CONSENT_INITIAL, [settings.userConsent]);
21
+
22
+ return {
23
+ setStatus(consent: unknown) {
24
+ // validate input param
25
+ if (!isBoolean(consent)) {
26
+ log.warn(ERROR_NOT_BOOLEAN, ['setUserConsent']);
27
+ return false;
28
+ }
29
+
30
+ const newConsentStatus = consent ? CONSENT_GRANTED : CONSENT_DECLINED;
31
+
32
+ if (settings.userConsent !== newConsentStatus) {
33
+ log.info(USER_CONSENT_UPDATED, [settings.userConsent, newConsentStatus]); // @ts-ignore, modify readonly prop
34
+ settings.userConsent = newConsentStatus;
35
+
36
+ if (consent) { // resumes submitters if transitioning to GRANTED
37
+ syncManager?.submitter?.start();
38
+ } else { // pauses submitters and drops tracked data if transitioning to DECLINED
39
+ syncManager?.submitter?.stop();
40
+ // @ts-ignore, clear method is present in storage for standalone and partial consumer mode
41
+ if (events.clear) events.clear(); // @ts-ignore
42
+ if (impressions.clear) impressions.clear();
43
+ if (impressionCounts) impressionCounts.clear();
44
+ }
45
+ } else {
46
+ log.info(USER_CONSENT_NOT_UPDATED, [newConsentStatus]);
47
+ }
48
+
49
+ return true;
50
+ },
51
+
52
+ getStatus() {
53
+ return settings.userConsent;
54
+ },
55
+
56
+ Status: ConsentStatus
57
+ };
58
+ }
@@ -11,7 +11,7 @@ import { OPTIMIZED, DEBUG } from '../utils/constants';
11
11
  import { objectAssign } from '../utils/lang/objectAssign';
12
12
  import { CLEANUP_REGISTERING, CLEANUP_DEREGISTERING } from '../logger/constants';
13
13
  import { ISyncManager } from '../sync/types';
14
- import { isConsentGranted } from '../utils/consent';
14
+ import { isConsentGranted } from '../consent';
15
15
 
16
16
  // 'unload' event is used instead of 'beforeunload', since 'unload' is not a cancelable event, so no other listeners can stop the event from occurring.
17
17
  const UNLOAD_DOM_EVENT = 'unload';
@@ -5,17 +5,16 @@ import { validateSplitExistance } from '../utils/inputValidation/splitExistance'
5
5
  import { validateTrafficTypeExistance } from '../utils/inputValidation/trafficTypeExistance';
6
6
  import { SDK_NOT_READY } from '../utils/labels';
7
7
  import { CONTROL } from '../utils/constants';
8
- import { IClientFactoryParams } from './types';
9
8
  import { IEvaluationResult } from '../evaluator/types';
10
9
  import { SplitIO, ImpressionDTO } from '../types';
11
10
  import { IMPRESSION, IMPRESSION_QUEUEING } from '../logger/constants';
12
-
11
+ import { ISdkFactoryContext } from '../sdkFactory/types';
13
12
 
14
13
  /**
15
14
  * Creator of base client with getTreatments and track methods.
16
15
  */
17
16
  // @TODO missing time tracking to collect telemetry
18
- export function clientFactory(params: IClientFactoryParams): SplitIO.IClient | SplitIO.IAsyncClient {
17
+ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | SplitIO.IAsyncClient {
19
18
  const { sdkReadinessManager: { readinessManager }, storage, settings, impressionsTracker, eventTracker } = params;
20
19
  const { log, mode } = settings;
21
20
 
@@ -3,13 +3,13 @@ import { IStatusInterface, SplitIO } from '../types';
3
3
  import { releaseApiKey } from '../utils/inputValidation/apiKey';
4
4
  import { clientFactory } from './client';
5
5
  import { clientInputValidationDecorator } from './clientInputValidation';
6
- import { ISdkClientFactoryParams } from './types';
6
+ import { ISdkFactoryContext } from '../sdkFactory/types';
7
7
 
8
8
  /**
9
9
  * Creates an Sdk client, i.e., a base client with status and destroy interface
10
10
  */
11
- export function sdkClientFactory(params: ISdkClientFactoryParams): SplitIO.IClient | SplitIO.IAsyncClient {
12
- const { sdkReadinessManager, syncManager, storage, signalListener, settings, sharedClient } = params;
11
+ export function sdkClientFactory(params: ISdkFactoryContext, isSharedClient?: boolean): SplitIO.IClient | SplitIO.IAsyncClient {
12
+ const { sdkReadinessManager, syncManager, storage, signalListener, settings } = params;
13
13
 
14
14
  return objectAssign(
15
15
  // Proto-linkage of the readiness Event Emitter
@@ -35,7 +35,7 @@ export function sdkClientFactory(params: ISdkClientFactoryParams): SplitIO.IClie
35
35
  signalListener && signalListener.stop();
36
36
 
37
37
  // Release the API Key if it is the main client
38
- if (!sharedClient) releaseApiKey(settings.core.authorizationKey);
38
+ if (!isSharedClient) releaseApiKey(settings.core.authorizationKey);
39
39
 
40
40
  // Cleanup storage
41
41
  return storage.destroy();
@@ -1,12 +1,12 @@
1
- import { ISdkClientFactoryParams } from './types';
2
1
  import { SplitIO } from '../types';
3
2
  import { sdkClientFactory } from './sdkClient';
4
3
  import { RETRIEVE_CLIENT_DEFAULT } from '../logger/constants';
4
+ import { ISdkFactoryContext } from '../sdkFactory/types';
5
5
 
6
6
  /**
7
7
  * Factory of client method for server-side SDKs (ISDK and IAsyncSDK)
8
8
  */
9
- export function sdkClientMethodFactory(params: ISdkClientFactoryParams): () => SplitIO.IClient | SplitIO.IAsyncClient {
9
+ export function sdkClientMethodFactory(params: ISdkFactoryContext): () => SplitIO.IClient | SplitIO.IAsyncClient {
10
10
  const log = params.settings.log;
11
11
  const clientInstance = sdkClientFactory(params);
12
12
 
@@ -1,5 +1,4 @@
1
1
  import { clientCSDecorator } from './clientCS';
2
- import { ISdkClientFactoryParams } from './types';
3
2
  import { SplitIO } from '../types';
4
3
  import { validateKey } from '../utils/inputValidation/key';
5
4
  import { getMatching, keyParser } from '../utils/key';
@@ -8,6 +7,7 @@ import { ISyncManagerCS } from '../sync/types';
8
7
  import { objectAssign } from '../utils/lang/objectAssign';
9
8
  import { RETRIEVE_CLIENT_DEFAULT, NEW_SHARED_CLIENT, RETRIEVE_CLIENT_EXISTING } from '../logger/constants';
10
9
  import { SDK_SEGMENTS_ARRIVED } from '../readiness/constants';
10
+ import { ISdkFactoryContext } from '../sdkFactory/types';
11
11
 
12
12
  function buildInstanceId(key: SplitIO.SplitKey) {
13
13
  // @ts-ignore
@@ -20,12 +20,12 @@ const method = 'Client instantiation';
20
20
  * Factory of client method for the client-side API variant where TT is ignored and thus
21
21
  * clients don't have a binded TT for the track method.
22
22
  */
23
- export function sdkClientMethodCSFactory(params: ISdkClientFactoryParams): (key?: SplitIO.SplitKey) => SplitIO.ICsClient {
23
+ export function sdkClientMethodCSFactory(params: ISdkFactoryContext): (key?: SplitIO.SplitKey) => SplitIO.ICsClient {
24
24
  const { storage, syncManager, sdkReadinessManager, settings: { core: { key }, startup: { readyTimeout }, log } } = params;
25
25
 
26
26
  const mainClientInstance = clientCSDecorator(
27
27
  log,
28
- sdkClientFactory(params) as SplitIO.IClient, // @ts-ignore
28
+ sdkClientFactory(params) as SplitIO.IClient,
29
29
  key
30
30
  );
31
31
 
@@ -76,8 +76,7 @@ export function sdkClientMethodCSFactory(params: ISdkClientFactoryParams): (key?
76
76
  storage: sharedStorage || storage,
77
77
  syncManager: sharedSyncManager,
78
78
  signalListener: undefined, // only the main client "destroy" method stops the signal listener
79
- sharedClient: true
80
- })) as SplitIO.IClient,
79
+ }), true) as SplitIO.IClient,
81
80
  validKey
82
81
  );
83
82
 
@@ -1,5 +1,4 @@
1
1
  import { clientCSDecorator } from './clientCS';
2
- import { ISdkClientFactoryParams } from './types';
3
2
  import { SplitIO } from '../types';
4
3
  import { validateKey } from '../utils/inputValidation/key';
5
4
  import { validateTrafficType } from '../utils/inputValidation/trafficType';
@@ -9,6 +8,7 @@ import { ISyncManagerCS } from '../sync/types';
9
8
  import { objectAssign } from '../utils/lang/objectAssign';
10
9
  import { RETRIEVE_CLIENT_DEFAULT, NEW_SHARED_CLIENT, RETRIEVE_CLIENT_EXISTING } from '../logger/constants';
11
10
  import { SDK_SEGMENTS_ARRIVED } from '../readiness/constants';
11
+ import { ISdkFactoryContext } from '../sdkFactory/types';
12
12
 
13
13
  function buildInstanceId(key: SplitIO.SplitKey, trafficType?: string) {
14
14
  // @ts-ignore
@@ -22,12 +22,12 @@ const method = 'Client instantiation';
22
22
  * where clients can have a binded TT for the track method, which is provided via the settings
23
23
  * (default client) or the client method (shared clients).
24
24
  */
25
- export function sdkClientMethodCSFactory(params: ISdkClientFactoryParams): (key?: SplitIO.SplitKey, trafficType?: string) => SplitIO.ICsClient {
25
+ export function sdkClientMethodCSFactory(params: ISdkFactoryContext): (key?: SplitIO.SplitKey, trafficType?: string) => SplitIO.ICsClient {
26
26
  const { storage, syncManager, sdkReadinessManager, settings: { core: { key, trafficType }, startup: { readyTimeout }, log } } = params;
27
27
 
28
28
  const mainClientInstance = clientCSDecorator(
29
29
  log,
30
- sdkClientFactory(params) as SplitIO.IClient, // @ts-ignore
30
+ sdkClientFactory(params) as SplitIO.IClient,
31
31
  key,
32
32
  trafficType
33
33
  );
@@ -86,8 +86,7 @@ export function sdkClientMethodCSFactory(params: ISdkClientFactoryParams): (key?
86
86
  storage: sharedStorage || storage,
87
87
  syncManager: sharedSyncManager,
88
88
  signalListener: undefined, // only the main client "destroy" method stops the signal listener
89
- sharedClient: true
90
- })) as SplitIO.IClient,
89
+ }), true) as SplitIO.IClient,
91
90
  validKey,
92
91
  validTrafficType
93
92
  );
@@ -81,7 +81,8 @@ export function sdkFactory(params: ISdkFactoryParams): SplitIO.ICsSDK | SplitIO.
81
81
  const signalListener = SignalListener && new SignalListener(syncManager, settings, storage, splitApi);
82
82
 
83
83
  // Sdk client and manager
84
- const clientMethod = sdkClientMethodFactory({ eventTracker, impressionsTracker, sdkReadinessManager, settings, storage, syncManager, signalListener });
84
+ const ctx = { eventTracker, impressionsTracker, sdkReadinessManager, settings, storage, syncManager, signalListener };
85
+ const clientMethod = sdkClientMethodFactory(ctx);
85
86
  const managerInstance = sdkManagerFactory(log, storage.splits, sdkReadinessManager);
86
87
 
87
88
  syncManager && syncManager.start();
@@ -104,5 +105,5 @@ export function sdkFactory(params: ISdkFactoryParams): SplitIO.ICsSDK | SplitIO.
104
105
  Logger: createLoggerAPI(settings.log),
105
106
 
106
107
  settings,
107
- }, extraProps && extraProps(settings, syncManager));
108
+ }, extraProps && extraProps(ctx));
108
109
  }
@@ -2,13 +2,23 @@ import { IIntegrationManager, IIntegrationFactoryParams } from '../integrations/
2
2
  import { ISignalListener } from '../listeners/types';
3
3
  import { ILogger } from '../logger/types';
4
4
  import { ISdkReadinessManager } from '../readiness/types';
5
- import { ISdkClientFactoryParams } from '../sdkClient/types';
6
5
  import { IFetch, ISplitApi, IEventSourceConstructor } from '../services/types';
7
6
  import { IStorageAsync, IStorageSync, ISplitsCacheSync, ISplitsCacheAsync, IStorageFactoryParams } from '../storages/types';
8
7
  import { ISyncManager, ISyncManagerFactoryParams } from '../sync/types';
9
8
  import { IImpressionObserver } from '../trackers/impressionObserver/types';
9
+ import { IImpressionsTracker, IEventTracker } from '../trackers/types';
10
10
  import { SplitIO, ISettings, IEventEmitter } from '../types';
11
11
 
12
+ export interface ISdkFactoryContext {
13
+ storage: IStorageSync | IStorageAsync,
14
+ sdkReadinessManager: ISdkReadinessManager,
15
+ settings: ISettings
16
+ impressionsTracker: IImpressionsTracker,
17
+ eventTracker: IEventTracker,
18
+ signalListener?: ISignalListener
19
+ syncManager?: ISyncManager,
20
+ }
21
+
12
22
  /**
13
23
  * Environment related dependencies.
14
24
  * These getters are called a fixed number of times per factory instantiation.
@@ -53,7 +63,7 @@ export interface ISdkFactoryParams {
53
63
 
54
64
  // Sdk client method factory (ISDK::client method).
55
65
  // It Allows to distinguish SDK clients with the client-side API (`ICsSDK`) or server-side API (`ISDK` or `IAsyncSDK`).
56
- sdkClientMethodFactory: (params: ISdkClientFactoryParams) => ({ (): SplitIO.ICsClient; (key: SplitIO.SplitKey, trafficType?: string | undefined): SplitIO.ICsClient; } | (() => SplitIO.IClient) | (() => SplitIO.IAsyncClient))
66
+ sdkClientMethodFactory: (params: ISdkFactoryContext) => ({ (): SplitIO.ICsClient; (key: SplitIO.SplitKey, trafficType?: string | undefined): SplitIO.ICsClient; } | (() => SplitIO.IClient) | (() => SplitIO.IAsyncClient))
57
67
 
58
68
  // Optional signal listener constructor. Used to handle special app states, like shutdown, app paused or resumed.
59
69
  // Pass only if `syncManager` (used by Node listener) and `splitApi` (used by Browser listener) are passed.
@@ -70,5 +80,5 @@ export interface ISdkFactoryParams {
70
80
  impressionsObserverFactory?: () => IImpressionObserver
71
81
 
72
82
  // Optional function to assign additional properties to the factory instance
73
- extraProps?: (settings: ISettings, syncManager?: ISyncManager) => object
83
+ extraProps?: (params: ISdkFactoryContext) => object
74
84
  }
@@ -6,7 +6,7 @@ import { IPushManager } from './streaming/types';
6
6
  import { IPollingManager, IPollingManagerCS } from './polling/types';
7
7
  import { PUSH_SUBSYSTEM_UP, PUSH_SUBSYSTEM_DOWN } from './streaming/constants';
8
8
  import { SYNC_START_POLLING, SYNC_CONTINUE_POLLING, SYNC_STOP_POLLING } from '../logger/constants';
9
- import { isConsentGranted } from '../utils/consent';
9
+ import { isConsentGranted } from '../consent';
10
10
 
11
11
  /**
12
12
  * Online SyncManager factory.
@@ -0,0 +1,2 @@
1
+ import { ISettings } from '../types';
2
+ export declare function isConsentGranted(settings: ISettings): boolean;
@@ -0,0 +1,13 @@
1
+ import { ISdkFactoryContext } from '../sdkFactory/types';
2
+ /**
3
+ * The public user consent API exposed via SplitFactory, used to control if the SDK tracks and sends impressions and events or not.
4
+ */
5
+ export declare function createUserConsentAPI(params: ISdkFactoryContext): {
6
+ setStatus(consent: unknown): boolean;
7
+ getStatus(): import("../types").ConsentStatus | undefined;
8
+ Status: {
9
+ GRANTED: string;
10
+ DECLINED: string;
11
+ UNKNOWN: string;
12
+ };
13
+ };
@@ -1,6 +1,6 @@
1
- import { IClientFactoryParams } from './types';
2
1
  import { SplitIO } from '../types';
2
+ import { ISdkFactoryContext } from '../sdkFactory/types';
3
3
  /**
4
4
  * Creator of base client with getTreatments and track methods.
5
5
  */
6
- export declare function clientFactory(params: IClientFactoryParams): SplitIO.IClient | SplitIO.IAsyncClient;
6
+ export declare function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | SplitIO.IAsyncClient;
@@ -1,6 +1,6 @@
1
1
  import { SplitIO } from '../types';
2
- import { ISdkClientFactoryParams } from './types';
2
+ import { ISdkFactoryContext } from '../sdkFactory/types';
3
3
  /**
4
4
  * Creates an Sdk client, i.e., a base client with status and destroy interface
5
5
  */
6
- export declare function sdkClientFactory(params: ISdkClientFactoryParams): SplitIO.IClient | SplitIO.IAsyncClient;
6
+ export declare function sdkClientFactory(params: ISdkFactoryContext, isSharedClient?: boolean): SplitIO.IClient | SplitIO.IAsyncClient;
@@ -1,6 +1,6 @@
1
- import { ISdkClientFactoryParams } from './types';
2
1
  import { SplitIO } from '../types';
2
+ import { ISdkFactoryContext } from '../sdkFactory/types';
3
3
  /**
4
4
  * Factory of client method for server-side SDKs (ISDK and IAsyncSDK)
5
5
  */
6
- export declare function sdkClientMethodFactory(params: ISdkClientFactoryParams): () => SplitIO.IClient | SplitIO.IAsyncClient;
6
+ export declare function sdkClientMethodFactory(params: ISdkFactoryContext): () => SplitIO.IClient | SplitIO.IAsyncClient;
@@ -1,7 +1,7 @@
1
- import { ISdkClientFactoryParams } from './types';
2
1
  import { SplitIO } from '../types';
2
+ import { ISdkFactoryContext } from '../sdkFactory/types';
3
3
  /**
4
4
  * Factory of client method for the client-side API variant where TT is ignored and thus
5
5
  * clients don't have a binded TT for the track method.
6
6
  */
7
- export declare function sdkClientMethodCSFactory(params: ISdkClientFactoryParams): (key?: SplitIO.SplitKey) => SplitIO.ICsClient;
7
+ export declare function sdkClientMethodCSFactory(params: ISdkFactoryContext): (key?: SplitIO.SplitKey) => SplitIO.ICsClient;
@@ -1,8 +1,8 @@
1
- import { ISdkClientFactoryParams } from './types';
2
1
  import { SplitIO } from '../types';
2
+ import { ISdkFactoryContext } from '../sdkFactory/types';
3
3
  /**
4
4
  * Factory of client method for the client-side (browser) variant of the Isomorphic JS SDK,
5
5
  * where clients can have a binded TT for the track method, which is provided via the settings
6
6
  * (default client) or the client method (shared clients).
7
7
  */
8
- export declare function sdkClientMethodCSFactory(params: ISdkClientFactoryParams): (key?: SplitIO.SplitKey, trafficType?: string) => SplitIO.ICsClient;
8
+ export declare function sdkClientMethodCSFactory(params: ISdkFactoryContext): (key?: SplitIO.SplitKey, trafficType?: string) => SplitIO.ICsClient;
@@ -2,12 +2,21 @@ import { IIntegrationManager, IIntegrationFactoryParams } from '../integrations/
2
2
  import { ISignalListener } from '../listeners/types';
3
3
  import { ILogger } from '../logger/types';
4
4
  import { ISdkReadinessManager } from '../readiness/types';
5
- import { ISdkClientFactoryParams } from '../sdkClient/types';
6
5
  import { IFetch, ISplitApi, IEventSourceConstructor } from '../services/types';
7
6
  import { IStorageAsync, IStorageSync, ISplitsCacheSync, ISplitsCacheAsync, IStorageFactoryParams } from '../storages/types';
8
7
  import { ISyncManager, ISyncManagerFactoryParams } from '../sync/types';
9
8
  import { IImpressionObserver } from '../trackers/impressionObserver/types';
9
+ import { IImpressionsTracker, IEventTracker } from '../trackers/types';
10
10
  import { SplitIO, ISettings, IEventEmitter } from '../types';
11
+ export interface ISdkFactoryContext {
12
+ storage: IStorageSync | IStorageAsync;
13
+ sdkReadinessManager: ISdkReadinessManager;
14
+ settings: ISettings;
15
+ impressionsTracker: IImpressionsTracker;
16
+ eventTracker: IEventTracker;
17
+ signalListener?: ISignalListener;
18
+ syncManager?: ISyncManager;
19
+ }
11
20
  /**
12
21
  * Environment related dependencies.
13
22
  * These getters are called a fixed number of times per factory instantiation.
@@ -28,7 +37,7 @@ export interface ISdkFactoryParams {
28
37
  splitApiFactory?: (settings: ISettings, platform: IPlatform) => ISplitApi;
29
38
  syncManagerFactory?: (params: ISyncManagerFactoryParams) => ISyncManager;
30
39
  sdkManagerFactory: (log: ILogger, splits: ISplitsCacheSync | ISplitsCacheAsync, sdkReadinessManager: ISdkReadinessManager) => SplitIO.IManager | SplitIO.IAsyncManager;
31
- sdkClientMethodFactory: (params: ISdkClientFactoryParams) => ({
40
+ sdkClientMethodFactory: (params: ISdkFactoryContext) => ({
32
41
  (): SplitIO.ICsClient;
33
42
  (key: SplitIO.SplitKey, trafficType?: string | undefined): SplitIO.ICsClient;
34
43
  } | (() => SplitIO.IClient) | (() => SplitIO.IAsyncClient));
@@ -38,5 +47,5 @@ export interface ISdkFactoryParams {
38
47
  serviceApi: ISplitApi | undefined) => ISignalListener;
39
48
  integrationsManagerFactory?: (params: IIntegrationFactoryParams) => IIntegrationManager | undefined;
40
49
  impressionsObserverFactory?: () => IImpressionObserver;
41
- extraProps?: (settings: ISettings, syncManager?: ISyncManager) => object;
50
+ extraProps?: (params: ISdkFactoryContext) => object;
42
51
  }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,40 +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 consent_1 = require("../utils/consent");
6
- var constants_2 = require("../utils/constants");
7
- var lang_1 = require("../utils/lang");
8
- // Extend client-side factory instances with user consent getter/setter
9
- function userConsentProps(settings, syncManager) {
10
- var log = settings.log;
11
- if (!(0, consent_1.isConsentGranted)(settings))
12
- log.info(constants_1.USER_CONSENT_INITIAL, [settings.userConsent]);
13
- return {
14
- setUserConsent: function (consent) {
15
- var _a, _b;
16
- // validate input param
17
- if (!(0, lang_1.isBoolean)(consent)) {
18
- log.warn(constants_1.ERROR_NOT_BOOLEAN, ['setUserConsent']);
19
- return false;
20
- }
21
- var newConsentStatus = consent ? constants_2.CONSENT_GRANTED : constants_2.CONSENT_DECLINED;
22
- if (settings.userConsent !== newConsentStatus) {
23
- log.info(constants_1.USER_CONSENT_UPDATED, [settings.userConsent, newConsentStatus]); // @ts-ignore, modify readonly prop
24
- settings.userConsent = newConsentStatus;
25
- if (consent)
26
- (_a = syncManager === null || syncManager === void 0 ? void 0 : syncManager.submitter) === null || _a === void 0 ? void 0 : _a.start(); // resumes submitters if transitioning to GRANTED
27
- else
28
- (_b = syncManager === null || syncManager === void 0 ? void 0 : syncManager.submitter) === null || _b === void 0 ? void 0 : _b.stop(); // pauses submitters if transitioning to DECLINED
29
- }
30
- else {
31
- log.info(constants_1.USER_CONSENT_NOT_UPDATED, [newConsentStatus]);
32
- }
33
- return true;
34
- },
35
- getUserConsent: function () {
36
- return settings.userConsent;
37
- }
38
- };
39
- }
40
- exports.userConsentProps = userConsentProps;
@@ -1 +0,0 @@
1
- export {};
@@ -1,36 +0,0 @@
1
- import { ERROR_NOT_BOOLEAN, USER_CONSENT_UPDATED, USER_CONSENT_NOT_UPDATED, USER_CONSENT_INITIAL } from '../logger/constants';
2
- import { isConsentGranted } from '../utils/consent';
3
- import { CONSENT_GRANTED, CONSENT_DECLINED } from '../utils/constants';
4
- import { isBoolean } from '../utils/lang';
5
- // Extend client-side factory instances with user consent getter/setter
6
- export function userConsentProps(settings, syncManager) {
7
- var log = settings.log;
8
- if (!isConsentGranted(settings))
9
- log.info(USER_CONSENT_INITIAL, [settings.userConsent]);
10
- return {
11
- setUserConsent: function (consent) {
12
- var _a, _b;
13
- // validate input param
14
- if (!isBoolean(consent)) {
15
- log.warn(ERROR_NOT_BOOLEAN, ['setUserConsent']);
16
- return false;
17
- }
18
- var newConsentStatus = consent ? CONSENT_GRANTED : CONSENT_DECLINED;
19
- if (settings.userConsent !== newConsentStatus) {
20
- log.info(USER_CONSENT_UPDATED, [settings.userConsent, newConsentStatus]); // @ts-ignore, modify readonly prop
21
- settings.userConsent = newConsentStatus;
22
- if (consent)
23
- (_a = syncManager === null || syncManager === void 0 ? void 0 : syncManager.submitter) === null || _a === void 0 ? void 0 : _a.start(); // resumes submitters if transitioning to GRANTED
24
- else
25
- (_b = syncManager === null || syncManager === void 0 ? void 0 : syncManager.submitter) === null || _b === void 0 ? void 0 : _b.stop(); // pauses submitters if transitioning to DECLINED
26
- }
27
- else {
28
- log.info(USER_CONSENT_NOT_UPDATED, [newConsentStatus]);
29
- }
30
- return true;
31
- },
32
- getUserConsent: function () {
33
- return settings.userConsent;
34
- }
35
- };
36
- }
@@ -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,42 +0,0 @@
1
- import { ERROR_NOT_BOOLEAN, USER_CONSENT_UPDATED, USER_CONSENT_NOT_UPDATED, USER_CONSENT_INITIAL } from '../logger/constants';
2
- import { ISyncManager } from '../sync/types';
3
- import { ISettings } from '../types';
4
- import { isConsentGranted } from '../utils/consent';
5
- import { CONSENT_GRANTED, CONSENT_DECLINED } from '../utils/constants';
6
- import { isBoolean } from '../utils/lang';
7
-
8
- // Extend client-side factory instances with user consent getter/setter
9
- export function userConsentProps(settings: ISettings, syncManager?: ISyncManager) {
10
-
11
- const log = settings.log;
12
-
13
- if (!isConsentGranted(settings)) log.info(USER_CONSENT_INITIAL, [settings.userConsent]);
14
-
15
- return {
16
- setUserConsent(consent: unknown) {
17
- // validate input param
18
- if (!isBoolean(consent)) {
19
- log.warn(ERROR_NOT_BOOLEAN, ['setUserConsent']);
20
- return false;
21
- }
22
-
23
- const newConsentStatus = consent ? CONSENT_GRANTED : CONSENT_DECLINED;
24
-
25
- if (settings.userConsent !== newConsentStatus) {
26
- log.info(USER_CONSENT_UPDATED, [settings.userConsent, newConsentStatus]); // @ts-ignore, modify readonly prop
27
- settings.userConsent = newConsentStatus;
28
-
29
- if (consent) syncManager?.submitter?.start(); // resumes submitters if transitioning to GRANTED
30
- else syncManager?.submitter?.stop(); // pauses submitters if transitioning to DECLINED
31
- } else {
32
- log.info(USER_CONSENT_NOT_UPDATED, [newConsentStatus]);
33
- }
34
-
35
- return true;
36
- },
37
-
38
- getUserConsent() {
39
- return settings.userConsent;
40
- }
41
- };
42
- }