@splitsoftware/splitio-commons 1.2.1-rc.9 → 1.3.1-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.
- package/CHANGES.txt +18 -0
- package/cjs/{utils/consent.js → consent/index.js} +1 -1
- package/cjs/consent/sdkUserConsent.js +58 -0
- package/cjs/listeners/browser.js +1 -1
- package/cjs/logger/constants.js +3 -2
- package/cjs/logger/messages/info.js +1 -0
- package/cjs/readiness/sdkReadinessManager.js +5 -3
- package/cjs/sdkClient/sdkClient.js +3 -3
- package/cjs/sdkClient/sdkClientMethodCS.js +3 -5
- package/cjs/sdkClient/sdkClientMethodCSWithTT.js +3 -5
- package/cjs/sdkFactory/index.js +3 -2
- package/cjs/sync/syncManagerOnline.js +1 -1
- package/cjs/utils/inputValidation/attributes.js +1 -1
- package/cjs/utils/lang/index.js +4 -2
- package/cjs/utils/settingsValidation/index.js +8 -6
- package/esm/{utils/consent.js → consent/index.js} +1 -1
- package/esm/consent/sdkUserConsent.js +54 -0
- package/esm/listeners/browser.js +1 -1
- package/esm/logger/constants.js +1 -0
- package/esm/logger/messages/info.js +1 -0
- package/esm/readiness/sdkReadinessManager.js +5 -3
- package/esm/sdkClient/sdkClient.js +3 -3
- package/esm/sdkClient/sdkClientMethodCS.js +3 -5
- package/esm/sdkClient/sdkClientMethodCSWithTT.js +3 -5
- package/esm/sdkFactory/index.js +3 -2
- package/esm/sync/syncManagerOnline.js +1 -1
- package/esm/utils/inputValidation/attributes.js +1 -1
- package/esm/utils/lang/index.js +4 -2
- package/esm/utils/settingsValidation/index.js +8 -6
- package/package.json +14 -2
- package/src/{utils/consent.ts → consent/index.ts} +1 -1
- package/src/consent/sdkUserConsent.ts +58 -0
- package/src/evaluator/parser/index.ts +1 -1
- package/src/evaluator/types.ts +2 -2
- package/src/evaluator/value/index.ts +2 -2
- package/src/evaluator/value/sanitize.ts +2 -2
- package/src/listeners/browser.ts +1 -1
- package/src/logger/constants.ts +1 -0
- package/src/logger/messages/info.ts +1 -0
- package/src/readiness/sdkReadinessManager.ts +7 -5
- package/src/sdkClient/client.ts +2 -3
- package/src/sdkClient/sdkClient.ts +4 -4
- package/src/sdkClient/sdkClientMethod.ts +2 -2
- package/src/sdkClient/sdkClientMethodCS.ts +4 -5
- package/src/sdkClient/sdkClientMethodCSWithTT.ts +4 -5
- package/src/sdkFactory/index.ts +3 -2
- package/src/sdkFactory/types.ts +13 -3
- package/src/sync/syncManagerOnline.ts +1 -1
- package/src/trackers/impressionsTracker.ts +2 -2
- package/src/types.ts +2 -2
- package/src/utils/inputValidation/attributes.ts +1 -2
- package/src/utils/lang/index.ts +7 -3
- package/src/utils/settingsValidation/index.ts +8 -6
- package/src/utils/settingsValidation/types.ts +4 -2
- package/types/consent/index.d.ts +2 -0
- package/types/consent/sdkUserConsent.d.ts +13 -0
- package/types/evaluator/types.d.ts +2 -2
- package/types/evaluator/value/index.d.ts +1 -1
- package/types/evaluator/value/sanitize.d.ts +1 -1
- package/types/logger/constants.d.ts +1 -0
- package/types/sdkClient/client.d.ts +2 -2
- package/types/sdkClient/sdkClient.d.ts +2 -2
- package/types/sdkClient/sdkClientMethod.d.ts +2 -2
- package/types/sdkClient/sdkClientMethodCS.d.ts +2 -2
- package/types/sdkClient/sdkClientMethodCSWithTT.d.ts +2 -2
- package/types/sdkFactory/types.d.ts +12 -3
- package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +8 -10
- package/types/storages/inRedis/TelemetryCacheInRedis.d.ts +19 -0
- package/types/storages/pluggable/TelemetryCachePluggable.d.ts +17 -1
- package/types/sync/submitters/telemetrySyncTask.d.ts +16 -6
- package/types/trackers/telemetryTracker.d.ts +4 -0
- package/types/types.d.ts +2 -2
- package/types/utils/lang/index.d.ts +2 -1
- package/types/utils/settingsValidation/types.d.ts +4 -2
- package/cjs/sdkClient/types.js +0 -2
- package/cjs/sdkFactory/userConsentProps.js +0 -37
- package/esm/sdkClient/types.js +0 -1
- package/esm/sdkFactory/userConsentProps.js +0 -33
- package/src/sdkClient/types.ts +0 -21
- package/src/sdkFactory/userConsentProps.ts +0 -40
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SplitIO } from '../types';
|
|
2
|
-
import {
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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?: (
|
|
50
|
+
extraProps?: (params: ISdkFactoryContext) => object;
|
|
42
51
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImpressionDataType, EventDataType, StreamingEvent, Method, OperationType } from '../../sync/submitters/types';
|
|
1
|
+
import { ImpressionDataType, EventDataType, LastSync, HttpErrors, HttpLatencies, StreamingEvent, Method, OperationType, MethodExceptions, MethodLatencies } from '../../sync/submitters/types';
|
|
2
2
|
import { TelemetryCacheSync } from '../types';
|
|
3
3
|
export declare class TelemetryCacheInMemory implements TelemetryCacheSync {
|
|
4
4
|
private timeUntilReady?;
|
|
@@ -17,16 +17,14 @@ export declare class TelemetryCacheInMemory implements TelemetryCacheSync {
|
|
|
17
17
|
getEventStats(type: EventDataType): number;
|
|
18
18
|
recordEventStats(type: EventDataType, count: number): void;
|
|
19
19
|
private lastSync;
|
|
20
|
-
getLastSynchronization():
|
|
20
|
+
getLastSynchronization(): LastSync;
|
|
21
21
|
recordSuccessfulSync(resource: OperationType, timeMs: number): void;
|
|
22
22
|
private httpErrors;
|
|
23
|
-
popHttpErrors():
|
|
24
|
-
|
|
25
|
-
}>;
|
|
26
|
-
recordSyncError(resource: OperationType, status: number): void;
|
|
23
|
+
popHttpErrors(): HttpErrors;
|
|
24
|
+
recordHttpError(resource: OperationType, status: number): void;
|
|
27
25
|
private httpLatencies;
|
|
28
|
-
popHttpLatencies():
|
|
29
|
-
|
|
26
|
+
popHttpLatencies(): HttpLatencies;
|
|
27
|
+
recordHttpLatency(resource: OperationType, latencyMs: number): void;
|
|
30
28
|
private authRejections;
|
|
31
29
|
popAuthRejections(): number;
|
|
32
30
|
recordAuthRejections(): void;
|
|
@@ -43,9 +41,9 @@ export declare class TelemetryCacheInMemory implements TelemetryCacheSync {
|
|
|
43
41
|
getSessionLength(): number | undefined;
|
|
44
42
|
recordSessionLength(ms: number): void;
|
|
45
43
|
private exceptions;
|
|
46
|
-
popExceptions():
|
|
44
|
+
popExceptions(): MethodExceptions;
|
|
47
45
|
recordException(method: Method): void;
|
|
48
46
|
private latencies;
|
|
49
|
-
popLatencies():
|
|
47
|
+
popLatencies(): MethodLatencies;
|
|
50
48
|
recordLatency(method: Method, latencyMs: number): void;
|
|
51
49
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ILogger } from '../../logger/types';
|
|
2
|
+
import { Method } from '../../sync/submitters/types';
|
|
3
|
+
import { KeyBuilderSS } from '../KeyBuilderSS';
|
|
4
|
+
import { TelemetryCacheAsync } from '../types';
|
|
5
|
+
import { Redis } from 'ioredis';
|
|
6
|
+
export declare class TelemetryCacheInRedis implements TelemetryCacheAsync {
|
|
7
|
+
private readonly log;
|
|
8
|
+
private readonly keys;
|
|
9
|
+
private readonly redis;
|
|
10
|
+
/**
|
|
11
|
+
* Create a Telemetry cache that uses a storage wrapper.
|
|
12
|
+
* @param log Logger instance.
|
|
13
|
+
* @param keys Key builder.
|
|
14
|
+
* @param redis Redis client.
|
|
15
|
+
*/
|
|
16
|
+
constructor(log: ILogger, keys: KeyBuilderSS, redis: Redis);
|
|
17
|
+
recordLatency(method: Method, latencyMs: number): Promise<number | void>;
|
|
18
|
+
recordException(method: Method): Promise<number | void>;
|
|
19
|
+
}
|
|
@@ -1,2 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import { ILogger } from '../../logger/types';
|
|
2
|
+
import { Method } from '../../sync/submitters/types';
|
|
3
|
+
import { KeyBuilderSS } from '../KeyBuilderSS';
|
|
4
|
+
import { IPluggableStorageWrapper, TelemetryCacheAsync } from '../types';
|
|
5
|
+
export declare class TelemetryCachePluggable implements TelemetryCacheAsync {
|
|
6
|
+
private readonly log;
|
|
7
|
+
private readonly keys;
|
|
8
|
+
private readonly wrapper;
|
|
9
|
+
/**
|
|
10
|
+
* Create a Telemetry cache that uses a storage wrapper.
|
|
11
|
+
* @param log Logger instance.
|
|
12
|
+
* @param keys Key builder.
|
|
13
|
+
* @param wrapper Adapted wrapper storage.
|
|
14
|
+
*/
|
|
15
|
+
constructor(log: ILogger, keys: KeyBuilderSS, wrapper: IPluggableStorageWrapper);
|
|
16
|
+
recordLatency(method: Method, latencyMs: number): Promise<number | void>;
|
|
17
|
+
recordException(method: Method): Promise<number | void>;
|
|
2
18
|
}
|
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
import { ISyncTask, ITimeTracker } from '../types';
|
|
2
|
-
import {
|
|
2
|
+
import { ISplitApi } from '../../services/types';
|
|
3
3
|
import { IStorageSync, TelemetryCacheSync } from '../../storages/types';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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
|
|
10
|
+
export declare function telemetryCacheStatsAdapter({ splits, segments, telemetry }: IStorageSync & {
|
|
11
|
+
telemetry: TelemetryCacheSync;
|
|
12
|
+
}): {
|
|
10
13
|
isEmpty(): boolean;
|
|
11
14
|
clear(): void;
|
|
12
|
-
state():
|
|
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(
|
|
25
|
+
export declare function telemetrySyncTaskFactory(settings: ISettings, { postMetricsUsage, postMetricsConfig }: ISplitApi, storage: IStorageSync & {
|
|
26
|
+
telemetry: TelemetryCacheSync;
|
|
27
|
+
}, telemetryRefreshRate: number, readiness: IReadinessManager, latencyTracker?: ITimeTracker): ISyncTask;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { TelemetryCacheAsync, TelemetryCacheSync } from '../storages/types';
|
|
2
|
+
import { ISettings } from '../types';
|
|
3
|
+
import { ITelemetryTracker } from './types';
|
|
4
|
+
export declare function telemetryTrackerFactory(settings: ISettings, telemetryCache?: TelemetryCacheAsync | TelemetryCacheSync, now?: () => number): ITelemetryTracker;
|
package/types/types.d.ts
CHANGED
|
@@ -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
|
|
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
|
/**
|
|
@@ -13,8 +13,10 @@ export interface ISettingsValidationParams {
|
|
|
13
13
|
} & {
|
|
14
14
|
startup: ISettings['startup'];
|
|
15
15
|
};
|
|
16
|
-
/** If true, validates core.key
|
|
17
|
-
|
|
16
|
+
/** If true, validates core.key */
|
|
17
|
+
acceptKey?: boolean;
|
|
18
|
+
/** If true, validates core.trafficType */
|
|
19
|
+
acceptTT?: boolean;
|
|
18
20
|
/** Define runtime values (`settings.runtime`) */
|
|
19
21
|
runtime: (settings: ISettings) => ISettings['runtime'];
|
|
20
22
|
/** Storage validator (`settings.storage`) */
|
package/cjs/sdkClient/types.js
DELETED
|
@@ -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;
|
package/esm/sdkClient/types.js
DELETED
|
@@ -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
|
-
}
|
package/src/sdkClient/types.ts
DELETED
|
@@ -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
|
-
}
|