@kameleoon/javascript-sdk-core 0.0.3 → 1.0.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 (261) hide show
  1. package/README.md +7 -3
  2. package/dist/campaignConfiguration/campaignConfiguration.d.ts +46 -0
  3. package/dist/campaignConfiguration/campaignConfiguration.js +217 -0
  4. package/dist/campaignConfiguration/campaignConfiguration.js.map +1 -0
  5. package/dist/campaignConfiguration/constants.d.ts +18 -0
  6. package/dist/campaignConfiguration/constants.js +23 -0
  7. package/dist/campaignConfiguration/constants.js.map +1 -0
  8. package/dist/campaignConfiguration/index.d.ts +2 -0
  9. package/dist/campaignConfiguration/index.js +8 -0
  10. package/dist/campaignConfiguration/index.js.map +1 -0
  11. package/dist/campaignConfiguration/types.d.ts +126 -0
  12. package/dist/campaignConfiguration/types.js +47 -0
  13. package/dist/campaignConfiguration/types.js.map +1 -0
  14. package/dist/clientSettings/clientSettings.d.ts +12 -0
  15. package/dist/clientSettings/clientSettings.js +29 -0
  16. package/dist/clientSettings/clientSettings.js.map +1 -0
  17. package/dist/clientSettings/index.d.ts +2 -0
  18. package/dist/clientSettings/index.js +6 -0
  19. package/dist/clientSettings/index.js.map +1 -0
  20. package/dist/clientSettings/types.d.ts +6 -0
  21. package/dist/{interfaces/interfaces.js → clientSettings/types.js} +1 -1
  22. package/dist/clientSettings/types.js.map +1 -0
  23. package/dist/constants.d.ts +10 -16
  24. package/dist/constants.js +13 -20
  25. package/dist/constants.js.map +1 -1
  26. package/dist/eventSource/constants.d.ts +1 -0
  27. package/dist/eventSource/constants.js +5 -0
  28. package/dist/eventSource/constants.js.map +1 -0
  29. package/dist/eventSource/externalEventSource.d.ts +12 -0
  30. package/dist/eventSource/externalEventSource.js +26 -0
  31. package/dist/eventSource/externalEventSource.js.map +1 -0
  32. package/dist/eventSource/index.d.ts +3 -0
  33. package/dist/eventSource/index.js +8 -0
  34. package/dist/eventSource/index.js.map +1 -0
  35. package/dist/eventSource/types.d.ts +47 -0
  36. package/dist/eventSource/types.js +3 -0
  37. package/dist/eventSource/types.js.map +1 -0
  38. package/dist/hasher/constants.d.ts +1 -0
  39. package/dist/hasher/constants.js +5 -0
  40. package/dist/hasher/constants.js.map +1 -0
  41. package/dist/hasher/hasher.d.ts +6 -0
  42. package/dist/hasher/hasher.js +34 -0
  43. package/dist/hasher/hasher.js.map +1 -0
  44. package/dist/hasher/index.d.ts +1 -0
  45. package/dist/hasher/index.js +6 -0
  46. package/dist/hasher/index.js.map +1 -0
  47. package/dist/hasher/types.d.ts +12 -0
  48. package/dist/hasher/types.js +3 -0
  49. package/dist/hasher/types.js.map +1 -0
  50. package/dist/index.d.ts +10 -3
  51. package/dist/index.js +25 -7
  52. package/dist/index.js.map +1 -1
  53. package/dist/kameleoonClient.d.ts +189 -100
  54. package/dist/kameleoonClient.js +238 -701
  55. package/dist/kameleoonClient.js.map +1 -1
  56. package/dist/kameleoonData/browser.d.ts +21 -0
  57. package/dist/kameleoonData/browser.js +41 -0
  58. package/dist/kameleoonData/browser.js.map +1 -0
  59. package/dist/kameleoonData/constants.d.ts +1 -0
  60. package/dist/kameleoonData/constants.js +5 -0
  61. package/dist/kameleoonData/constants.js.map +1 -0
  62. package/dist/kameleoonData/conversion.d.ts +23 -0
  63. package/dist/kameleoonData/conversion.js +49 -0
  64. package/dist/kameleoonData/conversion.js.map +1 -0
  65. package/dist/kameleoonData/customData.d.ts +33 -0
  66. package/dist/kameleoonData/customData.js +68 -0
  67. package/dist/kameleoonData/customData.js.map +1 -0
  68. package/dist/kameleoonData/device.d.ts +21 -0
  69. package/dist/kameleoonData/device.js +41 -0
  70. package/dist/kameleoonData/device.js.map +1 -0
  71. package/dist/kameleoonData/index.d.ts +7 -0
  72. package/dist/kameleoonData/index.js +20 -0
  73. package/dist/kameleoonData/index.js.map +1 -0
  74. package/dist/kameleoonData/nonce.d.ts +5 -0
  75. package/dist/kameleoonData/nonce.js +20 -0
  76. package/dist/kameleoonData/nonce.js.map +1 -0
  77. package/dist/kameleoonData/pageView.d.ts +24 -0
  78. package/dist/kameleoonData/pageView.js +54 -0
  79. package/dist/kameleoonData/pageView.js.map +1 -0
  80. package/dist/kameleoonData/types.d.ts +100 -0
  81. package/dist/kameleoonData/types.js +36 -0
  82. package/dist/kameleoonData/types.js.map +1 -0
  83. package/dist/kameleoonData/userAgent.d.ts +18 -0
  84. package/dist/kameleoonData/userAgent.js +33 -0
  85. package/dist/kameleoonData/userAgent.js.map +1 -0
  86. package/dist/kameleoonError/constants.d.ts +22 -0
  87. package/dist/kameleoonError/constants.js +25 -0
  88. package/dist/kameleoonError/constants.js.map +1 -0
  89. package/dist/kameleoonError/helpers.d.ts +1 -0
  90. package/dist/kameleoonError/helpers.js +8 -0
  91. package/dist/kameleoonError/helpers.js.map +1 -0
  92. package/dist/kameleoonError/index.d.ts +3 -0
  93. package/dist/kameleoonError/index.js +10 -0
  94. package/dist/kameleoonError/index.js.map +1 -0
  95. package/dist/kameleoonError/kameleoonError.d.ts +24 -0
  96. package/dist/kameleoonError/kameleoonError.js +64 -0
  97. package/dist/kameleoonError/kameleoonError.js.map +1 -0
  98. package/dist/kameleoonError/types.d.ts +20 -0
  99. package/dist/kameleoonError/types.js +25 -0
  100. package/dist/kameleoonError/types.js.map +1 -0
  101. package/dist/kameleoonUtils.d.ts +11 -10
  102. package/dist/kameleoonUtils.js +42 -128
  103. package/dist/kameleoonUtils.js.map +1 -1
  104. package/dist/requester/constants.d.ts +15 -0
  105. package/dist/requester/constants.js +53 -0
  106. package/dist/requester/constants.js.map +1 -0
  107. package/dist/requester/index.d.ts +3 -0
  108. package/dist/requester/index.js +10 -0
  109. package/dist/requester/index.js.map +1 -0
  110. package/dist/requester/requester.d.ts +23 -0
  111. package/dist/requester/requester.js +121 -0
  112. package/dist/requester/requester.js.map +1 -0
  113. package/dist/requester/types.d.ts +43 -0
  114. package/dist/requester/types.js +39 -0
  115. package/dist/requester/types.js.map +1 -0
  116. package/dist/storage/constants.d.ts +9 -0
  117. package/dist/storage/constants.js +14 -0
  118. package/dist/storage/constants.js.map +1 -0
  119. package/dist/storage/externalStorage.d.ts +11 -0
  120. package/dist/storage/externalStorage.js +34 -0
  121. package/dist/storage/externalStorage.js.map +1 -0
  122. package/dist/storage/index.d.ts +3 -0
  123. package/dist/storage/index.js +8 -0
  124. package/dist/storage/index.js.map +1 -0
  125. package/dist/storage/types.d.ts +52 -11
  126. package/dist/targeting/conditions/conditionFactory.d.ts +6 -0
  127. package/dist/targeting/conditions/conditionFactory.js +26 -0
  128. package/dist/targeting/conditions/conditionFactory.js.map +1 -0
  129. package/dist/targeting/conditions/customDataCondition.d.ts +16 -0
  130. package/dist/targeting/conditions/customDataCondition.js +99 -0
  131. package/dist/targeting/conditions/customDataCondition.js.map +1 -0
  132. package/dist/targeting/conditions/exclusiveExperimentCondition.d.ts +9 -0
  133. package/dist/targeting/conditions/exclusiveExperimentCondition.js +21 -0
  134. package/dist/targeting/conditions/exclusiveExperimentCondition.js.map +1 -0
  135. package/dist/targeting/conditions/index.d.ts +5 -0
  136. package/dist/targeting/conditions/index.js +12 -0
  137. package/dist/targeting/conditions/index.js.map +1 -0
  138. package/dist/targeting/conditions/targetExperimentCondition.d.ts +13 -0
  139. package/dist/targeting/conditions/targetExperimentCondition.js +42 -0
  140. package/dist/targeting/conditions/targetExperimentCondition.js.map +1 -0
  141. package/dist/targeting/conditions/types.d.ts +22 -11
  142. package/dist/targeting/index.d.ts +3 -0
  143. package/dist/targeting/index.js +15 -0
  144. package/dist/targeting/index.js.map +1 -0
  145. package/dist/targeting/targetingNode.d.ts +21 -0
  146. package/dist/targeting/targetingNode.js +40 -0
  147. package/dist/targeting/targetingNode.js.map +1 -0
  148. package/dist/targeting/targetingTree.d.ts +16 -8
  149. package/dist/targeting/targetingTree.js +112 -10
  150. package/dist/targeting/targetingTree.js.map +1 -1
  151. package/dist/targeting/types.d.ts +127 -0
  152. package/dist/targeting/types.js +93 -0
  153. package/dist/targeting/types.js.map +1 -0
  154. package/dist/types.d.ts +135 -5
  155. package/dist/types.js +28 -0
  156. package/dist/types.js.map +1 -1
  157. package/dist/utilities/constants.d.ts +1 -0
  158. package/dist/utilities/constants.js +5 -0
  159. package/dist/utilities/constants.js.map +1 -0
  160. package/dist/utilities/index.d.ts +1 -0
  161. package/dist/utilities/index.js +6 -0
  162. package/dist/utilities/index.js.map +1 -0
  163. package/dist/utilities/types.d.ts +18 -0
  164. package/dist/utilities/types.js +3 -0
  165. package/dist/utilities/types.js.map +1 -0
  166. package/dist/utilities/utilities.d.ts +13 -0
  167. package/dist/utilities/utilities.js +119 -0
  168. package/dist/utilities/utilities.js.map +1 -0
  169. package/dist/variationConfiguration/index.d.ts +2 -0
  170. package/dist/variationConfiguration/index.js +6 -0
  171. package/dist/variationConfiguration/index.js.map +1 -0
  172. package/dist/variationConfiguration/types.d.ts +25 -0
  173. package/dist/variationConfiguration/types.js +3 -0
  174. package/dist/variationConfiguration/types.js.map +1 -0
  175. package/dist/variationConfiguration/variation.d.ts +13 -0
  176. package/dist/variationConfiguration/variation.js +38 -0
  177. package/dist/variationConfiguration/variation.js.map +1 -0
  178. package/dist/variationConfiguration/variationConfiguration.d.ts +36 -0
  179. package/dist/variationConfiguration/variationConfiguration.js +248 -0
  180. package/dist/variationConfiguration/variationConfiguration.js.map +1 -0
  181. package/package.json +19 -9
  182. package/dist/configurations/configuration.d.ts +0 -15
  183. package/dist/configurations/configuration.js +0 -31
  184. package/dist/configurations/configuration.js.map +0 -1
  185. package/dist/configurations/experiment.d.ts +0 -13
  186. package/dist/configurations/experiment.js +0 -54
  187. package/dist/configurations/experiment.js.map +0 -1
  188. package/dist/configurations/featureFlag.d.ts +0 -23
  189. package/dist/configurations/featureFlag.js +0 -105
  190. package/dist/configurations/featureFlag.js.map +0 -1
  191. package/dist/configurations/variation.d.ts +0 -15
  192. package/dist/configurations/variation.js +0 -14
  193. package/dist/configurations/variation.js.map +0 -1
  194. package/dist/data.d.ts +0 -67
  195. package/dist/data.js +0 -127
  196. package/dist/data.js.map +0 -1
  197. package/dist/exceptions/credentialsNotFound.d.ts +0 -6
  198. package/dist/exceptions/credentialsNotFound.js +0 -29
  199. package/dist/exceptions/credentialsNotFound.js.map +0 -1
  200. package/dist/exceptions/experimentConfigurationNotFound.d.ts +0 -6
  201. package/dist/exceptions/experimentConfigurationNotFound.js +0 -29
  202. package/dist/exceptions/experimentConfigurationNotFound.js.map +0 -1
  203. package/dist/exceptions/featureConfigurationNotFound.d.ts +0 -6
  204. package/dist/exceptions/featureConfigurationNotFound.js +0 -29
  205. package/dist/exceptions/featureConfigurationNotFound.js.map +0 -1
  206. package/dist/exceptions/notActivated.d.ts +0 -6
  207. package/dist/exceptions/notActivated.js +0 -29
  208. package/dist/exceptions/notActivated.js.map +0 -1
  209. package/dist/exceptions/notTargeted.d.ts +0 -6
  210. package/dist/exceptions/notTargeted.js +0 -29
  211. package/dist/exceptions/notTargeted.js.map +0 -1
  212. package/dist/exceptions/siteCodeDisabled.d.ts +0 -5
  213. package/dist/exceptions/siteCodeDisabled.js +0 -30
  214. package/dist/exceptions/siteCodeDisabled.js.map +0 -1
  215. package/dist/exceptions/variationConfigurationNotFound.d.ts +0 -6
  216. package/dist/exceptions/variationConfigurationNotFound.js +0 -29
  217. package/dist/exceptions/variationConfigurationNotFound.js.map +0 -1
  218. package/dist/exceptions/visitorCodeNotValid.d.ts +0 -5
  219. package/dist/exceptions/visitorCodeNotValid.js +0 -30
  220. package/dist/exceptions/visitorCodeNotValid.js.map +0 -1
  221. package/dist/interfaces/interfaces.d.ts +0 -81
  222. package/dist/interfaces/interfaces.js.map +0 -1
  223. package/dist/nonce.d.ts +0 -1
  224. package/dist/nonce.js +0 -16
  225. package/dist/nonce.js.map +0 -1
  226. package/dist/realTimeConfigurationService.d.ts +0 -12
  227. package/dist/realTimeConfigurationService.js +0 -24
  228. package/dist/realTimeConfigurationService.js.map +0 -1
  229. package/dist/storage/variationStorage.d.ts +0 -11
  230. package/dist/storage/variationStorage.js +0 -159
  231. package/dist/storage/variationStorage.js.map +0 -1
  232. package/dist/storage/visitorVariation.d.ts +0 -9
  233. package/dist/storage/visitorVariation.js +0 -22
  234. package/dist/storage/visitorVariation.js.map +0 -1
  235. package/dist/targeting/conditions/customDatum.d.ts +0 -12
  236. package/dist/targeting/conditions/customDatum.js +0 -129
  237. package/dist/targeting/conditions/customDatum.js.map +0 -1
  238. package/dist/targeting/conditions/exclusiveExperiment.d.ts +0 -9
  239. package/dist/targeting/conditions/exclusiveExperiment.js +0 -45
  240. package/dist/targeting/conditions/exclusiveExperiment.js.map +0 -1
  241. package/dist/targeting/conditions/targetExperiment.d.ts +0 -14
  242. package/dist/targeting/conditions/targetExperiment.js +0 -57
  243. package/dist/targeting/conditions/targetExperiment.js.map +0 -1
  244. package/dist/targeting/targetingCondition.d.ts +0 -7
  245. package/dist/targeting/targetingCondition.js +0 -9
  246. package/dist/targeting/targetingCondition.js.map +0 -1
  247. package/dist/targeting/targetingConditionsFactory.d.ts +0 -7
  248. package/dist/targeting/targetingConditionsFactory.js +0 -30
  249. package/dist/targeting/targetingConditionsFactory.js.map +0 -1
  250. package/dist/targeting/targetingData.d.ts +0 -7
  251. package/dist/targeting/targetingData.js +0 -11
  252. package/dist/targeting/targetingData.js.map +0 -1
  253. package/dist/targeting/targetingEngine.d.ts +0 -6
  254. package/dist/targeting/targetingEngine.js +0 -130
  255. package/dist/targeting/targetingEngine.js.map +0 -1
  256. package/dist/targeting/targetingSegment.d.ts +0 -5
  257. package/dist/targeting/targetingSegment.js +0 -9
  258. package/dist/targeting/targetingSegment.js.map +0 -1
  259. package/dist/targeting/targetingTreeBuilder.d.ts +0 -8
  260. package/dist/targeting/targetingTreeBuilder.js +0 -127
  261. package/dist/targeting/targetingTreeBuilder.js.map +0 -1
@@ -1,102 +1,191 @@
1
- import Configuration from './configurations/configuration';
2
- import TargetingData from './targeting/targetingData';
3
- import Experiment from './configurations/experiment';
4
- import FeatureFlag from './configurations/featureFlag';
5
- import ExperimentConfigurationNotFound from './exceptions/experimentConfigurationNotFound';
6
- import FeatureConfigurationNotFound from './exceptions/featureConfigurationNotFound';
7
- import NotActivated from './exceptions/notActivated';
8
- import NotTargeted from './exceptions/notTargeted';
9
- import VariationConfigurationNotFound from './exceptions/variationConfigurationNotFound';
10
- import CredentialsNotFound from './exceptions/credentialsNotFound';
11
- import { CallbackInterface, DataInterface, SDKConfiguration } from './interfaces/interfaces';
12
- declare class KameleoonClient {
13
- static readonly VISITOR_CODE_MAX_LENGTH = 255;
14
- configurations?: Configuration;
15
- ready: boolean;
16
- readyCallbacks: CallbackInterface[];
17
- minutesBetweenConfigurationUpdate: number;
18
- siteCode: string;
19
- targetingData: {
20
- [visitorCode: string]: TargetingData[];
21
- };
22
- targetingDataNumberEntriesAuthorized: number;
23
- unsentData: {
24
- [visitorCode: string]: DataInterface[];
25
- };
26
- visitorDataMaximumSize: number;
27
- environment: string | null;
28
- private realTimeConfigurationService;
29
- private handlerUpdateConfiguration;
30
- private variationStorage;
31
- constructor(siteCode: string, configuration?: SDKConfiguration);
32
- private updateCampaignConfiguration;
33
- runWhenReady: (successCallback: () => void, errorCallback: () => void, timeout: number) => void;
34
- clearCallbacks: (success: boolean, errorCallback?: (() => void) | undefined) => void;
35
- trackConversion: (visitorCode: string, goalId: number, revenue?: number | undefined) => void;
36
- flush: (visitorCode?: string | undefined) => void;
1
+ import { JSONType } from './campaignConfiguration';
2
+ import { KameleoonDataType } from './kameleoonData';
3
+ import { TrackConversionParamsType, ExperimentType, FeatureFlagType, GetFeatureFlagVariableParamsType, FeatureVariableResultType, SDKCoreParameters } from './types';
4
+ /**
5
+ * @interface an interface of KameleoonClient instance
6
+ * */
7
+ export interface IKameleoonClient {
8
+ /**
9
+ * @method initialize - an asynchronous method for KameleoonClient initialization by fetching Kameleoon SDK related data from server or by retrieving data from local source if data is up-to-date or update interval has not been reached
10
+ * @returns {Promise<boolean>} Promise resolved into boolean field indicating success or fail
11
+ * @throws `KameleoonError` with one of the following `type` s:
12
+ *
13
+ * - `KameleoonException.StorageWrite` Couldn't update storage data
14
+ * - `KameleoonException.ClientConfiguration` Couldn't retrieve client configuration from Kameleoon Api
15
+ * */
16
+ initialize: () => Promise<boolean>;
17
+ /**
18
+ * @method addData - method for adding targeting data to the storage so that other methods could decide whether the current visitor is targeted or not. Note: userAgent data will not be stored in storage like other data, and it will be sent with every tracking request for bot filtration.
19
+ * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length
20
+ * @param {KameleoonDataType[]} kameleoonData - number of instances of any type of `KameleoonData`, can be added solely in array or as a sequential arguments
21
+ * @returns {void}
22
+ * @throws `KameleoonError` with one of the following `type` s:
23
+ *
24
+ * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded
25
+ * - `KameleoonException.StorageWrite` Couldn't update storage data
26
+ * - `KameleoonException.Initialization` Couldn't update storage data
27
+ * */
28
+ addData: (visitorCode: string, ...data: KameleoonDataType[]) => void;
29
+ /**
30
+ * @method triggerExperiment - triggers experiment by assigning the variation to the user with `visitorCode`, if the variation is already assigned just returns it's id. Note: returned id `0` indicates default variation. At the same time executes `flushData` without sending extra request.
31
+ * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length
32
+ * @param {number} experimentId - id of experiment running for the current visitor
33
+ * @returns {number} associated variationId which is successfully searched/assigned
34
+ * @throws `KameleoonError` with one of the following `type` s:
35
+ *
36
+ * - `KameleoonException.ExperimentConfigurationNotFound` No configuration found for provided `experimentId`
37
+ * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded
38
+ * - `KameleoonException.StorageRead` Couldn't find associated experiment by provided `experimentId` and `visitorCode` inside the storage
39
+ * - `KameleoonException.NotTargeted` Current visitor is not targeted
40
+ * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`
41
+ * */
37
42
  triggerExperiment: (visitorCode: string, experimentId: number) => number;
38
- activateFeature: (visitorCode: string, featureIdOrName: number | string) => boolean;
39
- generateRandomString: () => string;
40
- obtainAsyncVisitorCode: (domain: string, defaultVisitorCode?: string | undefined) => Promise<string>;
41
- obtainVisitorCode: (domain: string, defaultVisitorCode?: string | undefined) => string;
42
- obtainHashDouble: (containerId: number, visitorCode: string, xpConf: Experiment | FeatureFlag) => number;
43
- private getCommonSSXParameters;
44
- private getDataTrackingURL;
45
- private getAPIDataRequestURL;
46
- private getEventsRequestURL;
47
- getExperimentRegisterURL: (visitorCode: string, experimentId: number, variationId?: number | undefined, noneVariation?: boolean | undefined) => string;
48
- getUnsentUsers: () => string[];
49
- getUnsentData: (visitorCode: string) => DataInterface[];
50
- getTargetingData: (visitorCode: string) => TargetingData[];
51
- emptyUnsentData: (visitorCode: string) => void;
52
- emptyTargetingData: () => void;
53
- addData: (visitorCode: string, ...data: DataInterface[]) => Promise<void>;
54
- checkTargeting: (visitorCode: string, campaignId: number, isFF: boolean) => boolean | null;
55
- private getConditionData;
56
- obtainVariationAssociatedData: (variationId: number) => Record<string | number | symbol, string | number | boolean | {
57
- [x: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any)[])[])[])[])[])[])[])[])[])[])[];
58
- } | (string | number | boolean | {
59
- [x: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any)[])[])[])[])[])[])[])[])[])[])[];
60
- } | (string | number | boolean | {
61
- [x: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any)[])[])[])[])[])[])[])[])[])[])[];
62
- } | (string | number | boolean | {
63
- [x: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any)[])[])[])[])[])[])[])[])[])[])[];
64
- } | (string | number | boolean | {
65
- [x: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any)[])[])[])[])[])[])[])[])[])[])[];
66
- } | (string | number | boolean | {
67
- [x: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any)[])[])[])[])[])[])[])[])[])[])[];
68
- } | (string | number | boolean | {
69
- [x: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any)[])[])[])[])[])[])[])[])[])[])[];
70
- } | (string | number | boolean | {
71
- [x: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any)[])[])[])[])[])[])[])[])[])[])[];
72
- } | (string | number | boolean | {
73
- [x: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any)[])[])[])[])[])[])[])[])[])[])[];
74
- } | (string | number | boolean | {
75
- [x: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any)[])[])[])[])[])[])[])[])[])[])[];
76
- } | (string | number | boolean | {
77
- [x: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any)[])[])[])[])[])[])[])[])[])[])[];
78
- } | (string | number | boolean | {
79
- [x: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any)[])[])[])[])[])[])[])[])[])[])[];
80
- } | any)[])[])[])[])[])[])[])[])[])[])[]>;
81
- obtainFeatureVariable: (featureIdOrName: number | string, variable: string) => any;
82
- retrieveDataFromRemoteSource: (key: string) => Promise<any>;
83
- private _parseJsonValue;
84
- private saveConfiguration;
85
- private validateVisitorCode;
86
- private checkSiteEnabled;
87
- private checkFeatureKeyOrId;
88
- private getAndClearUnsentData;
89
- onUpdateConfiguration: (handler: () => void) => void;
90
- private manageConfiguraitonUpdate;
91
- private fireUpdateConfigurationHandler;
43
+ /**
44
+ * @method trackConversion - creates and adds `Conversion` data to the visitor with specified parameters and executes `flushData`. Note: it's a helper method for the quick and convenient conversion tracking, however creating and adding `Conversion` manually allows more flexible `Conversion` with `negative` parameter
45
+ * @param {TrackConversionParamsType} conversionParameters - `visitorCode`, `goalId` and `revenue` parameters for data tracking
46
+ * @returns {void}
47
+ * @throws `KameleoonError` with one of the following `type` s:
48
+ *
49
+ * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded
50
+ * - `KameleoonException.StorageWrite` Couldn't update storage data
51
+ * */
52
+ trackConversion: ({ visitorCode, goalId, revenue, }: TrackConversionParamsType) => void;
53
+ /**
54
+ * @method flushData - takes visitor associated kameleoon data and sends the data tracking request with collected data
55
+ * sent data is removed from `KameleoonClient` instance but not from the storage for correct targeting checks
56
+ * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length
57
+ * @returns {void}
58
+ * @throws `KameleoonError` with one of the following `type` s:
59
+ *
60
+ * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`
61
+ * */
62
+ flushData: (visitorCode: string) => void;
63
+ /**
64
+ * @method getExperiments - returns a list of experiments stored in the client configuration
65
+ * @returns {ExperimentType[]} a list of all experiments items with `id` and `name` fields
66
+ * @throws `KameleoonError` with one of the following `type` s:
67
+ *
68
+ * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`
69
+ * */
70
+ getExperiments: () => ExperimentType[];
71
+ /**
72
+ * @method getVisitorExperiments - returns a list of experiments that the visitor with `visitorCode` is targeted by and that are *active* for the visitor (visitor will have one of the variations allocated if the experiment will be triggered).
73
+ * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length
74
+ * @param {boolean | undefined} isAllocated - boolean value indicating that only experiments *allocated* for visitor will be returned. Default value is `true`
75
+ * @returns {ExperimentType[]} a list of all experiments items with `id` and `name` fields
76
+ * @throws `KameleoonError` with one of the following `type` s:
77
+ *
78
+ * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded
79
+ * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`
80
+ * */
81
+ getVisitorExperiments: (visitorCode: string, isAllocated?: boolean) => ExperimentType[];
82
+ /**
83
+ * @method getFeatureFlags - returns a list of feature flags stored in the client configuration
84
+ * @returns {FeatureFlagType[]} a list of all feature flags items with `id` and `key` fields
85
+ * @throws `KameleoonError` with one of the following `type` s:
86
+ *
87
+ * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`
88
+ * */
89
+ getFeatureFlags: () => FeatureFlagType[];
90
+ /**
91
+ * @method getVisitorFeatureFlags - returns a list of feature flags that the visitor with `visitorCode` that is targeted by and that are *active* for the visitor (visitor will have one of the variations allocated).
92
+ * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length
93
+ * @returns {FeatureFlagType[]} a list of all feature flags items with `id` and `key` fields
94
+ * @throws `KameleoonError` with one of the following `type` s:
95
+ *
96
+ * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded
97
+ * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`
98
+ * - `KameleoonException.NotTargeted` - Current visitor is not targeted
99
+ * */
100
+ getVisitorFeatureFlags: (visitorCode: string) => FeatureFlagType[];
101
+ /**
102
+ * @method isFeatureFlagActive - returns a boolean indicating whether the visitor with `visitorCode` has `featureKey` active for him, this method includes targeting check, finding the according variation exposed to the visitor and saving it to storage along with sending tracking request if the feature rollout rule was of type of `Experimentation`
103
+ * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length
104
+ * @param {string} featureKey - a unique key for feature flag
105
+ * @returns {boolean} a boolean indicator of whether the feature flag with `featureKey` is active for visitor with `visitorCode`
106
+ * @throws `KameleoonError` with one of the following `type` s:
107
+ *
108
+ * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded
109
+ * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`
110
+ * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `visitorCode` and `featureKey`
111
+ * - `KameleoonException.DataInconsistency` - Allocated variation was found but there is no feature flag with according `featureKey`.
112
+ * - `KameleoonException.NotTargeted` - Current visitor is not targeted
113
+ * */
114
+ isFeatureFlagActive: (visitorCode: string, featureKey: string) => boolean;
115
+ /**
116
+ * @method getFeatureFlagVariationKey - returns variation key for the visitor under `visitorCode` in the found feature flag, this method includes targeting check, finding the according variation exposed to the visitor and saving it to storage along with sending tracking request if the feature rollout rule was of type of `Experimentation`
117
+ * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length
118
+ * @param {string} featureKey - a unique key for feature flag
119
+ * @returns {string} a string containing variable key for the allocated feature flag variation for the provided visitor
120
+ * @throws `KameleoonError` with one of the following `type` s:
121
+ *
122
+ * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded
123
+ * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`
124
+ * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `visitorCode` and `featureKey`
125
+ * - `KameleoonException.NotTargeted` - Current visitor is not targeted
126
+ * */
127
+ getFeatureFlagVariationKey: (visitorCode: string, featureKey: string) => string;
128
+ /**
129
+ * @method getFeatureFlagVariable - returns a variable for the visitor under `visitorCode` in the found feature flag, this method includes targeting check, finding the according variation exposed to the visitor and saving it to storage along with sending tracking request if the feature rollout rule was of type of `Experimentation`
130
+ * @param {GetFeatureFlagVariableParamsType} parameters - an object with parameters of a type `GetFeatureFlagVariableParamsType`, see the type for details.
131
+ * @returns {FeatureVariableResultType} a variable object containing `type` and `value` fields, `type` can be checked against `FeatureVariableType` enum, if the `type` is `FeatureVariableType.BOOLEAN` then the `value` type will be `boolean` and so on.
132
+ * @throws `KameleoonError` with one of the following `type` s:
133
+ *
134
+ * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded
135
+ * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`
136
+ * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `visitorCode` and `featureKey`
137
+ * - `KameleoonException.NotTargeted` - Current visitor is not targeted
138
+ * - `KameleoonException.JSONParse` - Couldn't pass JSON value
139
+ * - `KameleoonException.NumberParse` - Couldn't pass Number value
140
+ * */
141
+ getFeatureFlagVariable: ({ visitorCode, featureKey, variableKey, }: GetFeatureFlagVariableParamsType) => FeatureVariableResultType;
142
+ /**
143
+ * @method getRemoteData - returns a data which is stored for specified siteCode on a remote Kameleoon server.
144
+ * @param {string} key - unique key that the data you try to get is associated with.
145
+ * @returns {JSONType} - promise with retrieving data for specific key.
146
+ * @throws `KameleoonError` with one of the following `type` s:
147
+ *
148
+ * - `KameleoonException.RemoteData` - Couldn't retrieve data from Kameleoon server
149
+ * */
150
+ getRemoteData: (key: string) => Promise<JSONType>;
151
+ /**
152
+ * @method onConfigurationUpdate - fires a callback on client configuration update. Note: this method only works for server sent events of real time update.
153
+ * @param {() => void} callback - callback function with no parameters that will be called upon configuration update
154
+ * @returns {void}
155
+ * @throws `KameleoonError` with one of the following `type` s:
156
+ *
157
+ * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`
158
+ * */
159
+ onConfigurationUpdate: (callback: () => void) => void;
160
+ }
161
+ /**
162
+ * @class
163
+ * KameleoonClient - a class for creating kameleoon client instance
164
+ * for communicating with Kameleoon JavaScript SDK Core, when new instance is created
165
+ * */
166
+ export declare class KameleoonClient implements IKameleoonClient {
167
+ private internalConfiguration;
168
+ private variationConfiguration?;
169
+ private campaignConfiguration?;
170
+ private settings;
171
+ private requester;
172
+ /**
173
+ * @param {SDKCoreParameters} sdkCoreParameters - parameters for initializing sdk core
174
+ */
175
+ constructor({ siteCode, configuration, internalConfiguration, }: SDKCoreParameters);
176
+ initialize(): Promise<boolean>;
177
+ addData(visitorCode: string, ...data: KameleoonDataType[]): void;
178
+ triggerExperiment(visitorCode: string, experimentId: number): number;
179
+ trackConversion({ visitorCode, goalId, revenue, }: TrackConversionParamsType): void;
180
+ flushData(visitorCode: string): void;
181
+ getExperiments(): ExperimentType[];
182
+ getVisitorExperiments(visitorCode: string, isActive?: boolean): ExperimentType[];
183
+ getFeatureFlags(): FeatureFlagType[];
184
+ getVisitorFeatureFlags(visitorCode: string): FeatureFlagType[];
185
+ getFeatureFlagVariationKey(visitorCode: string, featureKey: string): string;
186
+ getFeatureFlagVariable({ visitorCode, featureKey, variableKey, }: GetFeatureFlagVariableParamsType): FeatureVariableResultType;
187
+ isFeatureFlagActive(visitorCode: string, featureKey: string): boolean;
188
+ getRemoteData(key: string): Promise<JSONType>;
189
+ onConfigurationUpdate(callback: () => void): void;
190
+ private _getFeatureFlagVariation;
92
191
  }
93
- declare const KameleoonException: {
94
- ExperimentConfigurationNotFound: typeof ExperimentConfigurationNotFound;
95
- FeatureConfigurationNotFound: typeof FeatureConfigurationNotFound;
96
- VariationConfigurationNotFound: typeof VariationConfigurationNotFound;
97
- NotTargeted: typeof NotTargeted;
98
- NotActivated: typeof NotActivated;
99
- CredentialsNotFound: typeof CredentialsNotFound;
100
- };
101
- export { KameleoonClient };
102
- export { KameleoonException };