@splitsoftware/splitio-commons 1.1.0 → 1.1.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 (75) hide show
  1. package/CHANGES.txt +3 -0
  2. package/cjs/sdkClient/clientAttributesDecoration.js +108 -0
  3. package/cjs/sdkClient/clientCS.js +9 -7
  4. package/cjs/sdkClient/sdkClientMethodCS.js +2 -2
  5. package/cjs/sdkClient/sdkClientMethodCSWithTT.js +2 -2
  6. package/cjs/storages/inMemory/AttributesCacheInMemory.js +70 -0
  7. package/cjs/utils/inputValidation/attribute.js +20 -0
  8. package/cjs/utils/inputValidation/attributes.js +13 -1
  9. package/esm/sdkClient/clientAttributesDecoration.js +104 -0
  10. package/esm/sdkClient/clientCS.js +9 -7
  11. package/esm/sdkClient/sdkClientMethodCS.js +2 -2
  12. package/esm/sdkClient/sdkClientMethodCSWithTT.js +2 -2
  13. package/esm/storages/inMemory/AttributesCacheInMemory.js +67 -0
  14. package/esm/utils/inputValidation/attribute.js +16 -0
  15. package/esm/utils/inputValidation/attributes.js +11 -0
  16. package/package.json +1 -1
  17. package/src/sdkClient/clientAttributesDecoration.ts +122 -0
  18. package/src/sdkClient/clientCS.ts +12 -7
  19. package/src/sdkClient/sdkClientMethodCS.ts +2 -0
  20. package/src/sdkClient/sdkClientMethodCSWithTT.ts +2 -0
  21. package/src/storages/inMemory/AttributesCacheInMemory.ts +73 -0
  22. package/src/types.ts +39 -0
  23. package/src/utils/inputValidation/attribute.ts +21 -0
  24. package/src/utils/inputValidation/attributes.ts +14 -0
  25. package/types/logger/browser/{debugLogger.d.ts → DebugLogger.d.ts} +0 -0
  26. package/types/logger/browser/{errorLogger.d.ts → ErrorLogger.d.ts} +0 -0
  27. package/types/logger/browser/{infoLogger.d.ts → InfoLogger.d.ts} +0 -0
  28. package/types/logger/browser/{warnLogger.d.ts → WarnLogger.d.ts} +0 -0
  29. package/types/sdkClient/clientAttributesDecoration.d.ts +51 -0
  30. package/types/sdkClient/clientCS.d.ts +2 -1
  31. package/types/storages/inMemory/AttributesCacheInMemory.d.ts +43 -0
  32. package/types/types.d.ts +39 -0
  33. package/types/utils/inputValidation/attribute.d.ts +2 -0
  34. package/types/utils/inputValidation/attributes.d.ts +1 -0
  35. package/src/logger/.DS_Store +0 -0
  36. package/types/integrations/ga/GaToSplitPlugin.d.ts +0 -3
  37. package/types/integrations/ga/SplitToGaPlugin.d.ts +0 -4
  38. package/types/logger/codes.d.ts +0 -2
  39. package/types/logger/codesConstants.d.ts +0 -117
  40. package/types/logger/codesConstantsBrowser.d.ts +0 -2
  41. package/types/logger/codesConstantsNode.d.ts +0 -14
  42. package/types/logger/codesDebug.d.ts +0 -1
  43. package/types/logger/codesDebugBrowser.d.ts +0 -1
  44. package/types/logger/codesDebugNode.d.ts +0 -1
  45. package/types/logger/codesError.d.ts +0 -1
  46. package/types/logger/codesErrorNode.d.ts +0 -1
  47. package/types/logger/codesInfo.d.ts +0 -1
  48. package/types/logger/codesWarn.d.ts +0 -1
  49. package/types/logger/codesWarnNode.d.ts +0 -1
  50. package/types/logger/debugLogger.d.ts +0 -2
  51. package/types/logger/errorLogger.d.ts +0 -2
  52. package/types/logger/infoLogger.d.ts +0 -2
  53. package/types/logger/messages/debugBrowser.d.ts +0 -1
  54. package/types/logger/messages/debugNode.d.ts +0 -1
  55. package/types/logger/messages/errorNode.d.ts +0 -1
  56. package/types/logger/messages/warnNode.d.ts +0 -1
  57. package/types/logger/noopLogger.d.ts +0 -2
  58. package/types/logger/warnLogger.d.ts +0 -2
  59. package/types/sdkManager/sdkManagerMethod.d.ts +0 -6
  60. package/types/storages/getRegisteredSegments.d.ts +0 -10
  61. package/types/sync/polling/syncTasks/splitsSyncTask.copy.d.ts +0 -35
  62. package/types/sync/polling/syncTasks/splitsSyncTask.morelikeoriginal.d.ts +0 -35
  63. package/types/sync/streaming/AuthClient/indexV1.d.ts +0 -12
  64. package/types/sync/streaming/AuthClient/indexV2.d.ts +0 -8
  65. package/types/sync/streaming/pushManagerCS.d.ts +0 -12
  66. package/types/sync/streaming/pushManagerNoUsers.d.ts +0 -13
  67. package/types/sync/streaming/pushManagerSS.d.ts +0 -11
  68. package/types/sync/syncManagerFromFile.d.ts +0 -2
  69. package/types/sync/syncManagerFromObject.d.ts +0 -2
  70. package/types/sync/syncManagerOffline.d.ts +0 -9
  71. package/types/utils/lang/errors.d.ts +0 -10
  72. package/types/utils/murmur3/commons.d.ts +0 -12
  73. package/types/utils/settingsValidation/buildMetadata.d.ts +0 -3
  74. package/types/utils/settingsValidation/localhost/index.d.ts +0 -9
  75. package/types/utils/settingsValidation/logger.d.ts +0 -11
@@ -0,0 +1,122 @@
1
+ import { AttributesCacheInMemory } from '../storages/inMemory/AttributesCacheInMemory';
2
+ import { validateAttributesDeep } from '../utils/inputValidation/attributes';
3
+ import { SplitIO } from '../types';
4
+ import { ILogger } from '../logger/types';
5
+ import { objectAssign } from '../utils/lang/objectAssign';
6
+
7
+ /**
8
+ * Add in memory attributes storage methods and combine them with any attribute received from the getTreatment/s call
9
+ */
10
+ export function clientAttributesDecoration<TClient extends SplitIO.IClient | SplitIO.IAsyncClient>(log: ILogger, client: TClient) {
11
+
12
+ const attributeStorage = new AttributesCacheInMemory();
13
+
14
+ // Keep a reference to the original methods
15
+ const clientGetTreatment = client.getTreatment;
16
+ const clientGetTreatmentWithConfig = client.getTreatmentWithConfig;
17
+ const clientGetTreatments = client.getTreatments;
18
+ const clientGetTreatmentsWithConfig = client.getTreatmentsWithConfig;
19
+ const clientTrack = client.track;
20
+
21
+ function getTreatment(maybeKey: SplitIO.SplitKey, maybeSplit: string, maybeAttributes?: SplitIO.Attributes) {
22
+ return clientGetTreatment(maybeKey, maybeSplit, combineAttributes(maybeAttributes));
23
+ }
24
+
25
+ function getTreatmentWithConfig(maybeKey: SplitIO.SplitKey, maybeSplit: string, maybeAttributes?: SplitIO.Attributes) {
26
+ return clientGetTreatmentWithConfig(maybeKey, maybeSplit, combineAttributes(maybeAttributes));
27
+ }
28
+
29
+ function getTreatments(maybeKey: SplitIO.SplitKey, maybeSplits: string[], maybeAttributes?: SplitIO.Attributes) {
30
+ return clientGetTreatments(maybeKey, maybeSplits, combineAttributes(maybeAttributes));
31
+ }
32
+
33
+ function getTreatmentsWithConfig(maybeKey: SplitIO.SplitKey, maybeSplits: string[], maybeAttributes?: SplitIO.Attributes) {
34
+ return clientGetTreatmentsWithConfig(maybeKey, maybeSplits, combineAttributes(maybeAttributes));
35
+ }
36
+
37
+ function track(maybeKey: SplitIO.SplitKey, maybeTT: string, maybeEvent: string, maybeEventValue?: number, maybeProperties?: SplitIO.Properties) {
38
+ return clientTrack(maybeKey, maybeTT, maybeEvent, maybeEventValue, maybeProperties);
39
+ }
40
+
41
+ function combineAttributes(maybeAttributes: SplitIO.Attributes | undefined): SplitIO.Attributes | undefined{
42
+ const storedAttributes = attributeStorage.getAll();
43
+ if (Object.keys(storedAttributes).length > 0) {
44
+ return objectAssign({}, storedAttributes, maybeAttributes);
45
+ }
46
+ return maybeAttributes;
47
+ }
48
+
49
+ return objectAssign(client, {
50
+ getTreatment: getTreatment,
51
+ getTreatmentWithConfig: getTreatmentWithConfig,
52
+ getTreatments: getTreatments,
53
+ getTreatmentsWithConfig: getTreatmentsWithConfig,
54
+ track: track,
55
+
56
+ /**
57
+ * Add an attribute to client's in memory attributes storage
58
+ *
59
+ * @param {string} attributeName Attrinute name
60
+ * @param {string, number, boolean, list} attributeValue Attribute value
61
+ * @returns {boolean} true if the attribute was stored and false otherways
62
+ */
63
+ setAttribute(attributeName: string, attributeValue: Object) {
64
+ const attribute: Record<string, Object> = {};
65
+ attribute[attributeName] = attributeValue;
66
+ if (!validateAttributesDeep(log, attribute, 'setAttribute')) return false;
67
+ log.debug(`stored ${attributeValue} for attribute ${attributeName}`);
68
+ return attributeStorage.setAttribute(attributeName, attributeValue);
69
+ },
70
+
71
+ /**
72
+ * Returns the attribute with the given key
73
+ *
74
+ * @param {string} attributeName Attribute name
75
+ * @returns {Object} Attribute with the given key
76
+ */
77
+ getAttribute(attributeName: string) {
78
+ log.debug(`retrieved attribute ${attributeName}`);
79
+ return attributeStorage.getAttribute(attributeName + '');
80
+ },
81
+
82
+ /**
83
+ * Add to client's in memory attributes storage the attributes in 'attributes'
84
+ *
85
+ * @param {Object} attributes Object with attributes to store
86
+ * @returns true if attributes were stored an false otherways
87
+ */
88
+ setAttributes(attributes: Record<string, Object>) {
89
+ if (!validateAttributesDeep(log, attributes, 'setAttributes')) return false;
90
+ return attributeStorage.setAttributes(attributes);
91
+ },
92
+
93
+ /**
94
+ * Return all the attributes stored in client's in memory attributes storage
95
+ *
96
+ * @returns {Object} returns all the stored attributes
97
+ */
98
+ getAttributes(): Record<string, Object> {
99
+ return attributeStorage.getAll();
100
+ },
101
+
102
+ /**
103
+ * Removes from client's in memory attributes storage the attribute with the given key
104
+ *
105
+ * @param {string} attributeName
106
+ * @returns {boolean} true if attribute was removed and false otherways
107
+ */
108
+ removeAttribute(attributeName: string) {
109
+ log.debug(`removed attribute ${attributeName}`);
110
+ return attributeStorage.removeAttribute(attributeName + '');
111
+ },
112
+
113
+ /**
114
+ * Remove all the stored attributes in the client's in memory attribute storage
115
+ */
116
+ clearAttributes() {
117
+ return attributeStorage.clear();
118
+ }
119
+
120
+ });
121
+
122
+ }
@@ -1,5 +1,7 @@
1
1
  import { objectAssign } from '../utils/lang/objectAssign';
2
+ import { ILogger } from '../logger/types';
2
3
  import { SplitIO } from '../types';
4
+ import { clientAttributesDecoration } from './clientAttributesDecoration';
3
5
 
4
6
 
5
7
  /**
@@ -9,15 +11,18 @@ import { SplitIO } from '../types';
9
11
  * @param key validated split key
10
12
  * @param trafficType validated traffic type
11
13
  */
12
- export function clientCSDecorator(client: SplitIO.IClient, key: SplitIO.SplitKey, trafficType?: string): SplitIO.ICsClient {
13
- return objectAssign(client, {
14
+ export function clientCSDecorator(log: ILogger, client: SplitIO.IClient, key: SplitIO.SplitKey, trafficType?: string): SplitIO.ICsClient {
15
+
16
+ let clientCS = clientAttributesDecoration(log, client);
17
+
18
+ return objectAssign(clientCS, {
14
19
  // In the client-side API, we bind a key to the client `getTreatment*` methods
15
- getTreatment: client.getTreatment.bind(client, key),
16
- getTreatmentWithConfig: client.getTreatmentWithConfig.bind(client, key),
17
- getTreatments: client.getTreatments.bind(client, key),
18
- getTreatmentsWithConfig: client.getTreatmentsWithConfig.bind(client, key),
20
+ getTreatment: clientCS.getTreatment.bind(clientCS, key),
21
+ getTreatmentWithConfig: clientCS.getTreatmentWithConfig.bind(clientCS, key),
22
+ getTreatments: clientCS.getTreatments.bind(clientCS, key),
23
+ getTreatmentsWithConfig: clientCS.getTreatmentsWithConfig.bind(clientCS, key),
19
24
 
20
25
  // Key is bound to the `track` method. Same thing happens with trafficType but only if provided
21
- track: trafficType ? client.track.bind(client, key, trafficType) : client.track.bind(client, key)
26
+ track: trafficType ? clientCS.track.bind(clientCS, key, trafficType) : clientCS.track.bind(clientCS, key)
22
27
  }) as SplitIO.ICsClient;
23
28
  }
@@ -29,6 +29,7 @@ export function sdkClientMethodCSFactory(params: ISdkClientFactoryParams): (key?
29
29
  const validKey = validateKey(log, key, method);
30
30
 
31
31
  const mainClientInstance = clientCSDecorator(
32
+ log,
32
33
  sdkClientFactory(params) as SplitIO.IClient, // @ts-ignore
33
34
  validKey
34
35
  );
@@ -74,6 +75,7 @@ export function sdkClientMethodCSFactory(params: ISdkClientFactoryParams): (key?
74
75
  // As shared clients reuse all the storage information, we don't need to check here if we
75
76
  // will use offline or online mode. We should stick with the original decision.
76
77
  clientInstances[instanceId] = clientCSDecorator(
78
+ log,
77
79
  sdkClientFactory(objectAssign({}, params, {
78
80
  sdkReadinessManager: sharedSdkReadiness,
79
81
  storage: sharedStorage || storage,
@@ -35,6 +35,7 @@ export function sdkClientMethodCSFactory(params: ISdkClientFactoryParams): (key?
35
35
  }
36
36
 
37
37
  const mainClientInstance = clientCSDecorator(
38
+ log,
38
39
  sdkClientFactory(params) as SplitIO.IClient, // @ts-ignore
39
40
  validKey,
40
41
  validTrafficType
@@ -88,6 +89,7 @@ export function sdkClientMethodCSFactory(params: ISdkClientFactoryParams): (key?
88
89
  // As shared clients reuse all the storage information, we don't need to check here if we
89
90
  // will use offline or online mode. We should stick with the original decision.
90
91
  clientInstances[instanceId] = clientCSDecorator(
92
+ log,
91
93
  sdkClientFactory(objectAssign({}, params, {
92
94
  sdkReadinessManager: sharedSdkReadiness,
93
95
  storage: sharedStorage || storage,
@@ -0,0 +1,73 @@
1
+ import { objectAssign } from '../../utils/lang/objectAssign';
2
+
3
+ export class AttributesCacheInMemory {
4
+
5
+ private attributesCache: Record<string, Object> = {};
6
+
7
+
8
+ /**
9
+ * Create or update the value for the given attribute
10
+ *
11
+ * @param {string} attributeName attribute name
12
+ * @param {Object} attributeValue attribute value
13
+ * @returns {boolean} the attribute was stored
14
+ */
15
+ setAttribute(attributeName: string, attributeValue: Object): boolean {
16
+ this.attributesCache[attributeName] = attributeValue;
17
+ return true;
18
+ }
19
+
20
+ /**
21
+ * Retrieves the value of a given attribute
22
+ *
23
+ * @param {string} attributeName attribute name
24
+ * @returns {Object?} stored attribute value
25
+ */
26
+ getAttribute(attributeName: string): Object {
27
+ return this.attributesCache[attributeName];
28
+ }
29
+
30
+ /**
31
+ * Create or update all the given attributes
32
+ *
33
+ * @param {[string, Object]} attributes attributes to create or update
34
+ * @returns {boolean} attributes were stored
35
+ */
36
+ setAttributes(attributes: Record<string, Object>): boolean {
37
+ this.attributesCache = objectAssign(this.attributesCache, attributes);
38
+ return true;
39
+ }
40
+
41
+ /**
42
+ * Retrieve the full attributes map
43
+ *
44
+ * @returns {Map<string, Object>} stored attributes
45
+ */
46
+ getAll(): Record<string, Object> {
47
+ return this.attributesCache;
48
+ }
49
+
50
+ /**
51
+ * Removes a given attribute from the map
52
+ *
53
+ * @param {string} attributeName attribute to remove
54
+ * @returns {boolean} attribute removed
55
+ */
56
+ removeAttribute(attributeName: string): boolean {
57
+ if (Object.keys(this.attributesCache).indexOf(attributeName) >= 0) {
58
+ delete this.attributesCache[attributeName];
59
+ return true;
60
+ }
61
+ return false;
62
+ }
63
+
64
+ /**
65
+ * Clears all attributes stored in the SDK
66
+ *
67
+ */
68
+ clear() {
69
+ this.attributesCache = {};
70
+ return true;
71
+ }
72
+
73
+ }
package/src/types.ts CHANGED
@@ -1108,6 +1108,45 @@ export namespace SplitIO {
1108
1108
  * @returns {boolean} Whether the event was added to the queue succesfully or not.
1109
1109
  */
1110
1110
  track(...args: [trafficType: string, eventType: string, value?: number, properties?: Properties] | [eventType: string, value?: number, properties?: Properties]): boolean,
1111
+ /**
1112
+ * Add an attribute to client's in memory attributes storage
1113
+ * @function setAttribute
1114
+ * @param {string} attributeName Attrinute name
1115
+ * @param {string, number, boolean, list} attributeValue Attribute value
1116
+ * @returns {boolean} true if the attribute was stored and false otherways
1117
+ */
1118
+ setAttribute(attributeName: string, attributeValue: Object): boolean,
1119
+ /**
1120
+ * Returns the attribute with the given key
1121
+ * @function getAttribute
1122
+ * @param {string} attributeName Attribute name
1123
+ * @returns {Object} Attribute with the given key
1124
+ */
1125
+ getAttribute(attributeName: string): Object,
1126
+ /**
1127
+ * Add to client's in memory attributes storage the attributes in 'attributes'
1128
+ * @function setAttributes
1129
+ * @param {Object} attributes Object with attributes to store
1130
+ * @returns true if attributes were stored an false otherways
1131
+ */
1132
+ setAttributes(attributes: Record<string, Object>): boolean,
1133
+ /**
1134
+ * Return all the attributes stored in client's in memory attributes storage
1135
+ * @function getAttributes
1136
+ * @returns {Object} returns all the stored attributes
1137
+ */
1138
+ getAttributes(): Record<string, Object>,
1139
+ /**
1140
+ * Removes from client's in memory attributes storage the attribute with the given key
1141
+ * @function removeAttribute
1142
+ * @param {string} attributeName
1143
+ * @returns {boolean} true if attribute was removed and false otherways
1144
+ */
1145
+ removeAttribute(attributeName: string): boolean,
1146
+ /**
1147
+ * Remove all the stored attributes in the client's in memory attribute storage
1148
+ */
1149
+ clearAttributes(): boolean
1111
1150
  }
1112
1151
  /**
1113
1152
  * Representation of a manager instance with synchronous storage of the SDK.
@@ -0,0 +1,21 @@
1
+ import { isString, isFiniteNumber, isBoolean } from '../../utils/lang';
2
+ import { ILogger } from '../../logger/types';
3
+
4
+ export function validateAttribute(log: ILogger, attributeKey: string, attributeValue: Object, method: string): boolean {
5
+ if (!isString(attributeKey) || attributeKey.length === 0) {
6
+ log.warn(`${method}: you passed an invalid attribute name, attribute name must be a non-empty string.`);
7
+ return false;
8
+ }
9
+
10
+ const isStringVal = isString(attributeValue);
11
+ const isFiniteVal = isFiniteNumber(attributeValue);
12
+ const isBoolVal = isBoolean(attributeValue);
13
+ const isArrayVal = Array.isArray(attributeValue);
14
+
15
+ if (!(isStringVal || isFiniteVal || isBoolVal || isArrayVal)) { // If it's not of valid type.
16
+ log.warn(`${method}: you passed an invalid attribute value for ${attributeKey}. Acceptable types are: string, number, boolean and array of strings.`);
17
+ return false;
18
+ }
19
+
20
+ return true;
21
+ }
@@ -1,6 +1,7 @@
1
1
  import { isObject } from '../lang';
2
2
  import { SplitIO } from '../../types';
3
3
  import { ILogger } from '../../logger/types';
4
+ import { validateAttribute } from './attribute';
4
5
  import { ERROR_NOT_PLAIN_OBJECT } from '../../logger/constants';
5
6
 
6
7
  export function validateAttributes(log: ILogger, maybeAttrs: any, method: string): SplitIO.Attributes | undefined | false {
@@ -11,3 +12,16 @@ export function validateAttributes(log: ILogger, maybeAttrs: any, method: string
11
12
  log.error(ERROR_NOT_PLAIN_OBJECT, [method, 'attributes']);
12
13
  return false;
13
14
  }
15
+
16
+ export function validateAttributesDeep(log: ILogger, maybeAttributes: Record<string, Object>, method: string): boolean {
17
+ if (!validateAttributes(log, maybeAttributes, method)) return false;
18
+
19
+ let result = true;
20
+ Object.keys(maybeAttributes).forEach(attributeKey => {
21
+ if (!validateAttribute(log, attributeKey, maybeAttributes[attributeKey], method))
22
+ result = false;
23
+ });
24
+
25
+ return result;
26
+
27
+ }
@@ -0,0 +1,51 @@
1
+ import { SplitIO } from '../types';
2
+ import { ILogger } from '../logger/types';
3
+ /**
4
+ * Add in memory attributes storage methods and combine them with any attribute received from the getTreatment/s call
5
+ */
6
+ export declare function clientAttributesDecoration<TClient extends SplitIO.IClient | SplitIO.IAsyncClient>(log: ILogger, client: TClient): TClient & {
7
+ getTreatment: (maybeKey: SplitIO.SplitKey, maybeSplit: string, maybeAttributes?: SplitIO.Attributes | undefined) => string | SplitIO.AsyncTreatment;
8
+ getTreatmentWithConfig: (maybeKey: SplitIO.SplitKey, maybeSplit: string, maybeAttributes?: SplitIO.Attributes | undefined) => SplitIO.TreatmentWithConfig | SplitIO.AsyncTreatmentWithConfig;
9
+ getTreatments: (maybeKey: SplitIO.SplitKey, maybeSplits: string[], maybeAttributes?: SplitIO.Attributes | undefined) => SplitIO.Treatments | SplitIO.AsyncTreatments;
10
+ getTreatmentsWithConfig: (maybeKey: SplitIO.SplitKey, maybeSplits: string[], maybeAttributes?: SplitIO.Attributes | undefined) => SplitIO.TreatmentsWithConfig | SplitIO.AsyncTreatmentsWithConfig;
11
+ track: (maybeKey: SplitIO.SplitKey, maybeTT: string, maybeEvent: string, maybeEventValue?: number | undefined, maybeProperties?: SplitIO.Properties | undefined) => import("../dtos/types").MaybeThenable<boolean>;
12
+ /**
13
+ * Add an attribute to client's in memory attributes storage
14
+ *
15
+ * @param {string} attributeName Attrinute name
16
+ * @param {string, number, boolean, list} attributeValue Attribute value
17
+ * @returns {boolean} true if the attribute was stored and false otherways
18
+ */
19
+ setAttribute(attributeName: string, attributeValue: Object): boolean;
20
+ /**
21
+ * Returns the attribute with the given key
22
+ *
23
+ * @param {string} attributeName Attribute name
24
+ * @returns {Object} Attribute with the given key
25
+ */
26
+ getAttribute(attributeName: string): Object;
27
+ /**
28
+ * Add to client's in memory attributes storage the attributes in 'attributes'
29
+ *
30
+ * @param {Object} attributes Object with attributes to store
31
+ * @returns true if attributes were stored an false otherways
32
+ */
33
+ setAttributes(attributes: Record<string, Object>): boolean;
34
+ /**
35
+ * Return all the attributes stored in client's in memory attributes storage
36
+ *
37
+ * @returns {Object} returns all the stored attributes
38
+ */
39
+ getAttributes(): Record<string, Object>;
40
+ /**
41
+ * Removes from client's in memory attributes storage the attribute with the given key
42
+ *
43
+ * @param {string} attributeName
44
+ * @returns {boolean} true if attribute was removed and false otherways
45
+ */
46
+ removeAttribute(attributeName: string): boolean;
47
+ /**
48
+ * Remove all the stored attributes in the client's in memory attribute storage
49
+ */
50
+ clearAttributes(): boolean;
51
+ };
@@ -1,3 +1,4 @@
1
+ import { ILogger } from '../logger/types';
1
2
  import { SplitIO } from '../types';
2
3
  /**
3
4
  * Decorator that binds a key and (optionally) a traffic type to client methods
@@ -6,4 +7,4 @@ import { SplitIO } from '../types';
6
7
  * @param key validated split key
7
8
  * @param trafficType validated traffic type
8
9
  */
9
- export declare function clientCSDecorator(client: SplitIO.IClient, key: SplitIO.SplitKey, trafficType?: string): SplitIO.ICsClient;
10
+ export declare function clientCSDecorator(log: ILogger, client: SplitIO.IClient, key: SplitIO.SplitKey, trafficType?: string): SplitIO.ICsClient;
@@ -0,0 +1,43 @@
1
+ export declare class AttributesCacheInMemory {
2
+ private attributesCache;
3
+ /**
4
+ * Create or update the value for the given attribute
5
+ *
6
+ * @param {string} attributeName attribute name
7
+ * @param {Object} attributeValue attribute value
8
+ * @returns {boolean} the attribute was stored
9
+ */
10
+ setAttribute(attributeName: string, attributeValue: Object): boolean;
11
+ /**
12
+ * Retrieves the value of a given attribute
13
+ *
14
+ * @param {string} attributeName attribute name
15
+ * @returns {Object?} stored attribute value
16
+ */
17
+ getAttribute(attributeName: string): Object;
18
+ /**
19
+ * Create or update all the given attributes
20
+ *
21
+ * @param {[string, Object]} attributes attributes to create or update
22
+ * @returns {boolean} attributes were stored
23
+ */
24
+ setAttributes(attributes: Record<string, Object>): boolean;
25
+ /**
26
+ * Retrieve the full attributes map
27
+ *
28
+ * @returns {Map<string, Object>} stored attributes
29
+ */
30
+ getAll(): Record<string, Object>;
31
+ /**
32
+ * Removes a given attribute from the map
33
+ *
34
+ * @param {string} attributeName attribute to remove
35
+ * @returns {boolean} attribute removed
36
+ */
37
+ removeAttribute(attributeName: string): boolean;
38
+ /**
39
+ * Clears all attributes stored in the SDK
40
+ *
41
+ */
42
+ clear(): boolean;
43
+ }
package/types/types.d.ts CHANGED
@@ -1108,6 +1108,45 @@ export declare namespace SplitIO {
1108
1108
  * @returns {boolean} Whether the event was added to the queue succesfully or not.
1109
1109
  */
1110
1110
  track(...args: [trafficType: string, eventType: string, value?: number, properties?: Properties] | [eventType: string, value?: number, properties?: Properties]): boolean;
1111
+ /**
1112
+ * Add an attribute to client's in memory attributes storage
1113
+ * @function setAttribute
1114
+ * @param {string} attributeName Attrinute name
1115
+ * @param {string, number, boolean, list} attributeValue Attribute value
1116
+ * @returns {boolean} true if the attribute was stored and false otherways
1117
+ */
1118
+ setAttribute(attributeName: string, attributeValue: Object): boolean;
1119
+ /**
1120
+ * Returns the attribute with the given key
1121
+ * @function getAttribute
1122
+ * @param {string} attributeName Attribute name
1123
+ * @returns {Object} Attribute with the given key
1124
+ */
1125
+ getAttribute(attributeName: string): Object;
1126
+ /**
1127
+ * Add to client's in memory attributes storage the attributes in 'attributes'
1128
+ * @function setAttributes
1129
+ * @param {Object} attributes Object with attributes to store
1130
+ * @returns true if attributes were stored an false otherways
1131
+ */
1132
+ setAttributes(attributes: Record<string, Object>): boolean;
1133
+ /**
1134
+ * Return all the attributes stored in client's in memory attributes storage
1135
+ * @function getAttributes
1136
+ * @returns {Object} returns all the stored attributes
1137
+ */
1138
+ getAttributes(): Record<string, Object>;
1139
+ /**
1140
+ * Removes from client's in memory attributes storage the attribute with the given key
1141
+ * @function removeAttribute
1142
+ * @param {string} attributeName
1143
+ * @returns {boolean} true if attribute was removed and false otherways
1144
+ */
1145
+ removeAttribute(attributeName: string): boolean;
1146
+ /**
1147
+ * Remove all the stored attributes in the client's in memory attribute storage
1148
+ */
1149
+ clearAttributes(): boolean;
1111
1150
  }
1112
1151
  /**
1113
1152
  * Representation of a manager instance with synchronous storage of the SDK.
@@ -0,0 +1,2 @@
1
+ import { ILogger } from '../../logger/types';
2
+ export declare function validateAttribute(log: ILogger, attributeKey: string, attributeValue: Object, method: string): boolean;
@@ -1,3 +1,4 @@
1
1
  import { SplitIO } from '../../types';
2
2
  import { ILogger } from '../../logger/types';
3
3
  export declare function validateAttributes(log: ILogger, maybeAttrs: any, method: string): SplitIO.Attributes | undefined | false;
4
+ export declare function validateAttributesDeep(log: ILogger, maybeAttributes: Record<string, Object>, method: string): boolean;
Binary file
@@ -1,3 +0,0 @@
1
- import { IIntegrationFactoryParams } from '../types';
2
- import { GoogleAnalyticsToSplitOptions } from './types';
3
- export declare function GoogleAnalyticsToSplit(options: GoogleAnalyticsToSplitOptions): (params: IIntegrationFactoryParams) => void;
@@ -1,4 +0,0 @@
1
- import { IIntegrationFactoryParams } from '../types';
2
- import SplitToGa from './SplitToGa';
3
- import { SplitToGoogleAnalyticsOptions } from './types';
4
- export declare function SplitToGoogleAnalytics(options?: SplitToGoogleAnalyticsOptions): (params: IIntegrationFactoryParams) => SplitToGa;
@@ -1,2 +0,0 @@
1
- import { ICodes } from './types';
2
- export declare const codes: ICodes;
@@ -1,117 +0,0 @@
1
- export declare const DEBUG_0 = 0;
2
- export declare const DEBUG_1 = 1;
3
- export declare const DEBUG_2 = 2;
4
- export declare const DEBUG_3 = 3;
5
- export declare const DEBUG_4 = 4;
6
- export declare const DEBUG_5 = 5;
7
- export declare const DEBUG_6 = 6;
8
- export declare const DEBUG_7 = 7;
9
- export declare const DEBUG_8 = 8;
10
- export declare const DEBUG_9 = 9;
11
- export declare const DEBUG_10 = 10;
12
- export declare const DEBUG_11 = 11;
13
- export declare const DEBUG_12 = 12;
14
- export declare const DEBUG_13 = 13;
15
- export declare const DEBUG_14 = 14;
16
- export declare const DEBUG_15 = 15;
17
- export declare const DEBUG_16 = 16;
18
- export declare const DEBUG_17 = 17;
19
- export declare const DEBUG_18 = 18;
20
- export declare const DEBUG_19 = 19;
21
- export declare const DEBUG_20 = 20;
22
- export declare const DEBUG_21 = 21;
23
- export declare const DEBUG_22 = 22;
24
- export declare const DEBUG_23 = 23;
25
- export declare const DEBUG_24 = 24;
26
- export declare const DEBUG_25 = 25;
27
- export declare const DEBUG_31 = 31;
28
- export declare const DEBUG_32 = 32;
29
- export declare const DEBUG_33 = 33;
30
- export declare const DEBUG_36 = 36;
31
- export declare const DEBUG_42 = 42;
32
- export declare const DEBUG_43 = 43;
33
- export declare const DEBUG_44 = 44;
34
- export declare const DEBUG_45 = 45;
35
- export declare const DEBUG_46 = 46;
36
- export declare const DEBUG_47 = 47;
37
- export declare const DEBUG_48 = 48;
38
- export declare const DEBUG_49 = 49;
39
- export declare const DEBUG_50 = 50;
40
- export declare const DEBUG_51 = 51;
41
- export declare const INFO_0 = 100;
42
- export declare const INFO_1 = 101;
43
- export declare const INFO_2 = 102;
44
- export declare const INFO_3 = 103;
45
- export declare const INFO_4 = 104;
46
- export declare const INFO_5 = 105;
47
- export declare const INFO_6 = 106;
48
- export declare const INFO_7 = 107;
49
- export declare const INFO_8 = 108;
50
- export declare const INFO_9 = 109;
51
- export declare const INFO_10 = 110;
52
- export declare const INFO_11 = 111;
53
- export declare const INFO_12 = 112;
54
- export declare const INFO_13 = 113;
55
- export declare const INFO_14 = 114;
56
- export declare const INFO_15 = 115;
57
- export declare const INFO_16 = 116;
58
- export declare const INFO_17 = 117;
59
- export declare const INFO_18 = 118;
60
- export declare const INFO_19 = 119;
61
- export declare const INFO_20 = 120;
62
- export declare const INFO_21 = 121;
63
- export declare const WARN_0 = 200;
64
- export declare const WARN_1 = 201;
65
- export declare const WARN_2 = 202;
66
- export declare const WARN_4 = 204;
67
- export declare const WARN_5 = 205;
68
- export declare const WARN_6 = 206;
69
- export declare const WARN_7 = 207;
70
- export declare const WARN_8 = 208;
71
- export declare const WARN_9 = 209;
72
- export declare const WARN_10 = 210;
73
- export declare const WARN_11 = 211;
74
- export declare const WARN_12 = 212;
75
- export declare const WARN_13 = 213;
76
- export declare const WARN_14 = 214;
77
- export declare const WARN_15 = 215;
78
- export declare const WARN_17 = 217;
79
- export declare const WARN_18 = 218;
80
- export declare const WARN_19 = 219;
81
- export declare const WARN_20 = 220;
82
- export declare const WARN_21 = 221;
83
- export declare const WARN_22 = 222;
84
- export declare const WARN_23 = 223;
85
- export declare const WARN_24 = 224;
86
- export declare const WARN_25 = 225;
87
- export declare const ERROR_0 = 300;
88
- export declare const ERROR_2 = 302;
89
- export declare const ERROR_3 = 303;
90
- export declare const ERROR_4 = 304;
91
- export declare const ERROR_5 = 305;
92
- export declare const ERROR_7 = 307;
93
- export declare const ERROR_9 = 309;
94
- export declare const ERROR_10 = 310;
95
- export declare const ERROR_11 = 311;
96
- export declare const ERROR_12 = 312;
97
- export declare const ERROR_13 = 313;
98
- export declare const ERROR_14 = 314;
99
- export declare const ERROR_15 = 315;
100
- export declare const ERROR_16 = 316;
101
- export declare const ERROR_17 = 317;
102
- export declare const ERROR_18 = 318;
103
- export declare const ERROR_19 = 319;
104
- export declare const ERROR_20 = 320;
105
- export declare const ERROR_21 = 321;
106
- export declare const ERROR_22 = 322;
107
- export declare const ERROR_23 = 323;
108
- export declare const ERROR_24 = 324;
109
- export declare const ERROR_25 = 325;
110
- export declare const ERROR_26 = 326;
111
- export declare const ERROR_32 = 332;
112
- export declare const ERROR_33 = 333;
113
- export declare const ERROR_34 = 334;
114
- export declare const ERROR_35 = 335;
115
- export declare const ERROR_36 = 336;
116
- export declare const ERROR_37 = 337;
117
- export declare const ERROR_38 = 338;
@@ -1,2 +0,0 @@
1
- export declare const DEBUG_26 = 26;
2
- export declare const DEBUG_27 = 27;