@kameleoon/javascript-sdk-core 4.0.0 → 4.1.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 (118) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/clientConfiguration/clientConfiguration.js +1 -1
  3. package/dist/clientConfiguration/clientConfiguration.js.map +1 -1
  4. package/dist/clientConfiguration/constants.js +1 -1
  5. package/dist/clientConfiguration/constants.js.map +1 -1
  6. package/dist/clientConfiguration/types.d.ts +1 -1
  7. package/dist/clientConfiguration/types.js.map +1 -1
  8. package/dist/constants.js +1 -1
  9. package/dist/constants.js.map +1 -1
  10. package/dist/kameleoonClient.d.ts +2 -1
  11. package/dist/kameleoonClient.js +1 -1
  12. package/dist/kameleoonClient.js.map +1 -1
  13. package/dist/kameleoonClientInterface.d.ts +2 -2
  14. package/dist/kameleoonClientInterface.js.map +1 -1
  15. package/dist/kameleoonData/applicationVersion.d.ts +0 -9
  16. package/dist/kameleoonData/applicationVersion.js.map +1 -1
  17. package/dist/kameleoonData/browser.d.ts +3 -12
  18. package/dist/kameleoonData/browser.js +1 -1
  19. package/dist/kameleoonData/browser.js.map +1 -1
  20. package/dist/kameleoonData/conversion.d.ts +11 -13
  21. package/dist/kameleoonData/conversion.js +1 -1
  22. package/dist/kameleoonData/conversion.js.map +1 -1
  23. package/dist/kameleoonData/cookie.d.ts +0 -9
  24. package/dist/kameleoonData/cookie.js.map +1 -1
  25. package/dist/kameleoonData/customData.d.ts +3 -13
  26. package/dist/kameleoonData/customData.js +1 -1
  27. package/dist/kameleoonData/customData.js.map +1 -1
  28. package/dist/kameleoonData/dataManager.d.ts +11 -5
  29. package/dist/kameleoonData/dataManager.js +1 -1
  30. package/dist/kameleoonData/dataManager.js.map +1 -1
  31. package/dist/kameleoonData/dataProcessor.d.ts +13 -6
  32. package/dist/kameleoonData/dataProcessor.js +1 -1
  33. package/dist/kameleoonData/dataProcessor.js.map +1 -1
  34. package/dist/kameleoonData/device.d.ts +3 -12
  35. package/dist/kameleoonData/device.js +1 -1
  36. package/dist/kameleoonData/device.js.map +1 -1
  37. package/dist/kameleoonData/geolocation.d.ts +3 -12
  38. package/dist/kameleoonData/geolocation.js +1 -1
  39. package/dist/kameleoonData/geolocation.js.map +1 -1
  40. package/dist/kameleoonData/index.d.ts +1 -0
  41. package/dist/kameleoonData/index.js +1 -1
  42. package/dist/kameleoonData/index.js.map +1 -1
  43. package/dist/kameleoonData/kameleoonConversionScore.d.ts +15 -0
  44. package/dist/kameleoonData/kameleoonConversionScore.js +2 -0
  45. package/dist/kameleoonData/kameleoonConversionScore.js.map +1 -0
  46. package/dist/kameleoonData/operatingSystem.d.ts +3 -12
  47. package/dist/kameleoonData/operatingSystem.js +1 -1
  48. package/dist/kameleoonData/operatingSystem.js.map +1 -1
  49. package/dist/kameleoonData/pageView.d.ts +4 -13
  50. package/dist/kameleoonData/pageView.js +1 -1
  51. package/dist/kameleoonData/pageView.js.map +1 -1
  52. package/dist/kameleoonData/types.d.ts +54 -11
  53. package/dist/kameleoonData/types.js +1 -1
  54. package/dist/kameleoonData/types.js.map +1 -1
  55. package/dist/kameleoonData/userAgent.d.ts +0 -9
  56. package/dist/kameleoonData/userAgent.js.map +1 -1
  57. package/dist/kameleoonData/visitProcessor.d.ts +34 -0
  58. package/dist/kameleoonData/visitProcessor.js +2 -0
  59. package/dist/kameleoonData/visitProcessor.js.map +1 -0
  60. package/dist/kameleoonData/visitsData.d.ts +7 -21
  61. package/dist/kameleoonData/visitsData.js +1 -1
  62. package/dist/kameleoonData/visitsData.js.map +1 -1
  63. package/dist/requester/constants.d.ts +1 -3
  64. package/dist/requester/constants.js +1 -1
  65. package/dist/requester/constants.js.map +1 -1
  66. package/dist/requester/index.d.ts +1 -1
  67. package/dist/requester/index.js +1 -1
  68. package/dist/requester/index.js.map +1 -1
  69. package/dist/requester/requester.d.ts +2 -6
  70. package/dist/requester/requester.js +1 -1
  71. package/dist/requester/requester.js.map +1 -1
  72. package/dist/requester/types.d.ts +24 -2
  73. package/dist/requester/types.js +1 -1
  74. package/dist/requester/types.js.map +1 -1
  75. package/dist/requester/urlProvider.d.ts +17 -0
  76. package/dist/requester/urlProvider.js +2 -0
  77. package/dist/requester/urlProvider.js.map +1 -0
  78. package/dist/storage/storage.js +1 -1
  79. package/dist/targeting/conditions/browser.js +1 -1
  80. package/dist/targeting/conditions/browser.js.map +1 -1
  81. package/dist/targeting/conditions/conditionFactory.js +1 -1
  82. package/dist/targeting/conditions/conditionFactory.js.map +1 -1
  83. package/dist/targeting/conditions/conversionLikelihood.d.ts +12 -0
  84. package/dist/targeting/conditions/conversionLikelihood.js +2 -0
  85. package/dist/targeting/conditions/conversionLikelihood.js.map +1 -0
  86. package/dist/targeting/conditions/firstVisit.js +1 -1
  87. package/dist/targeting/conditions/firstVisit.js.map +1 -1
  88. package/dist/targeting/conditions/geolocation.js +1 -1
  89. package/dist/targeting/conditions/geolocation.js.map +1 -1
  90. package/dist/targeting/conditions/index.d.ts +1 -0
  91. package/dist/targeting/conditions/index.js +1 -1
  92. package/dist/targeting/conditions/index.js.map +1 -1
  93. package/dist/targeting/conditions/lastVisit.js +1 -1
  94. package/dist/targeting/conditions/lastVisit.js.map +1 -1
  95. package/dist/targeting/conditions/newVisitor.js +1 -1
  96. package/dist/targeting/conditions/newVisitor.js.map +1 -1
  97. package/dist/targeting/conditions/sameDayVisits.js +1 -1
  98. package/dist/targeting/conditions/sameDayVisits.js.map +1 -1
  99. package/dist/targeting/conditions/targetFeatureFlag.js +1 -1
  100. package/dist/targeting/conditions/types.d.ts +3 -0
  101. package/dist/targeting/conditions/types.js.map +1 -1
  102. package/dist/targeting/conditions/visits.js +1 -1
  103. package/dist/targeting/conditions/visits.js.map +1 -1
  104. package/dist/targeting/index.d.ts +2 -2
  105. package/dist/targeting/index.js +1 -1
  106. package/dist/targeting/index.js.map +1 -1
  107. package/dist/targeting/types.d.ts +4 -0
  108. package/dist/targeting/types.js.map +1 -1
  109. package/dist/types.d.ts +2 -0
  110. package/dist/types.js.map +1 -1
  111. package/dist/utilities/types.d.ts +6 -1
  112. package/dist/utilities/types.js.map +1 -1
  113. package/dist/utilities/utilities.d.ts +1 -1
  114. package/dist/utilities/utilities.js +1 -1
  115. package/dist/utilities/utilities.js.map +1 -1
  116. package/dist/variationConfiguration/types.d.ts +1 -1
  117. package/dist/variationConfiguration/types.js.map +1 -1
  118. package/package.json +6 -2
@@ -1 +1 @@
1
- {"version":3,"file":"kameleoonClientInterface.js","names":[],"sources":["../src/kameleoonClientInterface.ts"],"sourcesContent":["import { JSONType } from './clientConfiguration';\nimport { CustomData, KameleoonDataType } from './kameleoonData';\nimport {\n FeatureFlagType,\n FeatureFlagVariableType,\n FeatureVariableResultType,\n GetFeatureFlagVariableParamsType,\n GetVisitorWarehouseAudienceParamsType,\n RemoteVisitorDataParamsType,\n TrackConversionParamsType,\n} from './types';\n\n/**\n * @interface an interface of KameleoonClient instance\n */\nexport interface IKameleoonClient {\n /**\n * @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\n * @param {boolean | undefined} useCache - optional parameter for activating SDK offline mode, if `true` is passed failed polls will not return error and will use cached data if such data is available, default value is `false`. Note: if offline mode is on, SDK will still try to retrieve the latest data.\n * @returns {Promise<boolean>} Promise resolved into boolean field indicating success or fail\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.StorageWrite` Couldn't update storage data\n * - `KameleoonException.ClientConfiguration` Couldn't retrieve client configuration from Kameleoon Api\n * - `KameleoonException.MaximumRetriesReached` Maximum retries reached, request failed\n */\n initialize(useCache?: boolean): Promise<boolean>;\n initialize(): Promise<boolean>;\n /**\n * @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.\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @param {KameleoonDataType[]} kameleoonData - number of instances of any type of `KameleoonData`, can be added solely in array or as a sequential arguments\n * @returns {void}\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.StorageWrite` Couldn't update storage data\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n */\n addData: (visitorCode: string, ...data: KameleoonDataType[]) => void;\n /**\n * @method getRemoteVisitorData - an asynchronous method for retrieving KameleoonData from Data API and optionally adding it to the storage so that other methods could decide whether the current visitor is targeted or not.\n * @param {RemoteVisitorDataParamsType} remoteVisitorDataParameters - `visitorCode`, `shouldAddData` and `filters` parameters\n * @returns {KameleoonDataType[]} promise resolved to an array of `KameleoonData` instances, only includes custom data\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.RemoteData` - Couldn't retrieve data from Kameleoon server\n * - `KameleoonException.VisitAmount` - Visit amount must be a number between 1 and 25\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n */\n getRemoteVisitorData: ({\n visitorCode,\n shouldAddData,\n filters,\n }: RemoteVisitorDataParamsType) => Promise<KameleoonDataType[]>;\n /**\n * @method trackConversion - creates and adds `Conversion` data to the visitor with specified parameters and executes `flush`. 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\n * @param {TrackConversionParamsType} conversionParameters - `visitorCode`, `goalId` and `revenue` parameters for data tracking\n * @returns {void}\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.StorageWrite` Couldn't update storage data\n */\n trackConversion: ({\n visitorCode,\n goalId,\n revenue,\n isUniqueIdentifier,\n }: TrackConversionParamsType) => void;\n /**\n * @method flush - takes visitor associated kameleoon data and sends the data tracking request with collected data,\n * sent data is removed from `KameleoonClient` instance but not from the storage for correct targeting checks. If no visitor is passed,\n * then data for all visitors is sent and removed from `KameleoonClient` instance. Moreover, regardless of visitor code input\n * the method first attempts to send all previously failed tracking requests which were stored locally during the offline mode.\n * @param {string | undefined} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @param {boolean | undefined} isUniqueIdentifier - an optional parameter for specifying if the visitorCode is a unique identifier, default value is `false`\n * @returns {void}\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n */\n flush: (visitorCode?: string, isUniqueIdentifier?: boolean) => void;\n /**\n * @method getFeatureFlags - returns a list of feature flags stored in the client configuration\n * @returns {FeatureFlagType[]} a list of all feature flags items with `id` and `key` fields\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n */\n getFeatureFlags: () => FeatureFlagType[];\n /**\n * @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).\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @returns {FeatureFlagType[]} a list of all feature flags items with `id` and `key` fields\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`\n * - `KameleoonException.StorageRead` - Couldn't read storage data\n * - `KameleoonException.NotTargeted` - Current visitor is not targeted\n */\n getVisitorFeatureFlags: (visitorCode: string) => FeatureFlagType[];\n /**\n * @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\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @param {string} featureKey - a unique key for feature flag\n * @returns {boolean} a boolean indicator of whether the feature flag with `featureKey` is active for visitor with `visitorCode`\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `featureKey`\n * - `KameleoonException.DataInconsistency` - Allocated variation was found but there is no feature flag with according `featureKey`.\n * - `KameleoonException.NotTargeted` - Current visitor is not targeted\n */\n isFeatureFlagActive: (visitorCode: string, featureKey: string) => boolean;\n /**\n * @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\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @param {string} featureKey - a unique key for feature flag\n * @returns {string} a string containing variable key for the allocated feature flag variation for the provided visitor\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `featureKey`\n * - `KameleoonException.FeatureFlagEnvironmentDisabled` - The feature flag is disabled for the current environment\n * - `KameleoonException.NotTargeted` - Current visitor is not targeted\n */\n getFeatureFlagVariationKey: (\n visitorCode: string,\n featureKey: string,\n ) => string;\n /**\n * @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\n * @param {GetFeatureFlagVariableParamsType} parameters - an object with parameters of a type `GetFeatureFlagVariableParamsType`, see the type for details.\n * @returns {FeatureFlagVariableType} a variable object containing `type` and `value` fields. You can check the `type` field against `VariableType` enum. For example, if the `type` is `VariableType.BOOLEAN` then `value` will be a `boolean` type.\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `featureKey`\n * - `KameleoonException.FeatureFlagVariableNotFound` - No feature variable was found for provided `visitorCode` and `variableKey`\n * - `KameleoonException.FeatureFlagEnvironmentDisabled` - The feature flag is disabled for the current environment\n * - `KameleoonException.NotTargeted` - Current visitor is not targeted\n * - `KameleoonException.JSONParse` - Couldn't parse JSON value\n * - `KameleoonException.NumberParse` - Couldn't parse Number value\n */\n getFeatureFlagVariable: ({\n visitorCode,\n featureKey,\n variableKey,\n }: GetFeatureFlagVariableParamsType) => FeatureFlagVariableType;\n /**\n * @method getFeatureFlagVariables - returns a list of variables 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\n * @param {string} visitorCode - a unique visitor identifier, shouldn't exceed 255 characters\n * @param {string} featureKey - a unique key for feature flag\n * @returns {FeatureVariableResultType[]} a list of variable objects containing `key`, `type` and `value` fields. You can check the `type` field against `VariableType` enum. For example, if the `type` is `VariableType.BOOLEAN` then `value` will be a `boolean` type.\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `featureKey`\n * - `KameleoonException.FeatureFlagVariationNotFound` - No feature variation was found for provided `visitorCode` and `variationKey`\n * - `KameleoonException.FeatureFlagEnvironmentDisabled` - The feature flag is disabled for the current environment\n * - `KameleoonException.JSONParse` - Couldn't parse JSON value\n * - `KameleoonException.NumberParse` - Couldn't parse Number value\n */\n getFeatureFlagVariables: (\n visitorCode: string,\n featureKey: string,\n ) => FeatureVariableResultType[];\n /**\n * @method getRemoteData - returns a data which is stored for specified siteCode on a remote Kameleoon server.\n * @param {string} key - unique key that the data you try to get is associated with.\n * @returns {JSONType} - promise with retrieving data for specific key.\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.RemoteData` - Couldn't retrieve data from Kameleoon server\n */\n getRemoteData: (key: string) => Promise<JSONType>;\n /**\n * @method getVisitorWarehouseAudience - an async method that returns a `CustomData` instance, containing data associated with a visitor's warehouse audiences\n * which is stored for specified visitorCode on a remote Kameleoon server.\n * Retrieved data will be added to storage under the specified `customDataIndex`\n * @param {GetVisitorWarehouseAudienceParamsType} parameters - an object with parameters of a type `GetVisitorWarehouseAudienceParamsType`, see the type for details.\n * @returns {Promise<CustomData | null>} `Promise` containing an instance of `CustomData` containing data associated with a visitor's warehouse audiences or `null` if the data was retrieved successfully but nothing was found under the specified `warehouseKey`\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` - The visitor code is empty\n * - `KameleoonException.RemoteData` - Couldn't retrieve data from Kameleoon server\n */\n getVisitorWarehouseAudience: ({\n visitorCode,\n customDataIndex,\n warehouseKey,\n }: GetVisitorWarehouseAudienceParamsType) => Promise<CustomData | null>;\n /**\n * @method getEngineTrackingCode - returns Kameleoon tracking code for the current visitor. Tracking code is built of the experiments that were triggered and feature flag variations that were assigned during the last 5 seconds\n * See [Kameleoon Automation API](https://developers.kameleoon.com/apis/activation-api-js/api-reference#trigger-1) for the details\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @returns {string} Kameleoon tracking code\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n */\n getEngineTrackingCode: (visitorCode: string) => string;\n /**\n * @method onConfigurationUpdate - fires a callback on client configuration update. Note: this method only works for server sent events of real time update.\n * @param {() => void} callback - callback function with no parameters that will be called upon configuration update\n * @returns {void}\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n */\n onConfigurationUpdate: (callback: () => void) => void;\n}\n"],"mappings":""}
1
+ {"version":3,"file":"kameleoonClientInterface.js","names":[],"sources":["../src/kameleoonClientInterface.ts"],"sourcesContent":["import { JSONType } from './clientConfiguration';\nimport { CustomData, KameleoonDataType } from './kameleoonData';\nimport {\n FeatureFlagType,\n FeatureFlagVariableType,\n FeatureVariableResultType,\n GetFeatureFlagVariableParamsType,\n GetVisitorWarehouseAudienceParamsType,\n RemoteVisitorDataParamsType,\n TrackConversionParamsType,\n} from './types';\n\n/**\n * @interface an interface of KameleoonClient instance\n */\nexport interface IKameleoonClient {\n /**\n * @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\n * @param {boolean | undefined} useCache - optional parameter for activating SDK offline mode, if `true` is passed failed polls will not return error and will use cached data if such data is available, default value is `false`. Note: if offline mode is on, SDK will still try to retrieve the latest data.\n * @returns {Promise<boolean>} Promise resolved into boolean field indicating success or fail\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.StorageWrite` Couldn't update storage data\n * - `KameleoonException.ClientConfiguration` Couldn't retrieve client configuration from Kameleoon Api\n * - `KameleoonException.MaximumRetriesReached` Maximum retries reached, request failed\n */\n initialize(useCache?: boolean): Promise<boolean>;\n initialize(): Promise<boolean>;\n /**\n * @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.\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @param {KameleoonDataType[]} kameleoonData - number of instances of any type of `KameleoonData`, can be added solely in array or as a sequential arguments\n * @returns {void}\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.StorageWrite` Couldn't update storage data\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n */\n addData: (visitorCode: string, ...data: KameleoonDataType[]) => void;\n /**\n * @method getRemoteVisitorData - an asynchronous method for retrieving KameleoonData from Data API and optionally adding it to the storage so that other methods could decide whether the current visitor is targeted or not.\n * @param {RemoteVisitorDataParamsType} remoteVisitorDataParameters - `visitorCode`, `shouldAddData`, `filters` and `isUniqueIdentifier` parameters\n * @returns {KameleoonDataType[]} promise resolved to an array of `KameleoonData` instances, only includes custom data\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.RemoteData` - Couldn't retrieve data from Kameleoon server\n * - `KameleoonException.VisitAmount` - Visit amount must be a number between 1 and 25\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n */\n getRemoteVisitorData: ({\n visitorCode,\n shouldAddData,\n filters,\n isUniqueIdentifier,\n }: RemoteVisitorDataParamsType) => Promise<KameleoonDataType[]>;\n /**\n * @method trackConversion - creates and adds `Conversion` data to the visitor with specified parameters and executes `flush`. 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\n * @param {TrackConversionParamsType} conversionParameters - `visitorCode`, `goalId` and `revenue` parameters for data tracking\n * @returns {void}\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.StorageWrite` Couldn't update storage data\n */\n trackConversion: ({\n visitorCode,\n goalId,\n revenue,\n isUniqueIdentifier,\n }: TrackConversionParamsType) => void;\n /**\n * @method flush - takes visitor associated kameleoon data and sends the data tracking request with collected data,\n * sent data is removed from `KameleoonClient` instance but not from the storage for correct targeting checks. If no visitor is passed,\n * then data for all visitors is sent and removed from `KameleoonClient` instance. Moreover, regardless of visitor code input\n * the method first attempts to send all previously failed tracking requests which were stored locally during the offline mode.\n * @param {string | undefined} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @param {boolean | undefined} isUniqueIdentifier - an optional parameter for specifying if the visitorCode is a unique identifier, default value is `false`\n * @returns {void}\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n */\n flush: (visitorCode?: string, isUniqueIdentifier?: boolean) => void;\n /**\n * @method getFeatureFlags - returns a list of feature flags stored in the client configuration\n * @returns {FeatureFlagType[]} a list of all feature flags items with `id` and `key` fields\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n */\n getFeatureFlags: () => FeatureFlagType[];\n /**\n * @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).\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @returns {FeatureFlagType[]} a list of all feature flags items with `id` and `key` fields\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`\n * - `KameleoonException.StorageRead` - Couldn't read storage data\n * - `KameleoonException.NotTargeted` - Current visitor is not targeted\n */\n getVisitorFeatureFlags: (visitorCode: string) => FeatureFlagType[];\n /**\n * @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\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @param {string} featureKey - a unique key for feature flag\n * @returns {boolean} a boolean indicator of whether the feature flag with `featureKey` is active for visitor with `visitorCode`\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `featureKey`\n * - `KameleoonException.DataInconsistency` - Allocated variation was found but there is no feature flag with according `featureKey`.\n * - `KameleoonException.NotTargeted` - Current visitor is not targeted\n */\n isFeatureFlagActive: (visitorCode: string, featureKey: string) => boolean;\n /**\n * @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\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @param {string} featureKey - a unique key for feature flag\n * @returns {string} a string containing variable key for the allocated feature flag variation for the provided visitor\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `featureKey`\n * - `KameleoonException.FeatureFlagEnvironmentDisabled` - The feature flag is disabled for the current environment\n * - `KameleoonException.NotTargeted` - Current visitor is not targeted\n */\n getFeatureFlagVariationKey: (\n visitorCode: string,\n featureKey: string,\n ) => string;\n /**\n * @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\n * @param {GetFeatureFlagVariableParamsType} parameters - an object with parameters of a type `GetFeatureFlagVariableParamsType`, see the type for details.\n * @returns {FeatureFlagVariableType} a variable object containing `type` and `value` fields. You can check the `type` field against `VariableType` enum. For example, if the `type` is `VariableType.BOOLEAN` then `value` will be a `boolean` type.\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `featureKey`\n * - `KameleoonException.FeatureFlagVariableNotFound` - No feature variable was found for provided `visitorCode` and `variableKey`\n * - `KameleoonException.FeatureFlagEnvironmentDisabled` - The feature flag is disabled for the current environment\n * - `KameleoonException.NotTargeted` - Current visitor is not targeted\n * - `KameleoonException.JSONParse` - Couldn't parse JSON value\n * - `KameleoonException.NumberParse` - Couldn't parse Number value\n */\n getFeatureFlagVariable: ({\n visitorCode,\n featureKey,\n variableKey,\n }: GetFeatureFlagVariableParamsType) => FeatureFlagVariableType;\n /**\n * @method getFeatureFlagVariables - returns a list of variables 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\n * @param {string} visitorCode - a unique visitor identifier, shouldn't exceed 255 characters\n * @param {string} featureKey - a unique key for feature flag\n * @returns {FeatureVariableResultType[]} a list of variable objects containing `key`, `type` and `value` fields. You can check the `type` field against `VariableType` enum. For example, if the `type` is `VariableType.BOOLEAN` then `value` will be a `boolean` type.\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `featureKey`\n * - `KameleoonException.FeatureFlagVariationNotFound` - No feature variation was found for provided `visitorCode` and `variationKey`\n * - `KameleoonException.FeatureFlagEnvironmentDisabled` - The feature flag is disabled for the current environment\n * - `KameleoonException.JSONParse` - Couldn't parse JSON value\n * - `KameleoonException.NumberParse` - Couldn't parse Number value\n */\n getFeatureFlagVariables: (\n visitorCode: string,\n featureKey: string,\n ) => FeatureVariableResultType[];\n /**\n * @method getRemoteData - returns a data which is stored for specified siteCode on a remote Kameleoon server.\n * @param {string} key - unique key that the data you try to get is associated with.\n * @returns {JSONType} - promise with retrieving data for specific key.\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.RemoteData` - Couldn't retrieve data from Kameleoon server\n */\n getRemoteData: (key: string) => Promise<JSONType>;\n /**\n * @method getVisitorWarehouseAudience - an async method that returns a `CustomData` instance, containing data associated with a visitor's warehouse audiences\n * which is stored for specified visitorCode on a remote Kameleoon server.\n * Retrieved data will be added to storage under the specified `customDataIndex`\n * @param {GetVisitorWarehouseAudienceParamsType} parameters - an object with parameters of a type `GetVisitorWarehouseAudienceParamsType`, see the type for details.\n * @returns {Promise<CustomData | null>} `Promise` containing an instance of `CustomData` containing data associated with a visitor's warehouse audiences or `null` if the data was retrieved successfully but nothing was found under the specified `warehouseKey`\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` - The visitor code is empty\n * - `KameleoonException.RemoteData` - Couldn't retrieve data from Kameleoon server\n */\n getVisitorWarehouseAudience: ({\n visitorCode,\n customDataIndex,\n warehouseKey,\n }: GetVisitorWarehouseAudienceParamsType) => Promise<CustomData | null>;\n /**\n * @method getEngineTrackingCode - returns Kameleoon tracking code for the current visitor. Tracking code is built of the experiments that were triggered and feature flag variations that were assigned during the last 5 seconds\n * See [Kameleoon Automation API](https://developers.kameleoon.com/apis/activation-api-js/api-reference#trigger-1) for the details\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @returns {string} Kameleoon tracking code\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n */\n getEngineTrackingCode: (visitorCode: string) => string;\n /**\n * @method onConfigurationUpdate - fires a callback on client configuration update. Note: this method only works for server sent events of real time update.\n * @param {() => void} callback - callback function with no parameters that will be called upon configuration update\n * @returns {void}\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n */\n onConfigurationUpdate: (callback: () => void) => void;\n}\n"],"mappings":""}
@@ -10,17 +10,8 @@ export declare class ApplicationVersion implements IKameleoonData {
10
10
  * @param {string} version - version of mobile application
11
11
  * */
12
12
  constructor(version: string);
13
- /**
14
- * @property url - url for the current data type used for events tracking
15
- * */
16
13
  get url(): string;
17
- /**
18
- * @property data - data of the current class instance
19
- * */
20
14
  get data(): ApplicationVersionDataType;
21
- /**
22
- * @property isSent - signifying if the data was sent already tracked
23
- * */
24
15
  get isSent(): boolean;
25
16
  set isSent(value: boolean);
26
17
  }
@@ -1 +1 @@
1
- {"version":3,"file":"applicationVersion.js","names":["_types","require","Object","defineProperty","exports","value","ApplicationVersion","_defineProperty","a","b","c","_toPropertyKey","enumerable","configurable","writable","_toPrimitive","Symbol","toPrimitive","d","call","TypeError","String","Number","constructor","version","sent","url","data","type","KameleoonData","isSent"],"sources":["../../src/kameleoonData/applicationVersion.ts"],"sourcesContent":["import {\n IKameleoonData,\n KameleoonData,\n ApplicationVersionDataType,\n} from './types';\n\n/**\n * @class\n * ApplicationVersion - a class for creating an instance for app version\n * */\nexport class ApplicationVersion implements IKameleoonData {\n private version: string;\n private sent: boolean;\n\n /**\n * @param {string} version - version of mobile application\n * */\n constructor(version: string) {\n this.version = version;\n this.sent = false;\n }\n\n /**\n * @property url - url for the current data type used for events tracking\n * */\n get url(): string {\n return '';\n }\n\n /**\n * @property data - data of the current class instance\n * */\n get data(): ApplicationVersionDataType {\n return {\n version: this.version,\n type: KameleoonData.ApplicationVersion,\n sent: this.sent,\n };\n }\n\n /**\n * @property isSent - signifying if the data was sent already tracked\n * */\n get isSent(): boolean {\n return this.sent;\n }\n\n set isSent(value: boolean) {\n this.sent = value;\n }\n}\n"],"mappings":"aAAA,IAAAA,MAAA,CAAAC,OAAA,YAIiBC,MAAA,CAAAC,cAAA,CAAAC,OAAA,eAAAC,KAAA,MAAAD,OAAA,CAAAE,kBAAA,iBAAAC,gBAAAC,CAAA,CAAAC,CAAA,CAAAC,CAAA,SAAAD,CAAA,CAAAE,cAAA,CAAAF,CAAA,EAAAA,CAAA,IAAAD,CAAA,CAAAN,MAAA,CAAAC,cAAA,CAAAK,CAAA,CAAAC,CAAA,EAAAJ,KAAA,CAAAK,CAAA,CAAAE,UAAA,IAAAC,YAAA,IAAAC,QAAA,MAAAN,CAAA,CAAAC,CAAA,EAAAC,CAAA,CAAAF,CAAA,UAAAG,eAAAH,CAAA,MAAAC,CAAA,CAAAM,YAAA,CAAAP,CAAA,kCAAAC,CAAA,CAAAA,CAAA,CAAAA,CAAA,aAAAM,aAAAP,CAAA,CAAAC,CAAA,sBAAAD,CAAA,GAAAA,CAAA,QAAAA,CAAA,KAAAE,CAAA,CAAAF,CAAA,CAAAQ,MAAA,CAAAC,WAAA,cAAAP,CAAA,MAAAQ,CAAA,CAAAR,CAAA,CAAAS,IAAA,CAAAX,CAAA,CAAAC,CAAA,iCAAAS,CAAA,QAAAA,CAAA,WAAAE,SAAA,mEAAAX,CAAA,CAAAY,MAAA,CAAAC,MAAA,EAAAd,CAAA,EAMV,KAAM,CAAAF,kBAA6C,CAOxDiB,WAAWA,CAACC,CAAe,CAAE,CAAAjB,eAAA,wBAAAA,eAAA,qBAC3B,IAAI,CAACiB,OAAO,CAAGA,CAAO,CACtB,IAAI,CAACC,IAAI,GACX,CAKA,GAAI,CAAAC,GAAGA,CAAA,CAAW,CAChB,MAAO,EACT,CAKA,GAAI,CAAAC,IAAIA,CAAA,CAA+B,CACrC,MAAO,CACLH,OAAO,CAAE,IAAI,CAACA,OAAO,CACrBI,IAAI,CAAEC,oBAAa,CAACvB,kBAAkB,CACtCmB,IAAI,CAAE,IAAI,CAACA,IACb,CACF,CAKA,GAAI,CAAAK,MAAMA,CAAA,CAAY,CACpB,MAAO,KAAI,CAACL,IACd,CAEA,GAAI,CAAAK,MAAMA,CAACzB,CAAc,CAAE,CACzB,IAAI,CAACoB,IAAI,CAAGpB,CACd,CACF,CAACD,OAAA,CAAAE,kBAAA,CAAAA,kBAAA"}
1
+ {"version":3,"file":"applicationVersion.js","names":["_types","require","Object","defineProperty","exports","value","ApplicationVersion","_defineProperty","a","b","c","_toPropertyKey","enumerable","configurable","writable","_toPrimitive","Symbol","toPrimitive","d","call","TypeError","String","Number","constructor","version","sent","url","data","type","KameleoonData","isSent"],"sources":["../../src/kameleoonData/applicationVersion.ts"],"sourcesContent":["import {\n IKameleoonData,\n KameleoonData,\n ApplicationVersionDataType,\n} from './types';\n\n/**\n * @class\n * ApplicationVersion - a class for creating an instance for app version\n * */\nexport class ApplicationVersion implements IKameleoonData {\n private version: string;\n private sent: boolean;\n\n /**\n * @param {string} version - version of mobile application\n * */\n constructor(version: string) {\n this.version = version;\n this.sent = false;\n }\n\n get url(): string {\n return '';\n }\n\n get data(): ApplicationVersionDataType {\n return {\n version: this.version,\n type: KameleoonData.ApplicationVersion,\n s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Aa,CAACvB,kBAAkB,CACtCmB,IAAI,CAAE,IAAI,CAACA,IACb,CACF,CAEA,GAAI,CAAAK,MAAMA,CAAA,CAAY,CACpB,MAAO,KAAI,CAACL,IACd,CAEA,GAAI,CAAAK,MAAMA,CAACzB,CAAc,CAAE,CACzB,IAAI,CAACoB,IAAI,CAAGpB,CACd,CACF,CAACD,OAAA,CAAAE,kBAAA,CAAAA,kBAAA"}
@@ -18,24 +18,15 @@ export declare class Browser implements IKameleoonData {
18
18
  * ```
19
19
  * */
20
20
  constructor(browser: BrowserType, version?: number);
21
- /**
22
- * @property url - url for the current data type used for events tracking
23
- * */
24
21
  get url(): string;
25
- /**
26
- * @property data - data of the current class instance
27
- * */
28
22
  get data(): BrowserDataType;
29
- /**
30
- * @property isSent - signifying if the data was sent already tracked
31
- * */
32
23
  get isSent(): boolean;
33
24
  set isSent(value: boolean);
34
25
  /**
35
26
  * @private
36
- * @method _fromVisits - an internal method for creating an instance of Browser class from a list of visits
37
- * @param {VisitType[]} visits - a list of visits
27
+ * @method _fromVisit - an internal method for creating an instance of Browser class from a visit
28
+ * @param {VisitType} visit - a visit
38
29
  * @returns {Browser | undefined} an instance of Browser class or undefined if browser can not be found among visits
39
30
  * */
40
- static _fromVisits(visits: VisitType[]): Browser | undefined;
31
+ static _fromVisit(visit: VisitType): Browser | undefined;
41
32
  }
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Browser=void 0;var _requester=require("../requester"),_types=require("./types");function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class Browser{constructor(a,b){_defineProperty(this,"browser",void 0),_defineProperty(this,"version",void 0),_defineProperty(this,"sent",void 0),this.browser=a,this.version=b,this.sent=!1}get url(){if(!this.browser)return"";const a=this.version?_requester.UrlParameter.BrowserVersion+this.version:"";return _requester.UrlEventType.StaticData+_requester.UrlParameter.Browser+this.browser+_requester.UrlParameter.BrowserIndex+_types.BrowserIndexMap[this.browser]+a}get data(){return{browser:this.browser,type:_types.KameleoonData.Browser,version:this.version,sent:this.sent}}get isSent(){return this.sent}set isSent(a){this.sent=a}static _fromVisits(a){let b={};for(let c=a.length-1;0<=c;c--){const d=a[c];if(!d.staticDataEvent)continue;const{browser:e,browserIndex:f,browserVersion:g}=d.staticDataEvent.data;(e||null!==f)&&(b={browserType:e,browserIndex:f,browserVersion:g})}const{browserType:c,browserIndex:d,browserVersion:e}=b;if(c||"number"==typeof d){const a=c?c:_types.BrowserTypeMap[d];return e?new Browser(a,e):new Browser(a)}}}exports.Browser=Browser;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Browser=void 0;var _requester=require("../requester"),_types=require("./types");function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class Browser{constructor(a,b){_defineProperty(this,"browser",void 0),_defineProperty(this,"version",void 0),_defineProperty(this,"sent",void 0),this.browser=a,this.version=b,this.sent=!1}get url(){if(!this.browser)return"";const a=this.version?_requester.UrlParameter.BrowserVersion+this.version:"";return _requester.UrlEventType.StaticData+_requester.UrlParameter.Browser+this.browser+_requester.UrlParameter.BrowserIndex+_types.BrowserIndexMap[this.browser]+a}get data(){return{browser:this.browser,type:_types.KameleoonData.Browser,version:this.version,sent:this.sent}}get isSent(){return this.sent}set isSent(a){this.sent=a}static _fromVisit(a){if(a.staticDataEvent){const{browser:b,browserIndex:c,browserVersion:d}=a.staticDataEvent.data;if(b||"number"==typeof c){const a=null!==b&&void 0!==b?b:_types.BrowserTypeMap[c];return d?new Browser(a,d):new Browser(a)}}}}exports.Browser=Browser;
2
2
  //# sourceMappingURL=browser.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"browser.js","names":["Browser","constructor","browser","version","_defineProperty","sent","url","browserVersion","UrlParameter","BrowserVersion","UrlEventType","StaticData","BrowserIndex","BrowserIndexMap","data","type","KameleoonData","isSent","value","_fromVisits","visits","browserData","i","length","visit","staticDataEvent","browserType","browserIndex","BrowserTypeMap","exports"],"sources":["../../src/kameleoonData/browser.ts"],"sourcesContent":["import { UrlEventType, UrlParameter, VisitType } from 'src/requester';\nimport {\n BrowserDataType,\n BrowserType,\n BrowserIndexMap,\n IKameleoonData,\n KameleoonData,\n BrowserTypeMap,\n} from './types';\n\n/**\n * @class\n * Browser - a class for creating an instance for browser of a certain type\n * */\nexport class Browser implements IKameleoonData {\n private browser: BrowserType;\n private version?: number;\n private sent: boolean;\n\n /**\n * @param {BrowserType} browser - one of the browser types available for data, if browser can not be found in a list, it can be marked as `BrowserType.Other`\n * @param {number | undefined} version - version of the browser, floating point number represents major and minor version of the browser\n * @example\n * ```ts\n * const browser = new Browser(BrowserType.Chrome, 86);\n * const browser = new Browser(BrowserType.Safari, 14.1);\n * ```\n * */\n constructor(browser: BrowserType, version?: number) {\n this.browser = browser;\n this.version = version;\n this.sent = false;\n }\n\n /**\n * @property url - url for the current data type used for events tracking\n * */\n get url(): string {\n // --- Note ---\n // If SDK is used in vanilla JS codebase, then you're also able to create an instance\n // with no required data, we don't want send anything to tracking in that case\n if (!this.browser) {\n return '';\n }\n\n const browserVersion = this.version\n ? UrlParameter.BrowserVersion + this.version\n : '';\n\n return (\n UrlEventType.StaticData +\n UrlParameter.Browser +\n this.browser +\n UrlParameter.BrowserIndex +\n BrowserIndexMap[this.browser] +\n browserVersion\n );\n }\n\n /**\n * @property data - data of the current class instance\n * */\n get data(): BrowserDataType {\n return {\n browser: this.browser,\n type: KameleoonData.Browser,\n version: this.version,\n sent: this.sent,\n };\n }\n\n /**\n * @property isSent - signifying if the data was sent already tracked\n * */\n get isSent(): boolean {\n return this.sent;\n }\n\n set isSent(value: boolean) {\n this.sent = value;\n }\n\n /**\n * @private\n * @method _fromVisits - an internal method for creating an instance of Browser class from a list of visits\n * @param {VisitType[]} visits - a list of visits\n * @returns {Browser | undefined} an instance of Browser class or undefined if browser can not be found among visits\n * */\n public static _fromVisits(visits: VisitType[]): Browser | undefined {\n let browserData: {\n browserType?: BrowserType | null;\n browserIndex?: number | null;\n browserVersion?: number | null;\n } = {};\n\n // --- Note ---\n // Going backwards to get the latest visit data\n for (let i = visits.length - 1; i >= 0; i--) {\n const visit = visits[i];\n if (!visit.staticDataEvent) {\n continue;\n }\n\n const {\n browser: browserType,\n browserIndex,\n browserVersion,\n } = visit.staticDataEvent.data;\n\n if (browserType || browserIndex !== null) {\n browserData = { browserType, browserIndex, browserVersion };\n }\n }\n\n const { browserType, browserIndex, browserVersion } = browserData;\n\n if (browserType || typeof browserIndex === 'number') {\n const browser = browserType\n ? browserType\n : BrowserTypeMap[browserIndex as number];\n\n if (browserVersion) {\n return new Browser(browser, browserVersion);\n } else {\n return new Browser(browser);\n }\n }\n }\n}\n"],"mappings":"+pBAcO,KAAM,CAAAA,OAAkC,CAc7CC,WAAWA,CAACC,CAAoB,CAAEC,CAAgB,CAAE,CAAAC,eAAA,wBAAAA,eAAA,wBAAAA,eAAA,qBAClD,IAAI,CAACF,OAAO,CAAGA,CAAO,CACtB,IAAI,CAACC,OAAO,CAAGA,CAAO,CACtB,IAAI,CAACE,IAAI,GACX,CAKA,GAAI,CAAAC,GAAGA,CAAA,CAAW,CAIhB,GAAI,CAAC,IA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Y,CAAZA,CAAY,CAAEpB,cAAc,CAAdA,CAAe,CAAC,CAE/D,CAEA,KAAM,CAAEmB,WAAW,CAAXA,CAAW,CAAEC,YAAY,CAAZA,CAAY,CAAEpB,cAAc,CAAdA,CAAe,CAAC,CAAGc,CAAW,CAEjE,GAAIK,CAAW,EAA4B,QAAQ,EAAhC,MAAO,CAAAC,CAAyB,CAAE,CACnD,KAAM,CAAAzB,CAAO,CAAGwB,CAAW,CACvBA,CAAW,CACXE,qBAAc,CAACD,CAAY,CAAW,CAAC,MAEvC,CAAApB,CAAc,CACT,GAAI,CAAAP,OAAO,CAACE,CAAO,CAAEK,CAAc,CAAC,CAEpC,GAAI,CAAAP,OAAO,CAACE,CAAO,CAE9B,CACF,CACF,CAAC2B,OAAA,CAAA7B,OAAA,CAAAA,OAAA"}
1
+ {"version":3,"file":"browser.js","names":["Browser","constructor","browser","version","_defineProperty","sent","url","browserVersion","UrlParameter","BrowserVersion","UrlEventType","StaticData","BrowserIndex","BrowserIndexMap","data","type","KameleoonData","isSent","value","_fromVisit","visit","staticDataEvent","browserType","browserIndex","BrowserTypeMap","exports"],"sources":["../../src/kameleoonData/browser.ts"],"sourcesContent":["import { UrlEventType, UrlParameter, VisitType } from 'src/requester';\nimport {\n BrowserDataType,\n BrowserType,\n BrowserIndexMap,\n IKameleoonData,\n KameleoonData,\n BrowserTypeMap,\n} from './types';\n\n/**\n * @class\n * Browser - a class for creating an instance for browser of a certain type\n * */\nexport class Browser implements IKameleoonData {\n private browser: BrowserType;\n private version?: number;\n private sent: boolean;\n\n /**\n * @param {BrowserType} browser - one of the browser types available for data, if browser can not be found in a list, it can be marked as `BrowserType.Other`\n * @param {number | undefined} version - version of the browser, floating point number represents major and minor version of the browser\n * @example\n * ```ts\n * const browser = new Browser(BrowserType.Chrome, 86);\n * const browser = new Browser(BrowserType.Safari, 14.1);\n * ```\n * */\n constructor(browser: BrowserType, version?: number) {\n this.browser = browser;\n this.version = version;\n this.sent = false;\n }\n\n get url(): string {\n // --- Note ---\n // If SDK is used in vanilla JS codebase, then you're also able to create an instance\n // with no required data, we don't want send anything to tracking in that case\n if (!this.browser) {\n return '';\n }\n\n const browserVersion = this.version\n ? UrlParameter.BrowserVersion + this.version\n : '';\n\n return (\n UrlEventType.StaticData +\n UrlParameter.Browser +\n this.browser +\n UrlParameter.BrowserIndex +\n BrowserIndexMap[this.browser] +\n browserVersion\n );\n }\n\n get data(): BrowserDataType {\n return {\n browser: this.browser,\n type: KameleoonData.Browser,\n version: this.version,\n sent: this.sent,\n };\n }\n\n get isSent(): boolean {\n return this.sent;\n }\n\n set isSent(value: boolean) {\n this.sent = value;\n }\n\n /**\n * @private\n * @method _fromVisit - an internal method for creating an instance of Browser class from a visit\n * @param {VisitType} visit - a visit\n * @returns {Browser | undefined} an instance of Browser class or undefined if browser can not be found among visits\n * */\n public static _fromVisit(visit: VisitType): Browser | undefined {\n if (!visit.staticDataEvent) {\n return undefined;\n }\n\n const {\n browser: browserType,\n browserIndex,\n browserVersion,\n } = visit.staticDataEvent.data;\n\n if (browserType || typeof browserIndex === 'number') {\n const browser = browserType ?? BrowserTypeMap[browserIndex as number];\n\n if (browserVersion) {\n return new Browser(browser, browserVersion);\n } else {\n return new Browser(browser);\n }\n }\n\n return undefined;\n }\n}\n"],"mappings":"+pBAcO,KAAM,CAAAA,OAAkC,CAc7CC,WAAWA,CAACC,CAAoB,CAAEC,CAAgB,CAAE,CAAAC,eAAA,wBAAAA,eAAA,wBAAAA,eAAA,qBAClD,IAAI,CAACF,OAAO,CAAGA,CAAO,CACtB,IAAI,CAACC,OAAO,CAAGA,CAAO,CACtB,IAAI,CAACE,IAAI,GACX,CAEA,GAAI,CAAAC,GAAGA,CAAA,CAAW,CAIhB,GAAI,CAAC,IAAI,CAACJ,OAAO,CACf,MAAO,EAAE,CAGX,KAAM,CAAAK,CAAc,CAAG,IAAI,CAACJ,OAAO,CAC/BK,uBAAY,CAACC,cAAc,CAAG,IAAI,CAACN,OAAO,CAC1C,EAAE,CAEN,MACE,CAAAO,uBAAY,CAACC,UAAU,CACvBH,uBAAY,CAACR,OAAO,CACpB,IAAI,CAACE,OAAO,CACZM,uBAAY,CAACI,YAAY,CACzBC,sBAAe,CAAC,IAAI,CAACX,OAAO,CAAC,CAC7BK,CAEJ,CAEA,GAAI,CAAAO,IAAIA,CAAA,CAAoB,CAC1B,MAAO,CACLZ,OAAO,CAAE,IAAI,CAACA,OAAO,CACrBa,IAAI,CAAEC,oBAAa,CAAChB,OAAO,CAC3BG,OAAO,CAAE,IAAI,CAACA,OAAO,CACrBE,IAAI,CAAE,IAAI,CAACA,IACb,CACF,CAEA,GAAI,CAAAY,MAAMA,CAAA,CAAY,CACpB,MAAO,KAAI,CAACZ,IACd,CAEA,GAAI,CAAAY,MAAMA,CAACC,CAAc,CAAE,CACzB,IAAI,CAACb,IAAI,CAAGa,CACd,CAQA,MAAc,CAAAC,UAAUA,CAACC,CAAgB,CAAuB,CAC9D,GAAKA,CAAK,CAACC,eAAe,EAI1B,KAAM,CACJnB,OAAO,CAAEoB,CAAW,CACpBC,YAAY,CAAZA,CAAY,CACZhB,cAAc,CAAdA,CACF,CAAC,CAAGa,CAAK,CAACC,eAAe,CAACP,IAAI,CAE9B,GAAIQ,CAAW,EAA4B,QAAQ,EAAhC,MAAO,CAAAC,CAAyB,CAAE,CACnD,KAAM,CAAArB,CAAO,QAAGoB,CAAW,WAAXA,CAAW,CAAXA,CAAW,CAAIE,qBAAc,CAACD,CAAY,CAAW,CAAC,MAElE,CAAAhB,CAAc,CACT,GAAI,CAAAP,OAAO,CAACE,CAAO,CAAEK,CAAc,CAAC,CAEpC,GAAI,CAAAP,OAAO,CAACE,CAAO,CAE9B,CAAC,CAGH,CACF,CAACuB,OAAA,CAAAzB,OAAA,CAAAA,OAAA"}
@@ -14,24 +14,22 @@ export declare class Conversion implements IKameleoonData {
14
14
  * @param {ConversionParametersType} conversionParameters - an object with conversion parameters
15
15
  * */
16
16
  constructor({ goalId, revenue, negative, }: ConversionParametersType);
17
- /**
18
- * @property url - url for the current data type used for events tracking
19
- * */
20
17
  get url(): string;
21
- /**
22
- * @property data - data of the current class instance
23
- * */
24
18
  get data(): ConversionDataType;
25
- /**
26
- * @property isSent - signifying if the data was sent already tracked
27
- * */
28
19
  get isSent(): boolean;
29
20
  set isSent(value: boolean);
30
21
  /**
31
22
  * @private
32
- * @method _listFromVisits - an internal method for creating a list of Conversion instances
33
- * @param {VisitType[]} visits - a list of visits
34
- * @returns {Conversion[]} a list of Conversion instances
23
+ * @method _listFromVisit - an internal method for returning a list of all Conversion instances
24
+ * @param {VisitType} visit - a visits
25
+ * @return {Conversion[]} - a list of Conversion instances
26
+ * */
27
+ static _listFromVisit(visit: VisitType): Conversion[];
28
+ /**
29
+ * @private
30
+ * @method _updateFromVisit - an internal method for updating a list of Conversion instances with only goalId
31
+ * @param {VisitType} visit - a visits
32
+ * @param {Map<number, Conversion>} dataMap - a map of Conversion instances
35
33
  * */
36
- static _listFromVisits(visits: VisitType[]): Conversion[];
34
+ static _updateFromVisit(visit: VisitType, dataMap: Map<number, Conversion>): void;
37
35
  }
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Conversion=void 0;var _requester=require("../requester"),_utilities=require("../utilities"),_types=require("./types");function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class Conversion{constructor(a){let{goalId:b,revenue:c=0,negative:d=!1}=a;_defineProperty(this,"goalId",void 0),_defineProperty(this,"revenue",void 0),_defineProperty(this,"negative",void 0),_defineProperty(this,"sent",void 0),_defineProperty(this,"nonce",void 0),this.goalId=b,this.revenue=c,this.negative=d,this.sent=!1,this.nonce=_utilities.Utilities.getNonce()}get url(){return this.goalId?_requester.UrlEventType.Conversion+_requester.UrlParameter.GoalId+(this.goalId+"")+_requester.UrlParameter.Revenue+(this.revenue+"")+_requester.UrlParameter.Negative+(this.negative+"")+_requester.UrlParameter.Nonce+this.nonce:""}get data(){return{goalId:this.goalId,revenue:this.revenue,negative:this.negative,type:_types.KameleoonData.Conversion,sent:this.sent}}get isSent(){return this.sent}set isSent(a){this.sent=a}static _listFromVisits(a){const b=[],c=new Map;for(const d of a){if(!d.conversionEvents)continue;const a=d.conversionEvents;for(const d of a){const{goalId:a}=d.data;if(!c.has(a)){c.set(a,!0);const d=new Conversion({goalId:a});d.isSent=!0,b.push(d)}}}return b}}exports.Conversion=Conversion;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Conversion=void 0;var _requester=require("../requester"),_utilities=require("../utilities"),_types=require("./types");function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class Conversion{constructor(a){let{goalId:b,revenue:c=0,negative:d=!1}=a;_defineProperty(this,"goalId",void 0),_defineProperty(this,"revenue",void 0),_defineProperty(this,"negative",void 0),_defineProperty(this,"sent",void 0),_defineProperty(this,"nonce",void 0),this.goalId=b,this.revenue=c,this.negative=d,this.sent=!1,this.nonce=_utilities.Utilities.getNonce()}get url(){return this.goalId?_requester.UrlEventType.Conversion+_requester.UrlParameter.GoalId+(this.goalId+"")+_requester.UrlParameter.Revenue+(this.revenue+"")+_requester.UrlParameter.Negative+(this.negative+"")+_requester.UrlParameter.Nonce+this.nonce:""}get data(){return{goalId:this.goalId,revenue:this.revenue,negative:this.negative,type:_types.KameleoonData.Conversion,sent:this.sent}}get isSent(){return this.sent}set isSent(a){this.sent=a}static _listFromVisit(a){var b,c;const d=[];if(!(null!==(b=a.conversionEvents)&&void 0!==b&&b.length))return[];if(null!==(c=a.conversionEvents)&&void 0!==c&&c.length)for(const b of a.conversionEvents){const{goalId:a,revenue:c,negative:e}=b.data,f=new Conversion({goalId:a,revenue:c,negative:e});f.isSent=!0,d.push(f)}return d}static _updateFromVisit(a,b){var c;if(null!==(c=a.conversionEvents)&&void 0!==c&&c.length)for(const c of a.conversionEvents){const{goalId:a}=c.data;if(!b.has(a)){const c=new Conversion({goalId:a});c.isSent=!0,b.set(a,c)}}}}exports.Conversion=Conversion;
2
2
  //# sourceMappingURL=conversion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"conversion.js","names":["Conversion","constructor","a","goalId","revenue","negative","_defineProperty","sent","nonce","Utilities","getNonce","url","UrlEventType","UrlParameter","GoalId","Revenue","Negative","Nonce","data","type","KameleoonData","isSent","value","_listFromVisits","visits","resultConversions","goalIdMap","Map","visit","conversionEvents","conversionEvent","has","set","conversion","push","exports"],"sources":["../../src/kameleoonData/conversion.ts"],"sourcesContent":["import { UrlEventType, UrlParameter, VisitType } from 'src/requester';\nimport { Utilities } from 'src/utilities';\nimport {\n ConversionDataType,\n ConversionParametersType,\n IKameleoonData,\n KameleoonData,\n} from './types';\n\n/**\n * @class\n * Conversion - a class for creating an instance for conversion tracking\n * */\nexport class Conversion implements IKameleoonData {\n private goalId: number;\n private revenue: number;\n private negative: boolean;\n private sent: boolean;\n private nonce: string;\n\n /**\n * @param {ConversionParametersType} conversionParameters - an object with conversion parameters\n * */\n constructor({\n goalId,\n revenue = 0,\n negative = false,\n }: ConversionParametersType) {\n this.goalId = goalId;\n this.revenue = revenue;\n this.negative = negative;\n this.sent = false;\n this.nonce = Utilities.getNonce();\n }\n\n /**\n * @property url - url for the current data type used for events tracking\n * */\n get url(): string {\n // --- Note ---\n // If SDK is used in vanilla JS codebase, then you're also able to create an instance\n // with no required data, we don't want send anything to tracking in that case\n if (!this.goalId) {\n return '';\n }\n\n return (\n UrlEventType.Conversion +\n UrlParameter.GoalId +\n String(this.goalId) +\n UrlParameter.Revenue +\n String(this.revenue) +\n UrlParameter.Negative +\n String(this.negative) +\n UrlParameter.Nonce +\n this.nonce\n );\n }\n\n /**\n * @property data - data of the current class instance\n * */\n get data(): ConversionDataType {\n return {\n goalId: this.goalId,\n revenue: this.revenue,\n negative: this.negative,\n type: KameleoonData.Conversion,\n sent: this.sent,\n };\n }\n\n /**\n * @property isSent - signifying if the data was sent already tracked\n * */\n get isSent(): boolean {\n return this.sent;\n }\n\n set isSent(value: boolean) {\n this.sent = value;\n }\n\n /**\n * @private\n * @method _listFromVisits - an internal method for creating a list of Conversion instances\n * @param {VisitType[]} visits - a list of visits\n * @returns {Conversion[]} a list of Conversion instances\n * */\n public static _listFromVisits(visits: VisitType[]): Conversion[] {\n const resultConversions: Conversion[] = [];\n const goalIdMap = new Map();\n\n for (const visit of visits) {\n if (!visit.conversionEvents) {\n continue;\n }\n\n const conversionEvents = visit.conversionEvents;\n\n for (const conversionEvent of conversionEvents) {\n const { goalId } = conversionEvent.data;\n\n // --- Note ---\n // - We only take unique `goalId`s as and don't use `revenue` and `negative`\n // because we only utilize it for Conversion Condition and don't re-sent this data tracking\n // not to break server `revenue` calculations and not to cause extra conversions\n // - Moreover conversion is marked as sent, so the visitor won't be converted again just\n // by pulling visits data\n if (!goalIdMap.has(goalId)) {\n goalIdMap.set(goalId, true);\n\n const conversion = new Conversion({ goalId });\n conversion.isSent = true;\n\n resultConversions.push(conversion);\n }\n }\n }\n\n return resultConversions;\n }\n}\n"],"mappings":"qsBAaO,KAAM,CAAAA,UAAqC,CAUhDC,WAAWA,CAAAC,CAAA,CAIkB,IAJjB,CACVC,MAAM,CAANA,CAA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AAAC,CAAK,GAAI,CAAAJ,CAAM,CAAE,CAC1B,GAAI,CAACI,CAAK,CAACC,gBAAgB,CACzB,SAGF,KAAM,CAAAA,CAAgB,CAAGD,CAAK,CAACC,gBAAgB,CAE/C,IAAK,KAAM,CAAAC,CAAe,GAAI,CAAAD,CAAgB,CAAE,CAC9C,KAAM,CAAE1B,MAAM,CAANA,CAAO,CAAC,CAAG2B,CAAe,CAACZ,IAAI,CAQvC,GAAI,CAACQ,CAAS,CAACK,GAAG,CAAC5B,CAAM,CAAC,CAAE,CAC1BuB,CAAS,CAACM,GAAG,CAAC7B,CAAM,GAAM,CAAC,CAE3B,KAAM,CAAA8B,CAAU,CAAG,GAAI,CAAAjC,UAAU,CAAC,CAAEG,MAAM,CAANA,CAAO,CAAC,CAAC,CAC7C8B,CAAU,CAACZ,MAAM,GAAO,CAExBI,CAAiB,CAACS,IAAI,CAACD,CAAU,CACnC,CACF,CACF,CAEA,MAAO,CAAAR,CACT,CACF,CAACU,OAAA,CAAAnC,UAAA,CAAAA,UAAA"}
1
+ {"version":3,"file":"conversion.js","names":["Conversion","constructor","a","goalId","revenue","negative","_defineProperty","sent","nonce","Utilities","getNonce","url","UrlEventType","UrlParameter","GoalId","Revenue","Negative","Nonce","data","type","KameleoonData","isSent","value","_listFromVisit","visit","b","c","conversions","conversionEvents","length","conversionEvent","conversion","push","_updateFromVisit","dataMap","has","set","exports"],"sources":["../../src/kameleoonData/conversion.ts"],"sourcesContent":["import { UrlEventType, UrlParameter, VisitType } from 'src/requester';\nimport { Utilities } from 'src/utilities';\nimport {\n ConversionDataType,\n ConversionParametersType,\n IKameleoonData,\n KameleoonData,\n} from './types';\n\n/**\n * @class\n * Conversion - a class for creating an instance for conversion tracking\n * */\nexport class Conversion implements IKameleoonData {\n private goalId: number;\n private revenue: number;\n private negative: boolean;\n private sent: boolean;\n private nonce: string;\n\n /**\n * @param {ConversionParametersType} conversionParameters - an object with conversion parameters\n * */\n constructor({\n goalId,\n revenue = 0,\n negative = false,\n }: ConversionParametersType) {\n this.goalId = goalId;\n this.revenue = revenue;\n this.negative = negative;\n this.sent = false;\n this.nonce = Utilities.getNonce();\n }\n\n get url(): string {\n // --- Note ---\n // If SDK is used in vanilla JS codebase, then you're also able to create an instance\n // with no required data, we don't want send anything to tracking in that case\n if (!this.goalId) {\n return '';\n }\n\n return (\n UrlEventType.Conversion +\n UrlParameter.GoalId +\n String(this.goalId) +\n UrlParameter.Revenue +\n String(this.revenue) +\n UrlParameter.Negative +\n String(this.negative) +\n UrlParameter.Nonce +\n this.nonce\n );\n }\n\n get data(): ConversionDataType {\n return {\n goalId: this.goalId,\n revenue: this.revenue,\n negative: this.negative,\n type: KameleoonData.Conversion,\n sent: this.sent,\n };\n }\n\n get isSent(): boolean {\n return this.sent;\n }\n\n set isSent(value: boolean) {\n this.sent = value;\n }\n\n /**\n * @private\n * @method _listFromVisit - an internal method for returning a list of all Conversion instances\n * @param {VisitType} visit - a visits\n * @return {Conversion[]} - a list of Conversion instances\n * */\n public static _listFromVisit(visit: VisitType): Conversion[] {\n const conversions: Conversion[] = [];\n\n if (!visit.conversionEvents?.length) {\n return [];\n }\n\n if (visit.conversionEvents?.length) {\n for (const conversionEvent of visit.conversionEvents) {\n const { goalId, revenue, negative } = conversionEvent.data;\n const conversion = new Conversion({ goalId, revenue, negative });\n\n // --- Note ---\n // Conversion is marked as sent, so the visitor won't be converted again just\n // by pulling visits data\n conversion.isSent = true;\n conversions.push(conversion);\n }\n }\n\n return conversions;\n }\n\n /**\n * @private\n * @method _updateFromVisit - an internal method for updating a list of Conversion instances with only goalId\n * @param {VisitType} visit - a visits\n * @param {Map<number, Conversion>} dataMap - a map of Conversion instances\n * */\n public static _updateFromVisit(\n visit: VisitType,\n dataMap: Map<number, Conversion>,\n ): void {\n if (visit.conversionEvents?.length) {\n for (const conversionEvent of visit.conversionEvents) {\n const { goalId } = conversionEvent.data;\n\n // --- Note ---\n // - We only take unique `goalId`s as and don't use `revenue` and `negative`\n // because we only utilize it for Conversion Condition and don't re-sent this data tracking\n // not to break server `revenue` calculations and not to cause extra conversions\n // - Moreover conversion is marked as sent, so the visitor won't be converted again just\n // by pulling visits data\n if (!dataMap.has(goalId)) {\n const conversion = new Conversion({ goalId });\n\n conversion.isSent = true;\n dataMap.set(goalId, conversion);\n }\n }\n }\n }\n}\n"],"mappings":"qsBAaO,KAAM,CAAAA,UAAqC,CAUhDC,WAAWA,CAAAC,CAAA,CAIkB,IAJjB,CACVC,MAAM,CAANA,CAAM,CACNC,OAAO,CAAPA,CAAO,CAAG,CAAC,CACXC,QAAQ,CAARA,CAAQ,GACgB,CAAC,CAAAH,CAAA,CAAAI,eAAA,uBAAAA,eAAA,wBAAAA,eAAA,yBAAAA,eAAA,qBAAAA,eAAA,sBACzB,IAAI,CAACH,MAAM,CAAGA,CAAM,CACpB,IAAI,CAACC,OAAO,CAAGA,CAAO,CACtB,IAAI,CAACC,QAAQ,CAAGA,CAAQ,CACxB,IAAI,CAACE,IAAI,GAAQ,CACjB,IAAI,CAACC,KAAK,CAAGC,oBAAS,CAACC,QAAQ,CAAC,CAClC,CAEA,GAAI,CAAAC,GAAGA,CAAA,CAAW,OAIX,KAAI,CAACR,MAAM,CAKdS,uBAAY,CAACZ,UAAU,CACvBa,uBAAY,CAACC,MAAM,EACZ,IAAI,CAACX,MAAM,IAAC,CACnBU,uBAAY,CAACE,OAAO,EACb,IAAI,CAACX,OAAO,IAAC,CACpBS,uBAAY,CAACG,QAAQ,EACd,IAAI,CAACX,QAAQ,IAAC,CACrBQ,uBAAY,CAACI,KAAK,CAClB,IAAI,CAACT,KAAK,CAZH,EAcX,CAEA,GAAI,CAAAU,IAAIA,CAAA,CAAuB,CAC7B,MAAO,CACLf,MAAM,CAAE,IAAI,CAACA,MAAM,CACnBC,OAAO,CAAE,IAAI,CAACA,OAAO,CACrBC,QAAQ,CAAE,IAAI,CAACA,QAAQ,CACvBc,IAAI,CAAEC,oBAAa,CAACpB,UAAU,CAC9BO,IAAI,CAAE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C,GAAI,CAACgB,CAAO,CAACC,GAAG,CAAChC,CAAM,CAAC,CAAE,CACxB,KAAM,CAAA4B,CAAU,CAAG,GAAI,CAAA/B,UAAU,CAAC,CAAEG,MAAM,CAANA,CAAO,CAAC,CAAC,CAE7C4B,CAAU,CAACV,MAAM,GAAO,CACxBa,CAAO,CAACE,GAAG,CAACjC,CAAM,CAAE4B,CAAU,CAChC,CACF,CAEJ,CACF,CAACM,OAAA,CAAArC,UAAA,CAAAA,UAAA"}
@@ -17,17 +17,8 @@ export declare class Cookie implements IKameleoonData {
17
17
  * @returns {Cookie} an instance of `Cookie`
18
18
  * */
19
19
  static fromString(cookieString: string): Cookie;
20
- /**
21
- * @property url - url for the current data type used for events tracking
22
- * */
23
20
  get url(): string;
24
- /**
25
- * @property data - data of the current class instance
26
- * */
27
21
  get data(): CookieDataType;
28
- /**
29
- * @property isSent - signifying if the data was sent already tracked
30
- * */
31
22
  get isSent(): boolean;
32
23
  set isSent(value: boolean);
33
24
  }
@@ -1 +1 @@
1
- {"version":3,"file":"cookie.js","names":["Cookie","constructor","cookie","_defineProperty","sent","fromString","cookieString","KameleoonError","KameleoonException","CookieParse","pairs","split","map","item","key","value","trim","url","data","type","KameleoonData","isSent","exports"],"sources":["../../src/kameleoonData/cookie.ts"],"sourcesContent":["import { KameleoonError, KameleoonException } from 'src/kameleoonError';\nimport {\n CookieDataType,\n CookieType,\n IKameleoonData,\n KameleoonData,\n} from './types';\n\n/**\n * @class\n * Cookie - a class for creating an instance for defining user's cookie\n * */\nexport class Cookie implements IKameleoonData {\n private cookie: CookieType[];\n private sent: boolean;\n\n /**\n * @param {CookieType[]} cookie - a list of cookies\n * */\n constructor(cookie: CookieType[]) {\n this.cookie = cookie;\n this.sent = false;\n }\n\n /**\n * @method fromString - a static method for creating an instance of `Cookie` from a string\n * @param {string} cookieString - a string containing a list of cookies\n * @throws {KameleoonError} throws an error if the string is not valid cookie\n * @returns {Cookie} an instance of `Cookie`\n * */\n static fromString(cookieString: string): Cookie {\n if (!cookieString) {\n throw new KameleoonError(\n KameleoonException.CookieParse,\n \"Cookie string can't be empty\",\n );\n }\n\n const pairs = cookieString.split(';');\n\n const cookie = pairs.map((item) => {\n const [key, value] = item.trim().split('=');\n\n if (!key || !value) {\n throw new KameleoonError(\n KameleoonException.CookieParse,\n 'Cookie string is not valid',\n );\n }\n\n return { key, value };\n });\n\n return new Cookie(cookie);\n }\n\n /**\n * @property url - url for the current data type used for events tracking\n * */\n get url(): string {\n return '';\n }\n\n /**\n * @property data - data of the current class instance\n * */\n get data(): CookieDataType {\n return {\n cookie: this.cookie,\n type: KameleoonData.Cookie,\n sent: this.sent,\n };\n }\n\n /**\n * @property isSent - signifying if the data was sent already tracked\n * */\n get isSent(): boolean {\n return this.sent;\n }\n\n set isSent(value: boolean) {\n this.sent = value;\n }\n}\n"],"mappings":"wqBAYO,KAAM,CAAAA,MAAiC,CAO5CC,WAAWA,CAACC,CAAoB,CAAE,CAAAC,eAAA,uBAAAA,eAAA,qBAChC,IAAI,CAACD,MAAM,CAAGA,CAAM,CACpB,IAAI,CAACE,IAAI,GACX,CAQA,MAAO,CAAAC,UAAUA,CAACC,CAAoB,CAAU,CAC9C,GAAI,CAACA,CAAY,CACf,KAAM,IAAI,CAAAC,8BAAc,CACtBC,kCAAkB,CAACC,WAAW,CAC9B,8BACF,CAAC,CACF,KAEK,CAAAC,CAAK,CAAGJ,CAAY,CAACK,KAAK,CAAC,GAAG,CAAC,CAE/BT,CAAM,CAAGQ,CAAK,CAACE,GAAG,CAAEC,CAAI,EAAK,CACjC,KAAM,CAACC,CAAG,CAAEC,CAAK,CAAC,CAAGF,CAAI,CAACG,IAAI,CAAC,CAAC,CAACL,KAAK,CAAC,GAAG,CAAC,CAE3C,GAAI,CAACG,CAAG,EAAI,CAACC,CAAK,CAChB,KAAM,IAAI,CAAAR,8BAAc,CACtBC,kCAAkB,CAACC,WAAW,CAC9B,4BACF,CAAC,CAGH,MAAO,CAAEK,GAAG,CAAHA,CAAG,CAAEC,KAAK,CAALA,CAAM,CACtB,CAAC,CAAC,CAEF,MAAO,IAAI,CAAAf,MAAM,CAACE,CAAM,CAC1B,CAKA,GAAI,CAAAe,GAAGA,CAAA,CAAW,CAChB,MAAO,EACT,CAKA,GAAI,CAAAC,IAAIA,CAAA,CAAmB,CACzB,MAAO,CACLhB,MAAM,CAAE,IAAI,CAACA,MAAM,CACnBiB,IAAI,CAAEC,oBAAa,CAACpB,MAAM,CAC1BI,IAAI,CAAE,IAAI,CAACA,IACb,CACF,CAKA,GAAI,CAAAiB,MAAMA,CAAA,CAAY,CACpB,MAAO,KAAI,CAACjB,IACd,CAEA,GAAI,CAAAiB,MAAMA,CAACN,CAAc,CAAE,CACzB,IAAI,CAACX,IAAI,CAAGW,CACd,CACF,CAACO,OAAA,CAAAtB,MAAA,CAAAA,MAAA"}
1
+ {"version":3,"file":"cookie.js","names":["Cookie","constructor","cookie","_defineProperty","sent","fromString","cookieString","KameleoonError","KameleoonException","CookieParse","pairs","split","map","item","key","value","trim","url","data","type","KameleoonData","isSent","exports"],"sources":["../../src/kameleoonData/cookie.ts"],"sourcesContent":["import { KameleoonError, KameleoonException } from 'src/kameleoonError';\nimport {\n CookieDataType,\n CookieType,\n IKameleoonData,\n KameleoonData,\n} from './types';\n\n/**\n * @class\n * Cookie - a class for creating an instance for defining user's cookie\n * */\nexport class Cookie implements IKameleoonData {\n private cookie: CookieType[];\n private sent: boolean;\n\n /**\n * @param {CookieType[]} cookie - a list of cookies\n * */\n constructor(cookie: CookieType[]) {\n this.cookie = cookie;\n this.sent = false;\n }\n\n /**\n * @method fromString - a static method for creating an instance of `Cookie` from a string\n * @param {string} cookieString - a string containing a list of cookies\n * @throws {KameleoonError} throws an error if the string is not valid cookie\n * @returns {Cookie} an instance of `Cookie`\n * */\n static fromString(cookieString: string): Cookie {\n if (!cookieString) {\n throw new KameleoonError(\n KameleoonException.CookieParse,\n \"Cookie string can't be empty\",\n );\n }\n\n const pairs = cookieString.split(';');\n\n const cookie = pairs.map((item) => {\n const [key, value] = item.trim().split('=');\n\n if (!key || !value) {\n throw new KameleoonError(\n KameleoonException.CookieParse,\n 'Cookie string is not valid',\n );\n }\n\n return { key, value };\n });\n\n return new Cookie(cookie);\n }\n\n get url(): string {\n return '';\n }\n\n get data(): CookieDataType {\n return {\n cookie: this.cookie,\n type: KameleoonData.Cookie,\n sent: this.sent,\n };\n }\n\n get isSent(): boolean {\n return this.sent;\n }\n\n set isSent(value: boolean) {\n this.sent = value;\n }\n}\n"],"mappings":"wqBAYO,KAAM,CAAAA,MAAiC,CAO5CC,WAAWA,CAACC,CAAoB,CAAE,CAAAC,eAAA,uBAAAA,eAAA,qBAChC,IAAI,CAACD,MAAM,CAAGA,CAAM,CACpB,IAAI,CAACE,IAAI,GACX,CAQA,MAAO,CAAAC,UAAUA,CAACC,CAAoB,CAAU,CAC9C,GAAI,CAACA,CAAY,CACf,KAAM,IAAI,CAAAC,8BAAc,CACtBC,kCAAkB,CAACC,WAAW,CAC9B,8BACF,CAAC,CACF,KAEK,CAAAC,CAAK,CAAGJ,CAAY,CAACK,KAAK,CAAC,GAAG,CAAC,CAE/BT,CAAM,CAAGQ,CAAK,CAACE,GAAG,CAAEC,CAAI,EAAK,CACjC,KAAM,CAACC,CAAG,CAAEC,CAAK,CAAC,CAAGF,CAAI,CAACG,IAAI,CAAC,CAAC,CAACL,KAAK,CAAC,GAAG,CAAC,CAE3C,GAAI,CAACG,CAAG,EAAI,CAACC,CAAK,CAChB,KAAM,IAAI,CAAAR,8BAAc,CACtBC,kCAAkB,CAACC,WAAW,CAC9B,4BACF,CAAC,CAGH,MAAO,CAAEK,GAAG,CAAHA,CAAG,CAAEC,KAAK,CAALA,CAAM,CACtB,CAAC,CAAC,CAEF,MAAO,IAAI,CAAAf,MAAM,CAACE,CAAM,CAC1B,CAEA,GAAI,CAAAe,GAAGA,CAAA,CAAW,CAChB,MAAO,EACT,CAEA,GAAI,CAAAC,IAAIA,CAAA,CAAmB,CACzB,MAAO,CACLhB,MAAM,CAAE,IAAI,CAACA,MAAM,CACnBiB,IAAI,CAAEC,oBAAa,CAACpB,MAAM,CAC1BI,IAAI,CAAE,IAAI,CAACA,IACb,CACF,CAEA,GAAI,CAAAiB,MAAMA,CAAA,CAAY,CACpB,MAAO,KAAI,CAACjB,IACd,CAEA,GAAI,CAAAiB,MAAMA,CAACN,CAAc,CAAE,CACzB,IAAI,CAACX,IAAI,CAAGW,CACd,CACF,CAACO,OAAA,CAAAtB,MAAA,CAAAA,MAAA"}
@@ -24,17 +24,8 @@ export declare class CustomData implements IKameleoonData {
24
24
  * ```
25
25
  * */
26
26
  constructor(index: number, ...value: string[]);
27
- /**
28
- * @property url - url for the current data type used for events tracking
29
- * */
30
27
  get url(): string;
31
- /**
32
- * @property data - data of the current class instance
33
- * */
34
28
  get data(): CustomDataType;
35
- /**
36
- * @property isSent - signifying if the data was sent already tracked
37
- * */
38
29
  get isSent(): boolean;
39
30
  set isSent(value: boolean);
40
31
  /**
@@ -44,9 +35,8 @@ export declare class CustomData implements IKameleoonData {
44
35
  set _isMappingIdentifier(value: boolean);
45
36
  /**
46
37
  * @private
47
- * @method _listFromVisits - an internal method for creating a list of custom data from a list of visits
48
- * @param {VisitType[]} visits - a list of visits
49
- * @returns {CustomData[]} a list of custom data
38
+ * @method _updateFromVisit - an internal method for updating a list of custom data from a visit
39
+ * @param {VisitType} visit - a visit
50
40
  * */
51
- static _listFromVisits(visits: VisitType[]): CustomData[];
41
+ static _updateFromVisit(visit: VisitType, dataMap: Map<number, CustomData>): void;
52
42
  }
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CustomData=void 0;var _requester=require("../requester"),_types=require("./types");function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class CustomData{constructor(a){_defineProperty(this,"index",void 0),_defineProperty(this,"value",void 0),_defineProperty(this,"sent",void 0),_defineProperty(this,"isIdentifier",void 0),this.index=a;for(var b=arguments.length,c=Array(1<b?b-1:0),d=1;d<b;d++)c[d-1]=arguments[d];this.value=c,this.sent=!1,this.isIdentifier=!1}get url(){if("number"!=typeof this.index)return"";const a=[...new Set(this.value)];let b={};if(a.forEach(a=>{b[a]=1}),!Object.keys(b).length)return"";let c="";return this.isIdentifier&&(c=_requester.UrlParameter.MappingIdentifier+"true"),_requester.UrlEventType.CustomData+_requester.UrlParameter.Index+this.index+_requester.UrlParameter.ValuesCountMap+encodeURIComponent(JSON.stringify(b))+_requester.UrlParameter.Overwrite+"true"+c}get data(){return{index:this.index,value:this.value,type:_types.KameleoonData.CustomData,isIdentifier:this.isIdentifier,sent:this.sent}}get isSent(){return this.sent}set isSent(a){this.sent=a}set _isMappingIdentifier(a){this.isIdentifier=a}static _listFromVisits(a){const b=[],c=new Map;for(let b=a.length-1;0<=b;b--){const d=a[b];if(!d.customDataEvents)continue;const e=d.customDataEvents;for(const a of e){const{index:b,valuesCountMap:d}=a.data;c.set(b,Object.keys(d))}}for(const[d,e]of c)b.push(new CustomData(d,...e));return b}}exports.CustomData=CustomData;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CustomData=void 0;var _requester=require("../requester"),_types=require("./types");function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class CustomData{constructor(a){_defineProperty(this,"index",void 0),_defineProperty(this,"value",void 0),_defineProperty(this,"sent",void 0),_defineProperty(this,"isIdentifier",void 0),this.index=a;for(var b=arguments.length,c=Array(1<b?b-1:0),d=1;d<b;d++)c[d-1]=arguments[d];this.value=c,this.sent=!1,this.isIdentifier=!1}get url(){if("number"!=typeof this.index)return"";const a=[...new Set(this.value)];let b={};if(a.forEach(a=>{b[a]=1}),!Object.keys(b).length)return"";let c="";return this.isIdentifier&&(c=_requester.UrlParameter.MappingIdentifier+"true"),_requester.UrlEventType.CustomData+_requester.UrlParameter.Index+this.index+_requester.UrlParameter.ValuesCountMap+encodeURIComponent(JSON.stringify(b))+_requester.UrlParameter.Overwrite+"true"+c}get data(){return{index:this.index,value:this.value,type:_types.KameleoonData.CustomData,isIdentifier:this.isIdentifier,sent:this.sent}}get isSent(){return this.sent}set isSent(a){this.sent=a}set _isMappingIdentifier(a){this.isIdentifier=a}static _updateFromVisit(a,b){var c;if(null!==(c=a.customDataEvents)&&void 0!==c&&c.length)for(let c=a.customDataEvents.length-1;0<=c;c--){const{index:d,valuesCountMap:e}=a.customDataEvents[c].data;b.has(d)||b.set(d,new CustomData(d,...Object.keys(e)))}}}exports.CustomData=CustomData;
2
2
  //# sourceMappingURL=customData.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"customData.js","names":["CustomData","constructor","index","_defineProperty","b","arguments","length","value","Array","d","sent","isIdentifier","url","uniqueValues","Set","resultValue","forEach","Object","keys","identifierParameter","UrlParameter","MappingIdentifier","UrlEventType","Index","ValuesCountMap","encodeURIComponent","JSON","stringify","Overwrite","data","type","KameleoonData","isSent","_isMappingIdentifier","_listFromVisits","visits","resultData","customDataMap","Map","i","visit","customDataEvents","customDataEvent","valuesCountMap","set","push","exports"],"sources":["../../src/kameleoonData/customData.ts"],"sourcesContent":["import { UrlEventType, UrlParameter, VisitType } from 'src/requester';\nimport { CustomDataType, IKameleoonData, KameleoonData } from './types';\n\n/**\n * @class\n * CustomData - a class for creating an instance for user's custom data\n * */\nexport class CustomData implements IKameleoonData {\n private index: number;\n private value: string[];\n private sent: boolean;\n private isIdentifier: boolean;\n\n /**\n * @param {number} index - an index of custom data to be stored under in a state, an index of custom data can be specified in `Advanced Tools` section of Kameleoon Application\n * @param {string[]} value - custom value to store under the specified id, value can be anything but has to be stringified to match the `string` type. *Note* value is variadic parameter and can be used as follows\n * @example\n * ```ts\n * // - Single value\n * const customData = new CustomData(0, 'value_1');\n * // - Variadic number of values\n * const customData = new CustomData(0, 'value_1', 'value_2', 'value_3');\n * // - Array of values\n * const values = ['value_1', 'value_2', 'value_3'];\n * const customData = new CustomData(0, ...values);\n * ```\n * */\n constructor(index: number, ...value: string[]) {\n this.index = index;\n this.value = value;\n this.sent = false;\n this.isIdentifier = false;\n }\n\n /**\n * @property url - url for the current data type used for events tracking\n * */\n get url(): string {\n // --- Note ---\n // If SDK is used in vanilla JS codebase, then you're also able to create an instance\n // with no required data, we don't want send anything to tracking in that case\n if (typeof this.index !== 'number') {\n return '';\n }\n\n const uniqueValues = [...new Set(this.value)];\n let resultValue: Record<string, 1> = {};\n\n // --- Note ---\n // Final value should look like this `{ \"value_1\": 1, \"value_2\": 1, \"value_3\": 1}`\n // With no duplicates\n uniqueValues.forEach((value) => {\n resultValue[value] = 1;\n });\n\n if (!Object.keys(resultValue).length) {\n return '';\n }\n\n let identifierParameter = '';\n\n if (this.isIdentifier) {\n identifierParameter = UrlParameter.MappingIdentifier + String(true);\n }\n\n return (\n UrlEventType.CustomData +\n UrlParameter.Index +\n this.index +\n UrlParameter.ValuesCountMap +\n encodeURIComponent(JSON.stringify(resultValue)) +\n UrlParameter.Overwrite +\n String(true) +\n identifierParameter\n );\n }\n\n /**\n * @property data - data of the current class instance\n * */\n get data(): CustomDataType {\n return {\n index: this.index,\n value: this.value,\n type: KameleoonData.CustomData,\n isIdentifier: this.isIdentifier,\n sent: this.sent,\n };\n }\n\n /**\n * @property isSent - signifying if the data was sent already tracked\n * */\n get isSent(): boolean {\n return this.sent;\n }\n\n set isSent(value: boolean) {\n this.sent = value;\n }\n\n /**\n * @property isMappingIdentifier - signifying if the data is a mapping identifier\n * @private\n * */\n set _isMappingIdentifier(value: boolean) {\n this.isIdentifier = value;\n }\n\n /**\n * @private\n * @method _listFromVisits - an internal method for creating a list of custom data from a list of visits\n * @param {VisitType[]} visits - a list of visits\n * @returns {CustomData[]} a list of custom data\n * */\n public static _listFromVisits(visits: VisitType[]): CustomData[] {\n const resultData: CustomData[] = [];\n const customDataMap = new Map<number, string[]>();\n\n // --- Note ---\n // Going backwards to get the latest visit data\n for (let i = visits.length - 1; i >= 0; i--) {\n const visit = visits[i];\n\n if (!visit.customDataEvents) {\n continue;\n }\n\n const customDataEvents = visit.customDataEvents;\n\n for (const customDataEvent of customDataEvents) {\n const { index, valuesCountMap } = customDataEvent.data;\n\n customDataMap.set(index, Object.keys(valuesCountMap));\n }\n }\n\n for (const [index, data] of customDataMap) {\n resultData.push(new CustomData(index, ...data));\n }\n\n return resultData;\n }\n}\n"],"mappings":"kqBAOO,KAAM,CAAAA,UAAqC,CAoBhDC,WAAWA,CAACC,CAAa,CAAsB,CAAAC,eAAA,sBAAAA,eAAA,sBAAAA,eAAA,qBAAAA,eAAA,6BAC7C,IAAI,CAACD,KAAK,CAAGA,CAAK,SAAAE,CAAA,CAAAC,SAAA,CAAAC,MAAA,CADUC,CAAK,CAAAC,KAAA,GAAAJ,CAAA,CAAAA,CAAA,MAAAK,CAAA,GAAAA,CAAA,CAAAL,CAAA,CAAAK,CAAA,GAALF,CAAK,CAAAE,CAAA,IAAAJ,SAAA,CAAAI,CAAA,EAEjC,IAAI,CAACF,KAAK,CAAGA,CAAK,CAClB,IAAI,CAACG,IAAI,GAAQ,CACjB,IAAI,CAACC,YAAY,GACnB,CAKA,GAAI,CAAAC,GAAGA,CAAA,CAAW,CAIhB,GAA0B,Q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CAAA2B,eAAeA,CAACC,CAAmB,CAAgB,MACzD,CAAAC,CAAwB,CAAG,EAAE,CAC7BC,CAAa,CAAG,GAAI,CAAAC,GAAuB,CAIjD,IAAK,GAAI,CAAAC,CAAC,CAAGJ,CAAM,CAAC7B,MAAM,CAAG,CAAC,CAAO,CAAC,EAANiC,CAAM,CAAEA,CAAC,EAAE,CAAE,CAC3C,KAAM,CAAAC,CAAK,CAAGL,CAAM,CAACI,CAAC,CAAC,CAEvB,GAAI,CAACC,CAAK,CAACC,gBAAgB,CACzB,SAGF,KAAM,CAAAA,CAAgB,CAAGD,CAAK,CAACC,gBAAgB,CAE/C,IAAK,KAAM,CAAAC,CAAe,GAAI,CAAAD,CAAgB,CAAE,CAC9C,KAAM,CAAEvC,KAAK,CAALA,CAAK,CAAEyC,cAAc,CAAdA,CAAe,CAAC,CAAGD,CAAe,CAACb,IAAI,CAEtDQ,CAAa,CAACO,GAAG,CAAC1C,CAAK,CAAEe,MAAM,CAACC,IAAI,CAACyB,CAAc,CAAC,CACtD,CACF,CAEA,IAAK,KAAM,CAACzC,CAAK,CAAE2B,CAAI,CAAC,EAAI,CAAAQ,CAAa,CACvCD,CAAU,CAACS,IAAI,CAAC,GAAI,CAAA7C,UAAU,CAACE,CAAK,CAAE,GAAG2B,CAAI,CAAC,CAAC,CAGjD,MAAO,CAAAO,CACT,CACF,CAACU,OAAA,CAAA9C,UAAA,CAAAA,UAAA"}
1
+ {"version":3,"file":"customData.js","names":["CustomData","constructor","index","_defineProperty","b","arguments","length","value","Array","d","sent","isIdentifier","url","uniqueValues","Set","resultValue","forEach","Object","keys","identifierParameter","UrlParameter","MappingIdentifier","UrlEventType","Index","ValuesCountMap","encodeURIComponent","JSON","stringify","Overwrite","data","type","KameleoonData","isSent","_isMappingIdentifier","_updateFromVisit","visit","dataMap","c","customDataEvents","i","valuesCountMap","has","set","exports"],"sources":["../../src/kameleoonData/customData.ts"],"sourcesContent":["import { UrlEventType, UrlParameter, VisitType } from 'src/requester';\nimport { CustomDataType, IKameleoonData, KameleoonData } from './types';\n\n/**\n * @class\n * CustomData - a class for creating an instance for user's custom data\n * */\nexport class CustomData implements IKameleoonData {\n private index: number;\n private value: string[];\n private sent: boolean;\n private isIdentifier: boolean;\n\n /**\n * @param {number} index - an index of custom data to be stored under in a state, an index of custom data can be specified in `Advanced Tools` section of Kameleoon Application\n * @param {string[]} value - custom value to store under the specified id, value can be anything but has to be stringified to match the `string` type. *Note* value is variadic parameter and can be used as follows\n * @example\n * ```ts\n * // - Single value\n * const customData = new CustomData(0, 'value_1');\n * // - Variadic number of values\n * const customData = new CustomData(0, 'value_1', 'value_2', 'value_3');\n * // - Array of values\n * const values = ['value_1', 'value_2', 'value_3'];\n * const customData = new CustomData(0, ...values);\n * ```\n * */\n constructor(index: number, ...value: string[]) {\n this.index = index;\n this.value = value;\n this.sent = false;\n this.isIdentifier = false;\n }\n\n get url(): string {\n // --- Note ---\n // If SDK is used in vanilla JS codebase, then you're also able to create an instance\n // with no required data, we don't want send anything to tracking in that case\n if (typeof this.index !== 'number') {\n return '';\n }\n\n const uniqueValues = [...new Set(this.value)];\n let resultValue: Record<string, 1> = {};\n\n // --- Note ---\n // Final value should look like this `{ \"value_1\": 1, \"value_2\": 1, \"value_3\": 1}`\n // With no duplicates\n uniqueValues.forEach((value) => {\n resultValue[value] = 1;\n });\n\n if (!Object.keys(resultValue).length) {\n return '';\n }\n\n let identifierParameter = '';\n\n if (this.isIdentifier) {\n identifierParameter = UrlParameter.MappingIdentifier + String(true);\n }\n\n return (\n UrlEventType.CustomData +\n UrlParameter.Index +\n this.index +\n UrlParameter.ValuesCountMap +\n encodeURIComponent(JSON.stringify(resultValue)) +\n UrlParameter.Overwrite +\n String(true) +\n identifierParameter\n );\n }\n\n get data(): CustomDataType {\n return {\n index: this.index,\n value: this.value,\n type: KameleoonData.CustomData,\n isIdentifier: this.isIdentifier,\n sent: this.sent,\n };\n }\n\n get isSent(): boolean {\n return this.sent;\n }\n\n set isSent(value: boolean) {\n this.sent = value;\n }\n\n /**\n * @property isMappingIdentifier - signifying if the data is a mapping identifier\n * @private\n * */\n set _isMappingIdentifier(value: boolean) {\n this.isIdentifier = value;\n }\n\n /**\n * @private\n * @method _updateFromVisit - an internal method for updating a list of custom data from a visit\n * @param {VisitType} visit - a visit\n * */\n public static _updateFromVisit(\n visit: VisitType,\n dataMap: Map<number, CustomData>,\n ): void {\n if (visit.customDataEvents?.length) {\n for (let i = visit.customDataEvents.length - 1; i >= 0; i--) {\n const { index, valuesCountMap } = visit.customDataEvents[i].data;\n\n if (!dataMap.has(index)) {\n dataMap.set(\n index,\n new CustomData(index, ...Object.keys(valuesCountMap)),\n );\n }\n }\n }\n }\n}\n"],"mappings":"kqBAOO,KAAM,CAAAA,UAAqC,CAoBhDC,WAAWA,CAACC,CAAa,CAAsB,CAAAC,eAAA,sBAAAA,eAAA,sBAAAA,eAAA,qBAAAA,eAAA,6BAC7C,IAAI,CAACD,KAAK,CAAGA,CAAK,SAAAE,CAAA,CAAAC,SAAA,CAAAC,MAAA,CADUC,CAAK,CAAAC,KAAA,GAAAJ,CAAA,CAAAA,CAAA,MAAAK,CAAA,GAAAA,CAAA,CAAAL,CAAA,CAAAK,CAAA,GAALF,CAAK,CAAAE,CAAA,IAAAJ,SAAA,CAAAI,CAAA,EAEjC,IAAI,CAACF,KAAK,CAAGA,CAAK,CAClB,IAAI,CAACG,IAAI,GAAQ,CACjB,IAAI,CAACC,YAAY,GACnB,CAEA,GAAI,CAAAC,GAAGA,CAAA,CAAW,CAIhB,GAA0B,QAAQ,EAA9B,MAAO,KAAI,CAACV,KAAkB,CAChC,MAAO,EAAE,CAGX,KAAM,CAAAW,CAAY,CAAG,CAAC,GAAG,GAAI,CAAAC,GAAG,CAAC,IAAI,CAACP,KAAK,CAAC,CAAC,CAC7C,GAAI,CAAAQ,CAA8B,CAAG,CAAC,CAAC,CASvC,GAJAF,CAAY,CAACG,OAAO,CAAET,CAAK,EAAK,CAC9BQ,CAAW,CAAC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AAEA,CAAC,EAAE,CAAE,CAC3D,KAAM,CAAErC,KAAK,CAALA,CAAK,CAAEsC,cAAc,CAAdA,CAAe,CAAC,CAAGL,CAAK,CAACG,gBAAgB,CAACC,CAAC,CAAC,CAACV,IAAI,CAE3DO,CAAO,CAACK,GAAG,CAACvC,CAAK,CAAC,EACrBkC,CAAO,CAACM,GAAG,CACTxC,CAAK,CACL,GAAI,CAAAF,UAAU,CAACE,CAAK,CAAE,GAAGe,MAAM,CAACC,IAAI,CAACsB,CAAc,CAAC,CACtD,CAEJ,CAEJ,CACF,CAACG,OAAA,CAAA3C,UAAA,CAAAA,UAAA"}
@@ -1,9 +1,9 @@
1
1
  import { Result } from 'ts-res';
2
2
  import { KameleoonError } from '../kameleoonError';
3
- import { SegmentType, TargetingDataType, Tree } from '../targeting';
3
+ import { SegmentType, Tree } from '../targeting';
4
4
  import { CustomDataConfigurationType } from '../clientConfiguration';
5
5
  import { CustomData } from './customData';
6
- import { DataManagerParametersType, KameleoonData, KameleoonDataType, UnsentTargetingDataType } from './types';
6
+ import { DataManagerParametersType, KameleoonData, KameleoonDataType, KameleoonVisitorDataType, UnsentTargetingDataType } from './types';
7
7
  interface IDataManager {
8
8
  addData(visitorCode: string, ...kameleoonData: KameleoonDataType[]): void;
9
9
  getUnsentData: (visitorCode: string) => UnsentTargetingDataType[string] | undefined;
@@ -11,15 +11,17 @@ interface IDataManager {
11
11
  clearTrees(): void;
12
12
  clearUnsentData: (visitorCode: string) => void;
13
13
  isPersistentCustomData: (dataItem: KameleoonDataType) => boolean;
14
+ getLinkedVisitor: (visitorCode: string) => string | null;
15
+ getTargetingData: (visitorCode: string) => KameleoonVisitorDataType | undefined;
14
16
  readonly trees: Map<string, Tree>;
15
- readonly storedTargetingData: TargetingDataType;
16
17
  readonly unsentDataVisitors: string[];
18
+ readonly identifierCustomDataIndex: number | null;
17
19
  }
18
20
  export declare class DataManager implements IDataManager {
19
21
  private targetingTrees;
20
22
  private localCustomDataIndexes;
21
23
  private persistentCustomDataIndexes;
22
- private mappingIdentifierCustomDataIndexes;
24
+ private mappingIdentifierCustomDataIndex;
23
25
  private targetingDataIntervalId;
24
26
  private dataProcessor;
25
27
  private unsentData;
@@ -32,10 +34,14 @@ export declare class DataManager implements IDataManager {
32
34
  clearUnsentData(visitorCode: string): void;
33
35
  clearUnsentDataByKey(visitorCode: string, key: KameleoonData): void;
34
36
  isPersistentCustomData(dataItem: KameleoonDataType): dataItem is CustomData;
37
+ getLinkedVisitor(visitorCode: string): string | null;
35
38
  getVisitorIdentifier(visitorCode: string): string;
39
+ getTargetingData(visitorCode: string): KameleoonVisitorDataType | undefined;
36
40
  get trees(): Map<string, Tree>;
37
41
  get unsentDataVisitors(): string[];
38
- get storedTargetingData(): TargetingDataType;
42
+ get identifierCustomDataIndex(): number | null;
43
+ get storedDataTypes(): Set<KameleoonData>;
44
+ get storedCustomDataIndexes(): Set<number>;
39
45
  set customDataIndexes(customData: CustomDataConfigurationType[]);
40
46
  }
41
47
  export {};
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DataManager=void 0;var _targeting=require("../targeting"),_dataProcessor=require("./dataProcessor"),_utilities=require("../utilities"),_clientConfiguration=require("../clientConfiguration"),_types=require("../types"),_types2=require("./types");function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class DataManager{constructor(a){let{storage:b,targetingCleanupInterval:c}=a;if(_defineProperty(this,"targetingTrees",new Map),_defineProperty(this,"localCustomDataIndexes",new Set),_defineProperty(this,"persistentCustomDataIndexes",new Set),_defineProperty(this,"mappingIdentifierCustomDataIndexes",new Set),_defineProperty(this,"targetingDataIntervalId",null),_defineProperty(this,"dataProcessor",void 0),_defineProperty(this,"unsentData",void 0),_defineProperty(this,"sentPageViewTimestamps",new Map),this.dataProcessor=new _dataProcessor.DataProcessor(b),this.unsentData={},c){const a=0>c?1:c,b=()=>{this.dataProcessor.cleanupOutdatedTargetingData(c),this.sentPageViewTimestamps.clear()};try{this.targetingDataIntervalId=setInterval(b,a*_types.Milliseconds.Minute)}catch(a){throw this.targetingDataIntervalId&&clearInterval(this.targetingDataIntervalId),a}}}addData(a){this.unsentData[a]||(this.unsentData[a]=new Map);for(var b=arguments.length,c=Array(1<b?b-1:0),d=1;d<b;d++)c[d-1]=arguments[d];for(const b of c)switch(this.dataProcessor.updateData(a,b),b.data.type){case _types2.KameleoonData.CustomData:{const c=b,d=c.data;this.mappingIdentifierCustomDataIndexes.has(d.index)&&(c._isMappingIdentifier=!0),this.localCustomDataIndexes.has(d.index)||b.isSent||this.unsentData[a].set(d.index,c);break}case _types2.KameleoonData.PageView:{const c=b.data,d=this.dataProcessor.storedTargetingData.or({}),e=d[a][_types2.KameleoonData.PageView];if(e){const d=e[c.urlAddress];if(!b.isSent)for(const c of d.timestamps)this.sentPageViewTimestamps.has(c)||(this.unsentData[a].set(c,b),this.sentPageViewTimestamps.set(c,!0));else for(const a of d.timestamps)this.sentPageViewTimestamps.has(a)||this.sentPageViewTimestamps.set(a,!0)}break}case _types2.KameleoonData.Conversion:{const c=this.unsentData[a];if(!b.isSent)if(c.has(_types2.KameleoonData.Conversion)){const a=c.get(_types2.KameleoonData.Conversion);a.push(b),c.set(_types2.KameleoonData.Conversion,a)}else c.set(_types2.KameleoonData.Conversion,[b]);break}default:{const{data:c}=b;b.isSent||this.unsentData[a].set(c.type,b)}}return this.dataProcessor.createVisit(a)}getTree(a){if(!this.targetingTrees.has(a.id)){const b=new _targeting.Tree(a);return this.targetingTrees.set(a.id,new _targeting.Tree(a)),b}return this.targetingTrees.get(a.id)}clearTrees(){this.targetingTrees.clear()}getUnsentData(a){return this.unsentData[a]}clearUnsentData(a){var b;const c=null===(b=this.unsentData[a])||void 0===b?void 0:b.values();if(c&&this.persistentCustomDataIndexes.size){const b=new Map;for(const a of c)!Array.isArray(a)&&this.isPersistentCustomData(a)&&b.set(a.data.index,a);if(b.size)return void(this.unsentData[a]=b)}delete this.unsentData[a]}clearUnsentDataByKey(a,b){const c=this.unsentData[a];if(c){if(b===_types2.KameleoonData.CustomData&&this.persistentCustomDataIndexes.size)for(const[a,d]of c.entries())this.isPersistentCustomData(d)||a===b&&c.delete(a);else if(b===_types2.KameleoonData.PageView)for(const a of c.keys())"number"==typeof a&&c.delete(a);else c.delete(b);c.size||delete this.unsentData[a]}}isPersistentCustomData(a){return!!this.persistentCustomDataIndexes.size&&!!_utilities.Utilities.isCustomData(a)&&this.persistentCustomDataIndexes.has(a.data.index)}getVisitorIdentifier(a){const b=this.storedTargetingData;if(!b[a])return a;const c=b[a][_types2.KameleoonData.CustomData];if(!c)return a;for(const[b,d]of Object.entries(c))if(this.mappingIdentifierCustomDataIndexes.has(parseInt(b))&&d)return d.value[0];return a}get trees(){return this.targetingTrees}get unsentDataVisitors(){return Object.keys(this.unsentData)}get storedTargetingData(){return this.dataProcessor.storedTargetingData.or({})}set customDataIndexes(a){const[b,c,d]=[[],[],[]];a.forEach(a=>{a.localOnly&&b.push(a.index),a.scope===_clientConfiguration.CustomDataScope.Visitor&&c.push(a.index),a.isMappingIdentifier&&d.push(a.index)}),b.length&&(this.localCustomDataIndexes=new Set(b)),c.length&&(this.persistentCustomDataIndexes=new Set(c)),d.length&&(this.mappingIdentifierCustomDataIndexes=new Set(d))}}exports.DataManager=DataManager;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DataManager=void 0;var _tsRes=require("ts-res"),_targeting=require("../targeting"),_dataProcessor=require("./dataProcessor"),_utilities=require("../utilities"),_clientConfiguration=require("../clientConfiguration"),_types=require("../types"),_types2=require("./types");function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class DataManager{constructor(a){let{storage:b,targetingCleanupInterval:c}=a;if(_defineProperty(this,"targetingTrees",new Map),_defineProperty(this,"localCustomDataIndexes",new Set),_defineProperty(this,"persistentCustomDataIndexes",new Set),_defineProperty(this,"mappingIdentifierCustomDataIndex",null),_defineProperty(this,"targetingDataIntervalId",null),_defineProperty(this,"dataProcessor",void 0),_defineProperty(this,"unsentData",void 0),_defineProperty(this,"sentPageViewTimestamps",new Map),this.dataProcessor=new _dataProcessor.DataProcessor(b),this.unsentData={},c){const a=0>c?1:c,b=()=>{this.dataProcessor.cleanupOutdatedTargetingData(c),this.sentPageViewTimestamps.clear()};try{this.targetingDataIntervalId=setInterval(b,a*_types.Milliseconds.Minute)}catch(a){throw this.targetingDataIntervalId&&clearInterval(this.targetingDataIntervalId),a}}}addData(a){this.unsentData[a]||(this.unsentData[a]=new Map);for(var b=arguments.length,c=Array(1<b?b-1:0),d=1;d<b;d++)c[d-1]=arguments[d];for(const b of c)switch(this.dataProcessor.updateData(a,b),b.data.type){case _types2.KameleoonData.CustomData:{const c=b,d=c.data;this.mappingIdentifierCustomDataIndex===d.index&&(c._isMappingIdentifier=!0,a!==d.value[0]&&this.dataProcessor.createReference(a,d.value[0])),this.localCustomDataIndexes.has(d.index)||b.isSent||this.unsentData[a].set(d.index,c);break}case _types2.KameleoonData.PageView:{const c=b.data,d=this.dataProcessor.getTargetingData(a).or({});if(d){const e=d[_types2.KameleoonData.PageView],f=e[c.urlAddress];if(!b.isSent)for(const c of f.timestamps)this.sentPageViewTimestamps.has(c)||(this.unsentData[a].set(c,b),this.sentPageViewTimestamps.set(c,!0));else for(const a of f.timestamps)this.sentPageViewTimestamps.has(a)||this.sentPageViewTimestamps.set(a,!0)}break}case _types2.KameleoonData.Conversion:{const c=this.unsentData[a];if(!b.isSent)if(c.has(_types2.KameleoonData.Conversion)){const a=c.get(_types2.KameleoonData.Conversion);a.push(b),c.set(_types2.KameleoonData.Conversion,a)}else c.set(_types2.KameleoonData.Conversion,[b]);break}default:{const{data:c}=b;b.isSent||this.unsentData[a].set(c.type,b)}}return(0,_tsRes.Ok)()}getTree(a){if(this.targetingTrees.has(a.id))return this.targetingTrees.get(a.id);const b=new _targeting.Tree(a);return this.targetingTrees.set(a.id,b),b}clearTrees(){this.targetingTrees.clear()}getUnsentData(a){return this.unsentData[a]}clearUnsentData(a){var b;const c=null===(b=this.unsentData[a])||void 0===b?void 0:b.values();if(c&&this.persistentCustomDataIndexes.size){const b=new Map;for(const a of c)!Array.isArray(a)&&this.isPersistentCustomData(a)&&b.set(a.data.index,a);if(b.size)return void(this.unsentData[a]=b)}delete this.unsentData[a]}clearUnsentDataByKey(a,b){const c=this.unsentData[a];if(c){if(b===_types2.KameleoonData.CustomData&&this.persistentCustomDataIndexes.size)for(const[a,d]of c.entries())this.isPersistentCustomData(d)||a===b&&c.delete(a);else if(b===_types2.KameleoonData.PageView)for(const a of c.keys())"number"==typeof a&&c.delete(a);else c.delete(b);c.size||delete this.unsentData[a]}}isPersistentCustomData(a){return!!this.persistentCustomDataIndexes.size&&!!_utilities.Utilities.isCustomData(a)&&this.persistentCustomDataIndexes.has(a.data.index)}getLinkedVisitor(a){return this.dataProcessor.getLinkedVisitor(a,this.mappingIdentifierCustomDataIndex)}getVisitorIdentifier(a){const b=this.getTargetingData(a);if(!b)return a;const c=b[_types2.KameleoonData.CustomData];if(!c||null===this.mappingIdentifierCustomDataIndex)return a;const d=c[this.mappingIdentifierCustomDataIndex];return d?d.value[0]:a}getTargetingData(a){const b=this.dataProcessor.getTargetingData(a).or(null);return b?b:void 0}get trees(){return this.targetingTrees}get unsentDataVisitors(){return Object.keys(this.unsentData)}get identifierCustomDataIndex(){return this.mappingIdentifierCustomDataIndex}get storedDataTypes(){return this.dataProcessor.storedDataTypeList}get storedCustomDataIndexes(){return this.dataProcessor.storedCustomDataIndexList}set customDataIndexes(a){const[b,c]=[[],[]];a.forEach(a=>{a.localOnly&&b.push(a.index),a.scope===_clientConfiguration.CustomDataScope.Visitor&&c.push(a.index),a.isMappingIdentifier&&(this.mappingIdentifierCustomDataIndex=a.index)}),b.length&&(this.localCustomDataIndexes=new Set(b)),c.length&&(this.persistentCustomDataIndexes=new Set(c))}}exports.DataManager=DataManager;
2
2
  //# sourceMappingURL=dataManager.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"dataManager.js","names":["DataManager","constructor","a","storage","targetingCleanupInterval","_defineProperty","Map","Set","dataProcessor","DataProcessor","unsentData","cleanupInterval","cleanupCallback","cleanupOutdatedTargetingData","sentPageViewTimestamps","clear","targetingDataIntervalId","setInterval","Milliseconds","Minute","err","clearInterval","addData","visitorCode","b","arguments","length","kameleoonData","Array","d","dataItem","updateData","data","type","KameleoonData","CustomData","customData","mappingIdentifierCustomDataIndexes","has","index","_isMappingIdentifier","localCustomDataIndexes","isSent","set","PageView","storedData","storedTargetingData","or","storedVisitorData","pageView","urlAddress","timestamp","timestamps","Conversion","existingConversions","get","push","createVisit","getTree","segment","targetingTrees","id","targetingTree","Tree","clearTrees","getUnsentData","clearUnsentData","dataItems","values","persistentCustomDataIndexes","size","persistentCustomData","isArray","isPersistentCustomData","clearUnsentDataByKey","key","visitorData","dataKey","entries","delete","keys","Utilities","isCustomData","getVisitorIdentifier","targetingData","Object","parseInt","value","trees","unsentDataVisitors","customDataIndexes","customDataLocalOnlyIndexes","forEach","localOnly","scope","CustomDataScope","Visitor","isMappingIdentifier","exports"],"sources":["../../src/kameleoonData/dataManager.ts"],"sourcesContent":["import { Result } from 'ts-res';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { SegmentType, TargetingDataType, Tree } from 'src/targeting';\nimport { DataProcessor } from './dataProcessor';\nimport { Utilities } from 'src/utilities';\nimport {\n CustomDataConfigurationType,\n CustomDataScope,\n} from 'src/clientConfiguration';\nimport { Milliseconds } from 'src/types';\nimport { CustomData } from './customData';\nimport {\n DataManagerParametersType,\n ExistingPageViewDataType,\n KameleoonData,\n KameleoonDataType,\n PageViewDataType,\n UnsentTargetingDataType,\n UnsentVisitorTargetingDataType,\n} from './types';\n\ninterface IDataManager {\n addData(visitorCode: string, ...kameleoonData: KameleoonDataType[]): void;\n getUnsentData: (\n visitorCode: string,\n ) => UnsentTargetingDataType[string] | undefined;\n getTree(segment: SegmentType): Tree;\n clearTrees(): void;\n clearUnsentData: (visitorCode: string) => void;\n isPersistentCustomData: (dataItem: KameleoonDataType) => boolean;\n readonly trees: Map<string, Tree>;\n readonly storedTargetingData: TargetingDataType;\n readonly unsentDataVisitors: string[];\n}\n\nexport class DataManager implements IDataManager {\n private targetingTrees: Map<string, Tree> = new Map();\n private localCustomDataIndexes: Set<number> = new Set();\n private persistentCustomDataIndexes: Set<number> = new Set();\n private mappingIdentifierCustomDataIndexes: Set<number> = new Set();\n private targetingDataIntervalId: NodeJS.Timer | null = null;\n private dataProcessor: DataProcessor;\n private unsentData: UnsentTargetingDataType;\n private sentPageViewTimestamps: Map<number, boolean> = new Map();\n\n constructor({\n storage,\n targetingCleanupInterval,\n }: DataManagerParametersType) {\n this.dataProcessor = new DataProcessor(storage);\n this.unsentData = {};\n\n if (targetingCleanupInterval) {\n const cleanupInterval =\n targetingCleanupInterval < 0 ? 1 : targetingCleanupInterval;\n\n const cleanupCallback = () => {\n this.dataProcessor.cleanupOutdatedTargetingData(\n targetingCleanupInterval,\n );\n this.sentPageViewTimestamps.clear();\n };\n\n // --- Note ---\n // We can not make delayed code execution recoverable, as it might lead\n // to targeting data storage size overflow\n try {\n this.targetingDataIntervalId = setInterval(\n cleanupCallback,\n cleanupInterval * Milliseconds.Minute,\n );\n } catch (err) {\n if (this.targetingDataIntervalId) {\n clearInterval(this.targetingDataIntervalId);\n }\n\n throw err;\n }\n }\n }\n\n public addData(\n visitorCode: string,\n ...kameleoonData: KameleoonDataType[]\n ): Result<void, KameleoonError> {\n // --- Note ---\n // We assume `this.unsentTargetingData[visitorCode]` is always presents further\n if (!this.unsentData[visitorCode]) {\n this.unsentData[visitorCode] = new Map();\n }\n\n for (const dataItem of kameleoonData) {\n this.dataProcessor.updateData(visitorCode, dataItem);\n\n switch (dataItem.data.type) {\n case KameleoonData.CustomData: {\n const customData = dataItem as CustomData;\n const data = customData.data;\n\n // --- Bug ---\n // - There's a known issue here: `mappingIdentifier` won't be updated\n // in the storage because the data is written before `unsentData` update\n // and we get `mappingIdentifier` only by checking CC here\n // - It doesn't affect the functionality, as stored data is\n // only used for condition evaluation and `Visitor` scoped CD is never removed from `unsentData`\n // still it should be fixed with some `.updateData` refactor\n if (this.mappingIdentifierCustomDataIndexes.has(data.index)) {\n customData._isMappingIdentifier = true;\n }\n\n if (\n !this.localCustomDataIndexes.has(data.index) &&\n !dataItem.isSent\n ) {\n this.unsentData[visitorCode]!.set(data.index, customData);\n }\n\n break;\n }\n case KameleoonData.PageView: {\n const data = dataItem.data as PageViewDataType;\n\n // --- Note ---\n // `PageViews` can only be processed during storage update as they\n // can't create and merge referrers/titles/timestamps on their own\n // So we have to extract them from storage to update `unsentData` correctly\n const storedData = this.dataProcessor.storedTargetingData.or({});\n const storedVisitorData =\n storedData[visitorCode][KameleoonData.PageView];\n\n if (storedVisitorData) {\n const pageView = (storedVisitorData as ExistingPageViewDataType)[\n data.urlAddress\n ];\n\n // --- Note ---\n // A case for newly created page view\n if (!dataItem.isSent) {\n for (const timestamp of pageView.timestamps) {\n // --- Note ---\n // As we don't keep `sent` status for each timestamp, we have to\n // check if it was already sent to avoid duplicates\n if (!this.sentPageViewTimestamps.has(timestamp)) {\n this.unsentData[visitorCode]!.set(timestamp, dataItem);\n this.sentPageViewTimestamps.set(timestamp, true);\n }\n }\n // --- Note ---\n // A case for `getRemoteVisitorData` pre-loaded pages that shouldn't be sent again\n } else {\n for (const timestamp of pageView.timestamps) {\n if (!this.sentPageViewTimestamps.has(timestamp)) {\n this.sentPageViewTimestamps.set(timestamp, true);\n }\n }\n }\n }\n\n break;\n }\n case KameleoonData.Conversion: {\n const unsentData = this.unsentData[visitorCode]!;\n\n if (!dataItem.isSent) {\n if (unsentData.has(KameleoonData.Conversion)) {\n const existingConversions = unsentData.get(\n KameleoonData.Conversion,\n ) as KameleoonDataType[];\n\n existingConversions.push(dataItem);\n\n unsentData.set(KameleoonData.Conversion, existingConversions);\n } else {\n unsentData.set(KameleoonData.Conversion, [dataItem]);\n }\n }\n\n break;\n }\n default: {\n const { data } = dataItem;\n\n if (!dataItem.isSent) {\n this.unsentData[visitorCode]!.set(data.type, dataItem);\n }\n }\n }\n }\n\n return this.dataProcessor.createVisit(visitorCode);\n }\n\n public getTree(segment: SegmentType): Tree {\n if (!this.targetingTrees.has(segment.id)) {\n const targetingTree = new Tree(segment);\n\n this.targetingTrees.set(segment.id, new Tree(segment));\n\n return targetingTree;\n }\n\n return this.targetingTrees.get(segment.id) as Tree;\n }\n\n public clearTrees(): void {\n this.targetingTrees.clear();\n }\n\n public getUnsentData(\n visitorCode: string,\n ): UnsentTargetingDataType[string] | undefined {\n return this.unsentData[visitorCode];\n }\n\n public clearUnsentData(visitorCode: string): void {\n const dataItems = this.unsentData[visitorCode]?.values();\n\n if (dataItems && this.persistentCustomDataIndexes.size) {\n const persistentCustomData: UnsentVisitorTargetingDataType = new Map();\n\n for (const dataItem of dataItems) {\n if (!Array.isArray(dataItem) && this.isPersistentCustomData(dataItem)) {\n persistentCustomData.set(dataItem.data.index, dataItem);\n }\n }\n\n if (persistentCustomData.size) {\n this.unsentData[visitorCode] = persistentCustomData;\n return;\n }\n }\n\n delete this.unsentData[visitorCode];\n }\n\n public clearUnsentDataByKey(visitorCode: string, key: KameleoonData): void {\n const visitorData = this.unsentData[visitorCode];\n\n if (!visitorData) {\n return;\n }\n\n if (\n key === KameleoonData.CustomData &&\n this.persistentCustomDataIndexes.size\n ) {\n for (const [dataKey, dataItem] of visitorData.entries()) {\n if (this.isPersistentCustomData(dataItem as KameleoonDataType)) {\n continue;\n }\n\n if (dataKey === key) {\n visitorData.delete(dataKey);\n }\n }\n } else if (key === KameleoonData.PageView) {\n for (const dataKey of visitorData.keys()) {\n if (typeof dataKey === 'number') {\n visitorData.delete(dataKey);\n }\n }\n } else {\n visitorData.delete(key);\n }\n\n if (!visitorData.size) {\n delete this.unsentData[visitorCode];\n }\n }\n\n public isPersistentCustomData(\n dataItem: KameleoonDataType,\n ): dataItem is CustomData {\n if (!this.persistentCustomDataIndexes.size) {\n return false;\n }\n\n if (Utilities.isCustomData(dataItem)) {\n return this.persistentCustomDataIndexes.has(dataItem.data.index);\n }\n\n return false;\n }\n\n public getVisitorIdentifier(visitorCode: string): string {\n const targetingData = this.storedTargetingData;\n\n if (!targetingData[visitorCode]) {\n return visitorCode;\n }\n\n const customData = targetingData[visitorCode][KameleoonData.CustomData];\n\n if (!customData) {\n return visitorCode;\n }\n\n for (const [index, dataItem] of Object.entries(customData)) {\n if (\n this.mappingIdentifierCustomDataIndexes.has(parseInt(index)) &&\n dataItem\n ) {\n return dataItem.value[0];\n }\n }\n\n return visitorCode;\n }\n\n get trees() {\n return this.targetingTrees;\n }\n\n get unsentDataVisitors(): string[] {\n return Object.keys(this.unsentData);\n }\n\n get storedTargetingData(): TargetingDataType {\n return this.dataProcessor.storedTargetingData.or({});\n }\n\n set customDataIndexes(customData: CustomDataConfigurationType[]) {\n const [\n customDataLocalOnlyIndexes,\n persistentCustomDataIndexes,\n mappingIdentifierCustomDataIndexes,\n ]: Array<number[]> = [[], [], []];\n\n customData.forEach((customData) => {\n if (customData.localOnly) {\n customDataLocalOnlyIndexes.push(customData.index);\n }\n\n if (customData.scope === CustomDataScope.Visitor) {\n persistentCustomDataIndexes.push(customData.index);\n }\n\n if (customData.isMappingIdentifier) {\n mappingIdentifierCustomDataIndexes.push(customData.index);\n }\n });\n\n if (customDataLocalOnlyIndexes.length) {\n this.localCustomDataIndexes = new Set(customDataLocalOnlyIndexes);\n }\n\n if (persistentCustomDataIndexes.length) {\n this.persistentCustomDataIndexes = new Set(persistentCustomDataIndexes);\n }\n\n if (mappingIdentifierCustomDataIndexes.length) {\n this.mappingIdentifierCustomDataIndexes = new Set(\n mappingIdentifierCustomDataIndexes,\n );\n }\n }\n}\n"],"mappings":"m0BAmCO,KAAM,CAAAA,WAAoC,CAU/CC,WAAWA,CAAAC,CAAA,CAGmB,IAHlB,CACVC,OAAO,CAAPA,CAAO,CACPC,wBAAwB,CAAxBA,CACyB,CAAC,CAAAF,CAAA,CAI1B,GAAAG,eAAA,uBAhB0C,GAAI,CAAAC,GAAK,EAAAD,eAAA,+BACP,GAAI,CAAAE,GAAK,EAAAF,eAAA,oCACJ,GAAI,CAAAE,GAAK,EAAAF,eAAA,2CACF,GAAI,CAAAE,GAAK,EAAAF,eAAA,gCACZ,IAAI,EAAAA,eAAA,8BAAAA,eAAA,2BAAAA,eAAA,+BAGJ,GAAI,CAAAC,GAAK,EAM9D,IAAI,CAACE,aAAa,CAAG,GAAI,CAAAC,4BAAa,CAACN,CAAO,CAAC,CAC/C,IAAI,CAACO,UAAU,CAAG,CAAC,CAAC,CAEhBN,CAAwB,CAAE,MACtB,CAAAO,CAAe,CACQ,CAAC,CAA5BP,CAA4B,CAAG,CAAC,CAAGA,CAAwB,CAEvDQ,CAAe,CAAGA,CAAA,GAAM,CAC5B,IAAI,CAACJ,aAAa,CAACK,4BAA4B,CAC7CT,CACF,CAAC,CACD,IAAI,CAACU,sBAAsB,CAACC,KAAK,CAAC,CACpC,CAAC,CAKD,GAAI,CACF,IAAI,CAACC,uBAAuB,CAAGC,WAAW,CACxCL,CAAe,CACfD,CAAe,CAAGO,mBAAY,CAACC,MACjC,CACF,CAAE,MAA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jCD,CAAU,CAACwD,OAAO,CAAExD,CAAU,EAAK,CAC7BA,CAAU,CAACyD,SAAS,EACtBF,CAA0B,CAACnC,IAAI,CAACpB,CAAU,CAACG,KAAK,CAAC,CAG/CH,CAAU,CAAC0D,KAAK,GAAKC,oCAAe,CAACC,OAAO,EAC9C3B,CAA2B,CAACb,IAAI,CAACpB,CAAU,CAACG,KAAK,CAAC,CAGhDH,CAAU,CAAC6D,mBAAmB,EAChC5D,CAAkC,CAACmB,IAAI,CAACpB,CAAU,CAACG,KAAK,CAE5D,CAAC,CAAC,CAEEoD,CAA0B,CAACjE,MAAM,GACnC,IAAI,CAACe,sBAAsB,CAAG,GAAI,CAAAlC,GAAG,CAACoF,CAA0B,CAAC,EAG/DtB,CAA2B,CAAC3C,MAAM,GACpC,IAAI,CAAC2C,2BAA2B,CAAG,GAAI,CAAA9D,GAAG,CAAC8D,CAA2B,CAAC,EAGrEhC,CAAkC,CAACX,MAAM,GAC3C,IAAI,CAACW,kCAAkC,CAAG,GAAI,CAAA9B,GAAG,CAC/C8B,CACF,CAAC,CAEL,CACF,CAAC6D,OAAA,CAAAlG,WAAA,CAAAA,WAAA"}
1
+ {"version":3,"file":"dataManager.js","names":["DataManager","constructor","a","storage","targetingCleanupInterval","_defineProperty","Map","Set","dataProcessor","DataProcessor","unsentData","cleanupInterval","cleanupCallback","cleanupOutdatedTargetingData","sentPageViewTimestamps","clear","targetingDataIntervalId","setInterval","Milliseconds","Minute","err","clearInterval","addData","visitorCode","b","arguments","length","kameleoonData","Array","d","dataItem","updateData","data","type","KameleoonData","CustomData","customData","mappingIdentifierCustomDataIndex","index","_isMappingIdentifier","value","createReference","localCustomDataIndexes","has","isSent","set","PageView","storedData","getTargetingData","or","storedVisitorData","pageView","urlAddress","timestamp","timestamps","Conversion","existingConversions","get","push","Ok","getTree","segment","targetingTrees","id","targetingTree","Tree","clearTrees","getUnsentData","clearUnsentData","dataItems","values","persistentCustomDataIndexes","size","persistentCustomData","isArray","isPersistentCustomData","clearUnsentDataByKey","key","visitorData","dataKey","entries","delete","keys","Utilities","isCustomData","getLinkedVisitor","getVisitorIdentifier","targetingData","customDataValue","trees","unsentDataVisitors","Object","identifierCustomDataIndex","storedDataTypes","storedDataTypeList","storedCustomDataIndexes","storedCustomDataIndexList","customDataIndexes","customDataLocalOnlyIndexes","forEach","localOnly","scope","CustomDataScope","Visitor","isMappingIdentifier","exports"],"sources":["../../src/kameleoonData/dataManager.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { SegmentType, Tree } from 'src/targeting';\nimport { DataProcessor } from './dataProcessor';\nimport { Utilities } from 'src/utilities';\nimport {\n CustomDataConfigurationType,\n CustomDataScope,\n} from 'src/clientConfiguration';\nimport { Milliseconds } from 'src/types';\nimport { CustomData } from './customData';\nimport {\n DataManagerParametersType,\n ExistingPageViewDataType,\n KameleoonData,\n KameleoonDataType,\n KameleoonVisitorDataType,\n PageViewDataType,\n UnsentTargetingDataType,\n UnsentVisitorTargetingDataType,\n} from './types';\n\ninterface IDataManager {\n addData(visitorCode: string, ...kameleoonData: KameleoonDataType[]): void;\n getUnsentData: (\n visitorCode: string,\n ) => UnsentTargetingDataType[string] | undefined;\n getTree(segment: SegmentType): Tree;\n clearTrees(): void;\n clearUnsentData: (visitorCode: string) => void;\n isPersistentCustomData: (dataItem: KameleoonDataType) => boolean;\n getLinkedVisitor: (visitorCode: string) => string | null;\n getTargetingData: (\n visitorCode: string,\n ) => KameleoonVisitorDataType | undefined;\n readonly trees: Map<string, Tree>;\n readonly unsentDataVisitors: string[];\n readonly identifierCustomDataIndex: number | null;\n}\n\nexport class DataManager implements IDataManager {\n private targetingTrees: Map<string, Tree> = new Map();\n private localCustomDataIndexes: Set<number> = new Set();\n private persistentCustomDataIndexes: Set<number> = new Set();\n private mappingIdentifierCustomDataIndex: number | null = null;\n private targetingDataIntervalId: NodeJS.Timer | null = null;\n private dataProcessor: DataProcessor;\n private unsentData: UnsentTargetingDataType;\n private sentPageViewTimestamps: Map<number, boolean> = new Map();\n\n constructor({\n storage,\n targetingCleanupInterval,\n }: DataManagerParametersType) {\n this.dataProcessor = new DataProcessor(storage);\n this.unsentData = {};\n\n if (targetingCleanupInterval) {\n const cleanupInterval =\n targetingCleanupInterval < 0 ? 1 : targetingCleanupInterval;\n\n const cleanupCallback = () => {\n this.dataProcessor.cleanupOutdatedTargetingData(\n targetingCleanupInterval,\n );\n this.sentPageViewTimestamps.clear();\n };\n\n // --- Note ---\n // We can not make delayed code execution recoverable, as it might lead\n // to targeting data storage size overflow\n try {\n this.targetingDataIntervalId = setInterval(\n cleanupCallback,\n cleanupInterval * Milliseconds.Minute,\n );\n } catch (err) {\n if (this.targetingDataIntervalId) {\n clearInterval(this.targetingDataIntervalId);\n }\n\n throw err;\n }\n }\n }\n\n public addData(\n visitorCode: string,\n ...kameleoonData: KameleoonDataType[]\n ): Result<void, KameleoonError> {\n // --- Note ---\n // We assume `this.unsentTargetingData[visitorCode]` is always presents further\n if (!this.unsentData[visitorCode]) {\n this.unsentData[visitorCode] = new Map();\n }\n\n for (const dataItem of kameleoonData) {\n // TODO: this can be optimized to be updated altogether\n // instead of updating each data item separately\n this.dataProcessor.updateData(visitorCode, dataItem);\n\n switch (dataItem.data.type) {\n case KameleoonData.CustomData: {\n const customData = dataItem as CustomData;\n const data = customData.data;\n\n // --- Bug ---\n // - There's a known issue here: `mappingIdentifier` won't be updated\n // in the storage because the data is written before `unsentData` update\n // and we get `mappingIdentifier` only by checking CC here\n // - It doesn't affect the functionality, as stored data is\n // only used for condition evaluation and `Visitor` scoped CD is never removed from `unsentData`\n // still it should be fixed with some `.updateData` refactor\n if (this.mappingIdentifierCustomDataIndex === data.index) {\n customData._isMappingIdentifier = true;\n\n if (visitorCode !== data.value[0]) {\n // --- Note ---\n // Associate linked visitor codes\n this.dataProcessor.createReference(visitorCode, data.value[0]);\n }\n }\n\n if (\n !this.localCustomDataIndexes.has(data.index) &&\n !dataItem.isSent\n ) {\n this.unsentData[visitorCode]!.set(data.index, customData);\n }\n\n break;\n }\n case KameleoonData.PageView: {\n const data = dataItem.data as PageViewDataType;\n\n // --- Note ---\n // `PageViews` can only be processed during storage update as they\n // can't create and merge referrers/titles/timestamps on their own\n // So we have to extract them from storage to update `unsentData` correctly\n const storedData = this.dataProcessor\n .getTargetingData(visitorCode)\n .or({});\n\n if (storedData) {\n const storedVisitorData = storedData[KameleoonData.PageView];\n const pageView = (storedVisitorData as ExistingPageViewDataType)[\n data.urlAddress\n ];\n\n // --- Note ---\n // A case for newly created page view\n if (!dataItem.isSent) {\n for (const timestamp of pageView.timestamps) {\n // --- Note ---\n // As we don't keep `sent` status for each timestamp, we have to\n // check if it was already sent to avoid duplicates\n if (!this.sentPageViewTimestamps.has(timestamp)) {\n this.unsentData[visitorCode]!.set(timestamp, dataItem);\n this.sentPageViewTimestamps.set(timestamp, true);\n }\n }\n // --- Note ---\n // A case for `getRemoteVisitorData` pre-loaded pages that shouldn't be sent again\n } else {\n for (const timestamp of pageView.timestamps) {\n if (!this.sentPageViewTimestamps.has(timestamp)) {\n this.sentPageViewTimestamps.set(timestamp, true);\n }\n }\n }\n }\n\n break;\n }\n case KameleoonData.Conversion: {\n const unsentData = this.unsentData[visitorCode]!;\n\n if (!dataItem.isSent) {\n if (unsentData.has(KameleoonData.Conversion)) {\n const existingConversions = unsentData.get(\n KameleoonData.Conversion,\n ) as KameleoonDataType[];\n\n existingConversions.push(dataItem);\n\n unsentData.set(KameleoonData.Conversion, existingConversions);\n } else {\n unsentData.set(KameleoonData.Conversion, [dataItem]);\n }\n }\n\n break;\n }\n default: {\n const { data } = dataItem;\n\n if (!dataItem.isSent) {\n this.unsentData[visitorCode]!.set(data.type, dataItem);\n }\n }\n }\n }\n\n return Ok();\n }\n\n public getTree(segment: SegmentType): Tree {\n if (this.targetingTrees.has(segment.id)) {\n return this.targetingTrees.get(segment.id)!;\n }\n\n const targetingTree = new Tree(segment);\n this.targetingTrees.set(segment.id, targetingTree);\n\n return targetingTree;\n }\n\n public clearTrees(): void {\n this.targetingTrees.clear();\n }\n\n public getUnsentData(\n visitorCode: string,\n ): UnsentTargetingDataType[string] | undefined {\n return this.unsentData[visitorCode];\n }\n\n public clearUnsentData(visitorCode: string): void {\n const dataItems = this.unsentData[visitorCode]?.values();\n\n if (dataItems && this.persistentCustomDataIndexes.size) {\n const persistentCustomData: UnsentVisitorTargetingDataType = new Map();\n\n for (const dataItem of dataItems) {\n if (!Array.isArray(dataItem) && this.isPersistentCustomData(dataItem)) {\n persistentCustomData.set(dataItem.data.index, dataItem);\n }\n }\n\n if (persistentCustomData.size) {\n this.unsentData[visitorCode] = persistentCustomData;\n return;\n }\n }\n\n delete this.unsentData[visitorCode];\n }\n\n public clearUnsentDataByKey(visitorCode: string, key: KameleoonData): void {\n const visitorData = this.unsentData[visitorCode];\n\n if (!visitorData) {\n return;\n }\n\n if (\n key === KameleoonData.CustomData &&\n this.persistentCustomDataIndexes.size\n ) {\n for (const [dataKey, dataItem] of visitorData.entries()) {\n if (this.isPersistentCustomData(dataItem as KameleoonDataType)) {\n continue;\n }\n\n if (dataKey === key) {\n visitorData.delete(dataKey);\n }\n }\n } else if (key === KameleoonData.PageView) {\n for (const dataKey of visitorData.keys()) {\n if (typeof dataKey === 'number') {\n visitorData.delete(dataKey);\n }\n }\n } else {\n visitorData.delete(key);\n }\n\n if (!visitorData.size) {\n delete this.unsentData[visitorCode];\n }\n }\n\n public isPersistentCustomData(\n dataItem: KameleoonDataType,\n ): dataItem is CustomData {\n if (!this.persistentCustomDataIndexes.size) {\n return false;\n }\n\n if (Utilities.isCustomData(dataItem)) {\n return this.persistentCustomDataIndexes.has(dataItem.data.index);\n }\n\n return false;\n }\n\n public getLinkedVisitor(visitorCode: string): string | null {\n return this.dataProcessor.getLinkedVisitor(\n visitorCode,\n this.mappingIdentifierCustomDataIndex,\n );\n }\n\n public getVisitorIdentifier(visitorCode: string): string {\n const targetingData = this.getTargetingData(visitorCode);\n\n if (!targetingData) {\n return visitorCode;\n }\n\n const customData = targetingData[KameleoonData.CustomData];\n\n if (!customData || this.mappingIdentifierCustomDataIndex === null) {\n return visitorCode;\n }\n\n const customDataValue = customData[this.mappingIdentifierCustomDataIndex];\n\n if (customDataValue) {\n return customDataValue.value[0];\n }\n\n return visitorCode;\n }\n\n public getTargetingData(\n visitorCode: string,\n ): KameleoonVisitorDataType | undefined {\n const targetingData = this.dataProcessor\n .getTargetingData(visitorCode)\n .or(null);\n\n if (!targetingData) {\n return undefined;\n }\n\n return targetingData;\n }\n\n get trees(): Map<string, Tree> {\n return this.targetingTrees;\n }\n\n get unsentDataVisitors(): string[] {\n return Object.keys(this.unsentData);\n }\n\n get identifierCustomDataIndex(): number | null {\n return this.mappingIdentifierCustomDataIndex;\n }\n\n get storedDataTypes(): Set<KameleoonData> {\n return this.dataProcessor.storedDataTypeList;\n }\n\n get storedCustomDataIndexes(): Set<number> {\n return this.dataProcessor.storedCustomDataIndexList;\n }\n\n set customDataIndexes(customData: CustomDataConfigurationType[]) {\n const [customDataLocalOnlyIndexes, persistentCustomDataIndexes]: Array<\n number[]\n > = [[], []];\n\n customData.forEach((customData) => {\n if (customData.localOnly) {\n customDataLocalOnlyIndexes.push(customData.index);\n }\n\n if (customData.scope === CustomDataScope.Visitor) {\n persistentCustomDataIndexes.push(customData.index);\n }\n\n if (customData.isMappingIdentifier) {\n this.mappingIdentifierCustomDataIndex = customData.index;\n }\n });\n\n if (customDataLocalOnlyIndexes.length) {\n this.localCustomDataIndexes = new Set(customDataLocalOnlyIndexes);\n }\n\n if (persistentCustomDataIndexes.length) {\n this.persistentCustomDataIndexes = new Set(persistentCustomDataIndexes);\n }\n }\n}\n"],"mappings":"41BAwCO,KAAM,CAAAA,WAAoC,CAU/CC,WAAWA,CAAAC,CAAA,CAGmB,IAHlB,CACVC,OAAO,CAAPA,CAAO,CACPC,wBAAwB,CAAxBA,CACyB,CAAC,CAAAF,CAAA,CAI1B,GAAAG,eAAA,uBAhB0C,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