You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flagon.apache.org by po...@apache.org on 2019/11/23 04:13:12 UTC

[incubator-flagon-useralejs] branch FLAGON-469 updated: [FLAGON-471] modified sendLogs adn getInitialSettings to accommodate authHeaders in script tag params

This is an automated email from the ASF dual-hosted git repository.

poorejc pushed a commit to branch FLAGON-469
in repository https://gitbox.apache.org/repos/asf/incubator-flagon-useralejs.git


The following commit(s) were added to refs/heads/FLAGON-469 by this push:
     new 41259ff  [FLAGON-471] modified sendLogs adn getInitialSettings to accommodate authHeaders in script tag params
41259ff is described below

commit 41259ff53976ff450a93b3d4aece2951838175d9
Author: poorejc <po...@apache.org>
AuthorDate: Fri Nov 22 23:12:33 2019 -0500

    [FLAGON-471] modified sendLogs adn getInitialSettings to accommodate authHeaders in script tag params
---
 build/UserAleWebExtension/background.js | 20 +++++++++++---------
 build/UserAleWebExtension/content.js    | 24 +++++++++++++-----------
 build/userale-2.0.2.js                  | 24 +++++++++++++-----------
 build/userale-2.0.2.min.js              |  2 +-
 src/getInitialSettings.js               |  2 +-
 src/sendLogs.js                         | 20 ++++++++++----------
 test/main_spec.js                       |  1 +
 7 files changed, 50 insertions(+), 43 deletions(-)

diff --git a/build/UserAleWebExtension/background.js b/build/UserAleWebExtension/background.js
index 3c3a538..44af556 100644
--- a/build/UserAleWebExtension/background.js
+++ b/build/UserAleWebExtension/background.js
@@ -179,7 +179,7 @@ function sendOnInterval(logs, config) {
     }
 
     if (logs.length >= config.logCountThreshold) {
-      sendLogs(logs.slice(0), config.url, 0); // Send a copy
+      sendLogs(logs.slice(0), config, 0); // Send a copy
       logs.splice(0); // Clear array reference (no reassignment)
     }
   }, config.transmitInterval);
@@ -202,7 +202,7 @@ function sendOnClose(logs, config) {
   } else {
     window.addEventListener('beforeunload', function() {
       if (logs.length > 0) {
-        sendLogs(logs, config.url, 1);
+        sendLogs(logs, config, 1);
       }
     });
   }
@@ -212,26 +212,28 @@ function sendOnClose(logs, config) {
  * Sends the provided array of logs to the specified url,
  * retrying the request up to the specified number of retries.
  * @param  {Array} logs    Array of logs to send.
- * @param  {string} url     URL to send the POST request to.
+ * @param  {string} config     configuration parameters (e.g., to extract URL from & send the POST request to).
  * @param  {Number} retries Maximum number of attempts to send the logs.
  */
-function sendLogs(logs, url, retries) {
+
+// @todo expose config object to sendLogs replate url with config.url
+function sendLogs(logs, config, retries) {
   var req = new XMLHttpRequest();
 
   // @todo setRequestHeader for Auth
   var data = JSON.stringify(logs);
 
-  req.open('POST', url);
-  //if (config.authHeader) {
-  //  req.setRequestHeader('Authorization', config.authHeader)
-  //}
+  req.open('POST', config.url);
+  if (config.authHeader) {
+    req.setRequestHeader('Authorization', config.authHeader);
+  }
 
   req.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
 
   req.onreadystatechange = function() {
     if (req.readyState === 4 && req.status !== 200) {
       if (retries > 0) {
-        sendLogs(logs, url, retries--);
+        sendLogs(logs, config, retries--);
       }
     }
   };
diff --git a/build/UserAleWebExtension/content.js b/build/UserAleWebExtension/content.js
index f225e95..ec59c1d 100644
--- a/build/UserAleWebExtension/content.js
+++ b/build/UserAleWebExtension/content.js
@@ -100,7 +100,7 @@ function getInitialSettings() {
   settings.userFromParams = get('data-user-from-params') || null;
   settings.time = timeStampScale(document.createEvent('CustomEvent'));
   settings.sessionID = get('data-session') || sessionId;
-//  settings.authHeader = get ('data-auth') || null;
+  settings.authHeader = get ('data-auth') || null;
 
   return settings;
 }
@@ -522,7 +522,7 @@ function sendOnInterval(logs, config) {
     }
 
     if (logs.length >= config.logCountThreshold) {
-      sendLogs(logs.slice(0), config.url, 0); // Send a copy
+      sendLogs(logs.slice(0), config, 0); // Send a copy
       logs.splice(0); // Clear array reference (no reassignment)
     }
   }, config.transmitInterval);
@@ -542,7 +542,7 @@ function sendOnRefresh(logs, config) {
     return;
   }
   if (logs.length > 0) {
-    sendLogs(logs, config.url, 1);
+    sendLogs(logs, config, 1);
   }
 }
 
@@ -563,7 +563,7 @@ function sendOnClose(logs, config) {
   } else {
     window.addEventListener('beforeunload', function() {
       if (logs.length > 0) {
-        sendLogs(logs, config.url, 1);
+        sendLogs(logs, config, 1);
       }
     });
   }
@@ -573,26 +573,28 @@ function sendOnClose(logs, config) {
  * Sends the provided array of logs to the specified url,
  * retrying the request up to the specified number of retries.
  * @param  {Array} logs    Array of logs to send.
- * @param  {string} url     URL to send the POST request to.
+ * @param  {string} config     configuration parameters (e.g., to extract URL from & send the POST request to).
  * @param  {Number} retries Maximum number of attempts to send the logs.
  */
-function sendLogs(logs, url, retries) {
+
+// @todo expose config object to sendLogs replate url with config.url
+function sendLogs(logs, config, retries) {
   var req = new XMLHttpRequest();
 
   // @todo setRequestHeader for Auth
   var data = JSON.stringify(logs);
 
-  req.open('POST', url);
-  //if (config.authHeader) {
-  //  req.setRequestHeader('Authorization', config.authHeader)
-  //}
+  req.open('POST', config.url);
+  if (config.authHeader) {
+    req.setRequestHeader('Authorization', config.authHeader);
+  }
 
   req.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
 
   req.onreadystatechange = function() {
     if (req.readyState === 4 && req.status !== 200) {
       if (retries > 0) {
-        sendLogs(logs, url, retries--);
+        sendLogs(logs, config, retries--);
       }
     }
   };
diff --git a/build/userale-2.0.2.js b/build/userale-2.0.2.js
index 0a47977..db5a5a1 100644
--- a/build/userale-2.0.2.js
+++ b/build/userale-2.0.2.js
@@ -71,7 +71,7 @@ var userale = (function (exports) {
     settings.userFromParams = get('data-user-from-params') || null;
     settings.time = timeStampScale(document.createEvent('CustomEvent'));
     settings.sessionID = get('data-session') || sessionId;
-  //  settings.authHeader = get ('data-auth') || null;
+    settings.authHeader = get ('data-auth') || null;
 
     return settings;
   }
@@ -501,7 +501,7 @@ var userale = (function (exports) {
       }
 
       if (logs.length >= config.logCountThreshold) {
-        sendLogs(logs.slice(0), config.url, 0); // Send a copy
+        sendLogs(logs.slice(0), config, 0); // Send a copy
         logs.splice(0); // Clear array reference (no reassignment)
       }
     }, config.transmitInterval);
@@ -521,7 +521,7 @@ var userale = (function (exports) {
       return;
     }
     if (logs.length > 0) {
-      sendLogs(logs, config.url, 1);
+      sendLogs(logs, config, 1);
     }
   }
 
@@ -542,7 +542,7 @@ var userale = (function (exports) {
     } else {
       window.addEventListener('beforeunload', function() {
         if (logs.length > 0) {
-          sendLogs(logs, config.url, 1);
+          sendLogs(logs, config, 1);
         }
       });
     }
@@ -552,26 +552,28 @@ var userale = (function (exports) {
    * Sends the provided array of logs to the specified url,
    * retrying the request up to the specified number of retries.
    * @param  {Array} logs    Array of logs to send.
-   * @param  {string} url     URL to send the POST request to.
+   * @param  {string} config     configuration parameters (e.g., to extract URL from & send the POST request to).
    * @param  {Number} retries Maximum number of attempts to send the logs.
    */
-  function sendLogs(logs, url, retries) {
+
+  // @todo expose config object to sendLogs replate url with config.url
+  function sendLogs(logs, config, retries) {
     var req = new XMLHttpRequest();
 
     // @todo setRequestHeader for Auth
     var data = JSON.stringify(logs);
 
-    req.open('POST', url);
-    //if (config.authHeader) {
-    //  req.setRequestHeader('Authorization', config.authHeader)
-    //}
+    req.open('POST', config.url);
+    if (config.authHeader) {
+      req.setRequestHeader('Authorization', config.authHeader);
+    }
 
     req.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
 
     req.onreadystatechange = function() {
       if (req.readyState === 4 && req.status !== 200) {
         if (retries > 0) {
-          sendLogs(logs, url, retries--);
+          sendLogs(logs, config, retries--);
         }
       }
     };
diff --git a/build/userale-2.0.2.min.js b/build/userale-2.0.2.min.js
index fcefba3..2d6fe76 100644
--- a/build/userale-2.0.2.min.js
+++ b/build/userale-2.0.2.min.js
@@ -15,4 +15,4 @@
  * limitations under the License.
  * @preserved
  */
-var userale=function(n){"use strict";var a,i,u,l,s,c,d,f,t="2.0.2",r=null;function e(n,o){Object.keys(o).forEach(function(t){if("userFromParams"===t){var e=function(t){var e=new RegExp("[?&]"+t+"(=([^&#]*)|&|#|$)"),n=window.location.href.match(e);return n&&n[2]?decodeURIComponent(n[2].replace(/\+/g," ")):null}(o[t]);e&&(n.userId=e)}n[t]=o[t]})}var m=null,p=null;function o(t,e){if(!i.on)return!1;var n=null;e&&(n=e(t));var o=function(t){return{milli:Math.floor(t),micro:Number((t%1).toFixed [...]
\ No newline at end of file
+var userale=function(n){"use strict";var a,i,u,l,s,c,d,f,t="2.0.2",r=null;function e(n,o){Object.keys(o).forEach(function(t){if("userFromParams"===t){var e=function(t){var e=new RegExp("[?&]"+t+"(=([^&#]*)|&|#|$)"),n=window.location.href.match(e);return n&&n[2]?decodeURIComponent(n[2].replace(/\+/g," ")):null}(o[t]);e&&(n.userId=e)}n[t]=o[t]})}var m=null,p=null;function o(t,e){if(!i.on)return!1;var n=null;e&&(n=e(t));var o=function(t){return{milli:Math.floor(t),micro:Number((t%1).toFixed [...]
\ No newline at end of file
diff --git a/src/getInitialSettings.js b/src/getInitialSettings.js
index 2514ce2..e96835a 100644
--- a/src/getInitialSettings.js
+++ b/src/getInitialSettings.js
@@ -48,7 +48,7 @@ export function getInitialSettings() {
   settings.userFromParams = get('data-user-from-params') || null;
   settings.time = timeStampScale(document.createEvent('CustomEvent'));
   settings.sessionID = get('data-session') || sessionId;
-//  settings.authHeader = get ('data-auth') || null;
+  settings.authHeader = get ('data-auth') || null;
 
   return settings;
 }
diff --git a/src/sendLogs.js b/src/sendLogs.js
index bd1579c..da43180 100644
--- a/src/sendLogs.js
+++ b/src/sendLogs.js
@@ -45,7 +45,7 @@ export function sendOnInterval(logs, config) {
     }
 
     if (logs.length >= config.logCountThreshold) {
-      sendLogs(logs.slice(0), config.url, 0); // Send a copy
+      sendLogs(logs.slice(0), config, 0); // Send a copy
       logs.splice(0); // Clear array reference (no reassignment)
     }
   }, config.transmitInterval);
@@ -65,7 +65,7 @@ export function sendOnRefresh(logs, config) {
     return;
   }
   if (logs.length > 0) {
-    sendLogs(logs, config.url, 1);
+    sendLogs(logs, config, 1);
   }
 }
 
@@ -86,7 +86,7 @@ export function sendOnClose(logs, config) {
   } else {
     window.addEventListener('beforeunload', function() {
       if (logs.length > 0) {
-        sendLogs(logs, config.url, 1);
+        sendLogs(logs, config, 1);
       }
     })
   }
@@ -96,28 +96,28 @@ export function sendOnClose(logs, config) {
  * Sends the provided array of logs to the specified url,
  * retrying the request up to the specified number of retries.
  * @param  {Array} logs    Array of logs to send.
- * @param  {string} url     URL to send the POST request to.
+ * @param  {string} config     configuration parameters (e.g., to extract URL from & send the POST request to).
  * @param  {Number} retries Maximum number of attempts to send the logs.
  */
 
 // @todo expose config object to sendLogs replate url with config.url
-export function sendLogs(logs, url, retries) {
+export function sendLogs(logs, config, retries) {
   var req = new XMLHttpRequest();
 
   // @todo setRequestHeader for Auth
   var data = JSON.stringify(logs);
 
-  req.open('POST', url);
-  //if (config.authHeader) {
-  //  req.setRequestHeader('Authorization', config.authHeader)
-  //}
+  req.open('POST', config.url);
+  if (config.authHeader) {
+    req.setRequestHeader('Authorization', config.authHeader)
+  }
 
   req.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
 
   req.onreadystatechange = function() {
     if (req.readyState === 4 && req.status !== 200) {
       if (retries > 0) {
-        sendLogs(logs, url, retries--);
+        sendLogs(logs, config, retries--);
       }
     }
   };
diff --git a/test/main_spec.js b/test/main_spec.js
index f66953a..3240825 100644
--- a/test/main_spec.js
+++ b/test/main_spec.js
@@ -47,6 +47,7 @@ describe('Userale API', () => {
         'toolName',
         'userFromParams',
         'time',
+        'authHeader',
       ]);
       window.close();
       done();