@@ -35,7 +35,7 @@ Countly.StorageTypes = cc.storageTypeEnums;
3535Countly . DeviceIdType = cc . deviceIdTypeEnums ;
3636Countly . Bulk = Bulk ;
3737( function ( ) {
38- var SDK_VERSION = "24.10.3 " ;
38+ var SDK_VERSION = "24.10.4 " ;
3939 var SDK_NAME = "javascript_native_nodejs" ;
4040
4141 var inited = false ;
@@ -103,6 +103,7 @@ Countly.Bulk = Bulk;
103103 * @param {number } [conf.session_update=60] - how often in seconds should session be extended
104104 * @param {number } [conf.max_events=100] - maximum amount of events to send in one batch
105105 * @param {boolean } [conf.force_post=false] - force using post method for all requests
106+ * @param {string } [conf.salt] - shared secret used to append checksum256 to outgoing requests
106107 * @param {boolean } [conf.clear_stored_device_id=false] - set it to true if you want to erase the stored device ID
107108 * @param {boolean } [conf.test_mode=false] - set it to true if you want to initiate test_mode
108109 * @param {string } [conf.storage_path] - where SDK would store data, including id, queues, etc
@@ -162,6 +163,7 @@ Countly.Bulk = Bulk;
162163 Countly . city = conf . city || Countly . city || null ;
163164 Countly . ip_address = conf . ip_address || Countly . ip_address || null ;
164165 Countly . force_post = conf . force_post || Countly . force_post || false ;
166+ Countly . salt = conf . salt || Countly . salt || null ;
165167 Countly . require_consent = conf . require_consent || Countly . require_consent || false ;
166168 Countly . remote_config = conf . remote_config || Countly . remote_config || false ;
167169 Countly . http_options = conf . http_options || Countly . http_options || null ;
@@ -215,6 +217,7 @@ Countly.Bulk = Bulk;
215217 cc . log ( cc . logLevelEnums . DEBUG , `init, IP address: [${ Countly . ip_address } ].` ) ;
216218 }
217219 cc . log ( cc . logLevelEnums . DEBUG , `init, Force POST requests: [${ Countly . force_post } ].` ) ;
220+ cc . log ( cc . logLevelEnums . DEBUG , `init, Salt is configured: [${ ! ! Countly . salt } ].` ) ;
218221 cc . log ( cc . logLevelEnums . DEBUG , `init, Storage path: [${ CountlyStorage . getStoragePath ( ) } ].` ) ;
219222 cc . log ( cc . logLevelEnums . DEBUG , `init, Require consent: [${ Countly . require_consent } ].` ) ;
220223 if ( Countly . remote_config ) {
@@ -353,6 +356,7 @@ Countly.Bulk = Bulk;
353356 Countly . city = undefined ;
354357 Countly . ip_address = undefined ;
355358 Countly . force_post = undefined ;
359+ Countly . salt = undefined ;
356360 Countly . require_consent = undefined ;
357361 Countly . http_options = undefined ;
358362 CountlyStorage . resetStorage ( ) ;
@@ -1670,17 +1674,36 @@ Countly.Bulk = Bulk;
16701674
16711675 var boundary = `FormBoundary${ Math . random ( ) . toString ( 16 ) . slice ( 2 ) } ` ;
16721676 var bodyParts = [ ] ;
1677+ var uploadParams = { } ;
16731678
16741679 for ( var p in params ) {
1675- if ( typeof params [ p ] !== "undefined" && p !== 'picturePath' ) {
1676- var value = params [ p ] ;
1680+ if ( Object . prototype . hasOwnProperty . call ( params , p ) && typeof params [ p ] !== "undefined" && p !== "picturePath" ) {
1681+ uploadParams [ p ] = params [ p ] ;
1682+ }
1683+ }
1684+
1685+ var uploadChecksum = null ;
1686+ if ( Countly . salt ) {
1687+ uploadChecksum = cc . calculateChecksum ( cc . serializeParams ( uploadParams ) , Countly . salt , true ) ;
1688+ }
1689+
1690+ for ( var param in uploadParams ) {
1691+ if ( Object . prototype . hasOwnProperty . call ( uploadParams , param ) ) {
1692+ var value = uploadParams [ param ] ;
16771693 bodyParts . push ( Buffer . from ( `--${ boundary } \r\n` ) ) ;
1678- bodyParts . push ( Buffer . from ( `Content-Disposition: form-data; name="${ p } "\r\n\r\n` ) ) ;
1694+ bodyParts . push ( Buffer . from ( `Content-Disposition: form-data; name="${ param } "\r\n\r\n` ) ) ;
16791695 bodyParts . push ( Buffer . from ( String ( value ) ) ) ;
16801696 bodyParts . push ( Buffer . from ( '\r\n' ) ) ;
16811697 }
16821698 }
16831699
1700+ if ( uploadChecksum ) {
1701+ bodyParts . push ( Buffer . from ( `--${ boundary } \r\n` ) ) ;
1702+ bodyParts . push ( Buffer . from ( 'Content-Disposition: form-data; name="checksum256"\r\n\r\n' ) ) ;
1703+ bodyParts . push ( Buffer . from ( uploadChecksum ) ) ;
1704+ bodyParts . push ( Buffer . from ( '\r\n' ) ) ;
1705+ }
1706+
16841707 bodyParts . push ( Buffer . from ( `--${ boundary } \r\n` ) ) ;
16851708 bodyParts . push ( Buffer . from ( `Content-Disposition: form-data; name="user_picture"; filename="${ fileName } "\r\n` ) ) ;
16861709 bodyParts . push ( Buffer . from ( `Content-Type: ${ contentType } \r\n\r\n` ) ) ;
@@ -1779,16 +1802,14 @@ Countly.Bulk = Bulk;
17791802 }
17801803
17811804 /**
1782- * Convert JSON object to query params
1805+ * Convert JSON object to query params and append checksum when configured
17831806 * @param {Object } params - object with url params
1807+ * @param {Boolean } decodeBeforeHash - if true request data is URL-decoded before hashing
17841808 * @returns {String } query string
17851809 */
1786- function prepareParams ( params ) {
1787- var str = [ ] ;
1788- for ( var i in params ) {
1789- str . push ( `${ i } =${ encodeURIComponent ( params [ i ] ) } ` ) ;
1790- }
1791- return str . join ( "&" ) ;
1810+ function prepareParams ( params , decodeBeforeHash ) {
1811+ var data = cc . serializeParams ( params ) ;
1812+ return cc . addChecksum ( data , Countly . salt , decodeBeforeHash , false ) ;
17921813 }
17931814
17941815 /**
0 commit comments