@splitsoftware/splitio-commons 1.7.3 → 1.8.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 +6 -0
- package/LICENSE +1 -1
- package/cjs/sdkClient/sdkClient.js +26 -2
- package/esm/integrations/ga/GaToSplit.js +1 -1
- package/esm/sdkClient/sdkClient.js +26 -2
- package/package.json +1 -1
- package/src/integrations/ga/GaToSplit.ts +1 -1
- package/src/sdkClient/sdkClient.ts +29 -2
- package/src/sync/submitters/types.ts +1 -1
- package/src/types.ts +6 -0
- package/types/sync/submitters/types.d.ts +1 -1
- package/types/types.d.ts +6 -0
package/CHANGES.txt
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
1.8.1 (February 7, 2023)
|
|
2
|
+
- Updated a module import to remove a trailing comma that can cause issues with some bundlers.
|
|
3
|
+
|
|
4
|
+
1.8.0 (February 3, 2023)
|
|
5
|
+
- Added flush data method to client
|
|
6
|
+
|
|
1
7
|
1.7.3 (December 16, 2022)
|
|
2
8
|
- Updated unique keys cache for Redis and Pluggable storages to optimize the usage of the underlying storage.
|
|
3
9
|
- Updated some transitive dependencies for vulnerability fixes.
|
package/LICENSE
CHANGED
|
@@ -5,11 +5,32 @@ var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
|
5
5
|
var apiKey_1 = require("../utils/inputValidation/apiKey");
|
|
6
6
|
var client_1 = require("./client");
|
|
7
7
|
var clientInputValidation_1 = require("./clientInputValidation");
|
|
8
|
+
var COOLDOWN_TIME_IN_MILLIS = 1000;
|
|
8
9
|
/**
|
|
9
10
|
* Creates an Sdk client, i.e., a base client with status and destroy interface
|
|
10
11
|
*/
|
|
11
12
|
function sdkClientFactory(params, isSharedClient) {
|
|
12
13
|
var sdkReadinessManager = params.sdkReadinessManager, syncManager = params.syncManager, storage = params.storage, signalListener = params.signalListener, settings = params.settings, telemetryTracker = params.telemetryTracker, uniqueKeysTracker = params.uniqueKeysTracker;
|
|
14
|
+
var lastActionTime = 0;
|
|
15
|
+
function __cooldown(func, time) {
|
|
16
|
+
var now = Date.now();
|
|
17
|
+
//get the actual time elapsed in ms
|
|
18
|
+
var timeElapsed = now - lastActionTime;
|
|
19
|
+
//check if the time elapsed is less than desired cooldown
|
|
20
|
+
if (timeElapsed < time) {
|
|
21
|
+
//if yes, return message with remaining time in seconds
|
|
22
|
+
settings.log.warn("Flush cooldown, remaining time " + (time - timeElapsed) / 1000 + " seconds");
|
|
23
|
+
return Promise.resolve();
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
//Do the requested action and re-assign the lastActionTime
|
|
27
|
+
lastActionTime = now;
|
|
28
|
+
return func();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function __flush() {
|
|
32
|
+
return syncManager ? syncManager.flush() : Promise.resolve();
|
|
33
|
+
}
|
|
13
34
|
return (0, objectAssign_1.objectAssign)(
|
|
14
35
|
// Proto-linkage of the readiness Event Emitter
|
|
15
36
|
Object.create(sdkReadinessManager.sdkStatus),
|
|
@@ -17,14 +38,17 @@ function sdkClientFactory(params, isSharedClient) {
|
|
|
17
38
|
(0, clientInputValidation_1.clientInputValidationDecorator)(settings, (0, client_1.clientFactory)(params), sdkReadinessManager.readinessManager),
|
|
18
39
|
// Sdk destroy
|
|
19
40
|
{
|
|
41
|
+
flush: function () {
|
|
42
|
+
// @TODO define cooldown time
|
|
43
|
+
return __cooldown(__flush, COOLDOWN_TIME_IN_MILLIS);
|
|
44
|
+
},
|
|
20
45
|
destroy: function () {
|
|
21
46
|
// record stat before flushing data
|
|
22
47
|
if (!isSharedClient)
|
|
23
48
|
telemetryTracker.sessionLength();
|
|
24
49
|
// Stop background jobs
|
|
25
50
|
syncManager && syncManager.stop();
|
|
26
|
-
|
|
27
|
-
return flush.then(function () {
|
|
51
|
+
return __flush().then(function () {
|
|
28
52
|
// Cleanup event listeners
|
|
29
53
|
sdkReadinessManager.readinessManager.destroy();
|
|
30
54
|
signalListener && signalListener.stop();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable no-undef */
|
|
2
2
|
import { objectAssign } from '../../utils/lang/objectAssign';
|
|
3
3
|
import { isString, isFiniteNumber, uniqAsStrings } from '../../utils/lang';
|
|
4
|
-
import { validateEvent, validateEventValue, validateEventProperties, validateKey, validateTrafficType
|
|
4
|
+
import { validateEvent, validateEventValue, validateEventProperties, validateKey, validateTrafficType } from '../../utils/inputValidation';
|
|
5
5
|
var logPrefix = 'ga-to-split: ';
|
|
6
6
|
var logNameMapper = 'ga-to-split:mapper';
|
|
7
7
|
/**
|
|
@@ -2,11 +2,32 @@ import { objectAssign } from '../utils/lang/objectAssign';
|
|
|
2
2
|
import { releaseApiKey } from '../utils/inputValidation/apiKey';
|
|
3
3
|
import { clientFactory } from './client';
|
|
4
4
|
import { clientInputValidationDecorator } from './clientInputValidation';
|
|
5
|
+
var COOLDOWN_TIME_IN_MILLIS = 1000;
|
|
5
6
|
/**
|
|
6
7
|
* Creates an Sdk client, i.e., a base client with status and destroy interface
|
|
7
8
|
*/
|
|
8
9
|
export function sdkClientFactory(params, isSharedClient) {
|
|
9
10
|
var sdkReadinessManager = params.sdkReadinessManager, syncManager = params.syncManager, storage = params.storage, signalListener = params.signalListener, settings = params.settings, telemetryTracker = params.telemetryTracker, uniqueKeysTracker = params.uniqueKeysTracker;
|
|
11
|
+
var lastActionTime = 0;
|
|
12
|
+
function __cooldown(func, time) {
|
|
13
|
+
var now = Date.now();
|
|
14
|
+
//get the actual time elapsed in ms
|
|
15
|
+
var timeElapsed = now - lastActionTime;
|
|
16
|
+
//check if the time elapsed is less than desired cooldown
|
|
17
|
+
if (timeElapsed < time) {
|
|
18
|
+
//if yes, return message with remaining time in seconds
|
|
19
|
+
settings.log.warn("Flush cooldown, remaining time " + (time - timeElapsed) / 1000 + " seconds");
|
|
20
|
+
return Promise.resolve();
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
//Do the requested action and re-assign the lastActionTime
|
|
24
|
+
lastActionTime = now;
|
|
25
|
+
return func();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function __flush() {
|
|
29
|
+
return syncManager ? syncManager.flush() : Promise.resolve();
|
|
30
|
+
}
|
|
10
31
|
return objectAssign(
|
|
11
32
|
// Proto-linkage of the readiness Event Emitter
|
|
12
33
|
Object.create(sdkReadinessManager.sdkStatus),
|
|
@@ -14,14 +35,17 @@ export function sdkClientFactory(params, isSharedClient) {
|
|
|
14
35
|
clientInputValidationDecorator(settings, clientFactory(params), sdkReadinessManager.readinessManager),
|
|
15
36
|
// Sdk destroy
|
|
16
37
|
{
|
|
38
|
+
flush: function () {
|
|
39
|
+
// @TODO define cooldown time
|
|
40
|
+
return __cooldown(__flush, COOLDOWN_TIME_IN_MILLIS);
|
|
41
|
+
},
|
|
17
42
|
destroy: function () {
|
|
18
43
|
// record stat before flushing data
|
|
19
44
|
if (!isSharedClient)
|
|
20
45
|
telemetryTracker.sessionLength();
|
|
21
46
|
// Stop background jobs
|
|
22
47
|
syncManager && syncManager.stop();
|
|
23
|
-
|
|
24
|
-
return flush.then(function () {
|
|
48
|
+
return __flush().then(function () {
|
|
25
49
|
// Cleanup event listeners
|
|
26
50
|
sdkReadinessManager.readinessManager.destroy();
|
|
27
51
|
signalListener && signalListener.stop();
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
validateEventValue,
|
|
7
7
|
validateEventProperties,
|
|
8
8
|
validateKey,
|
|
9
|
-
validateTrafficType
|
|
9
|
+
validateTrafficType
|
|
10
10
|
} from '../../utils/inputValidation';
|
|
11
11
|
import { SplitIO } from '../../types';
|
|
12
12
|
import { Identity, GoogleAnalyticsToSplitOptions } from './types';
|
|
@@ -5,12 +5,36 @@ import { clientFactory } from './client';
|
|
|
5
5
|
import { clientInputValidationDecorator } from './clientInputValidation';
|
|
6
6
|
import { ISdkFactoryContext } from '../sdkFactory/types';
|
|
7
7
|
|
|
8
|
+
const COOLDOWN_TIME_IN_MILLIS = 1000;
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
* Creates an Sdk client, i.e., a base client with status and destroy interface
|
|
10
12
|
*/
|
|
11
13
|
export function sdkClientFactory(params: ISdkFactoryContext, isSharedClient?: boolean): SplitIO.IClient | SplitIO.IAsyncClient {
|
|
12
14
|
const { sdkReadinessManager, syncManager, storage, signalListener, settings, telemetryTracker, uniqueKeysTracker } = params;
|
|
13
15
|
|
|
16
|
+
let lastActionTime = 0;
|
|
17
|
+
|
|
18
|
+
function __cooldown(func: Function, time: number) {
|
|
19
|
+
const now = Date.now();
|
|
20
|
+
//get the actual time elapsed in ms
|
|
21
|
+
const timeElapsed = now - lastActionTime;
|
|
22
|
+
//check if the time elapsed is less than desired cooldown
|
|
23
|
+
if (timeElapsed < time){
|
|
24
|
+
//if yes, return message with remaining time in seconds
|
|
25
|
+
settings.log.warn(`Flush cooldown, remaining time ${(time-timeElapsed)/1000} seconds`);
|
|
26
|
+
return Promise.resolve();
|
|
27
|
+
} else {
|
|
28
|
+
//Do the requested action and re-assign the lastActionTime
|
|
29
|
+
lastActionTime = now;
|
|
30
|
+
return func();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function __flush() {
|
|
35
|
+
return syncManager ? syncManager.flush() : Promise.resolve();
|
|
36
|
+
}
|
|
37
|
+
|
|
14
38
|
return objectAssign(
|
|
15
39
|
// Proto-linkage of the readiness Event Emitter
|
|
16
40
|
Object.create(sdkReadinessManager.sdkStatus) as IStatusInterface,
|
|
@@ -24,15 +48,18 @@ export function sdkClientFactory(params: ISdkFactoryContext, isSharedClient?: bo
|
|
|
24
48
|
|
|
25
49
|
// Sdk destroy
|
|
26
50
|
{
|
|
51
|
+
flush() {
|
|
52
|
+
// @TODO define cooldown time
|
|
53
|
+
return __cooldown(__flush, COOLDOWN_TIME_IN_MILLIS);
|
|
54
|
+
},
|
|
27
55
|
destroy() {
|
|
28
56
|
// record stat before flushing data
|
|
29
57
|
if (!isSharedClient) telemetryTracker.sessionLength();
|
|
30
58
|
|
|
31
59
|
// Stop background jobs
|
|
32
60
|
syncManager && syncManager.stop();
|
|
33
|
-
const flush = syncManager ? syncManager.flush() : Promise.resolve();
|
|
34
61
|
|
|
35
|
-
return
|
|
62
|
+
return __flush().then(() => {
|
|
36
63
|
// Cleanup event listeners
|
|
37
64
|
sdkReadinessManager.readinessManager.destroy();
|
|
38
65
|
signalListener && signalListener.stop();
|
package/src/types.ts
CHANGED
|
@@ -411,6 +411,12 @@ export interface IStatusInterface extends IEventEmitter {
|
|
|
411
411
|
* @extends IStatusInterface
|
|
412
412
|
*/
|
|
413
413
|
interface IBasicClient extends IStatusInterface {
|
|
414
|
+
/**
|
|
415
|
+
* Flush data
|
|
416
|
+
* @function flush
|
|
417
|
+
* @return {Promise<void>}
|
|
418
|
+
*/
|
|
419
|
+
flush(): Promise<void>
|
|
414
420
|
/**
|
|
415
421
|
* Destroy the client instance.
|
|
416
422
|
* @function destroy
|
package/types/types.d.ts
CHANGED
|
@@ -405,6 +405,12 @@ export interface IStatusInterface extends IEventEmitter {
|
|
|
405
405
|
* @extends IStatusInterface
|
|
406
406
|
*/
|
|
407
407
|
interface IBasicClient extends IStatusInterface {
|
|
408
|
+
/**
|
|
409
|
+
* Flush data
|
|
410
|
+
* @function flush
|
|
411
|
+
* @return {Promise<void>}
|
|
412
|
+
*/
|
|
413
|
+
flush(): Promise<void>;
|
|
408
414
|
/**
|
|
409
415
|
* Destroy the client instance.
|
|
410
416
|
* @function destroy
|