From 0e1159d3c28ea7f2bee210aaa51792812ab3919f Mon Sep 17 00:00:00 2001 From: Rufus Knight Date: Mon, 12 Feb 2024 15:29:22 -0500 Subject: [PATCH 1/4] Code changes for toolName and toolVersion constraints --- example/index.js | 1 + src/UserALEWebExtension/background.js | 9 +++++++++ src/UserALEWebExtension/options.js | 4 ++-- src/getInitialSettings.js | 11 ++++++++++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/example/index.js b/example/index.js index 44bb1e27..9139c3cb 100644 --- a/example/index.js +++ b/example/index.js @@ -22,6 +22,7 @@ const changeMe = "me"; window.userale.options({ 'userId': changeMe, 'logDetails': true, + 'toolVersion': '2.3.0', 'toolName': 'Apache UserALE.js Example (Custom)' }); diff --git a/src/UserALEWebExtension/background.js b/src/UserALEWebExtension/background.js index 90160ad7..09276e17 100644 --- a/src/UserALEWebExtension/background.js +++ b/src/UserALEWebExtension/background.js @@ -30,6 +30,7 @@ const defaultConfig = { userId: 'pluginUser', authHeader: null, toolName: 'useralePlugin', + toolVersion: '2.4.0', version: userale.version, }, pluginConfig: { @@ -41,6 +42,14 @@ const defaultConfig = { var urlWhitelist; function updateConfig(config) { + if ((config.toolName || "") === "") { + throw "Please set the tool name before use."; + } + + if ((config.toolVersion || "") === "") { + throw "Please set the app version before use."; + } + urlWhitelist = new RegExp(config.pluginConfig.urlWhitelist); userale.options(config.useraleConfig); // TODO: tabs need a page load to apply this config change. diff --git a/src/UserALEWebExtension/options.js b/src/UserALEWebExtension/options.js index caa442a6..4feb7b95 100644 --- a/src/UserALEWebExtension/options.js +++ b/src/UserALEWebExtension/options.js @@ -30,7 +30,7 @@ function setConfig() { url: document.getElementById("url").value, userId: document.getElementById("user").value, toolName: document.getElementById("tool").value, - version: document.getElementById("version").value + toolVersion: document.getElementById("version").value }; // Set a basic auth header if given credentials. @@ -58,7 +58,7 @@ function getConfig() { document.getElementById("url").value = config.url; document.getElementById("user").value = config.userId; document.getElementById("tool").value = config.toolName; - document.getElementById("version").value = config.version; + document.getElementById("version").value = config.toolVersion; }); browser.storage.local.get("pluginConfig", (res) => { document.getElementById("filter").value = res.pluginConfig.urlWhitelist; diff --git a/src/getInitialSettings.js b/src/getInitialSettings.js index b9624ebe..aad90ab8 100644 --- a/src/getInitialSettings.js +++ b/src/getInitialSettings.js @@ -42,7 +42,7 @@ export function getInitialSettings() { settings.transmitInterval = +get('data-interval') || 5000; settings.logCountThreshold = +get('data-threshold') || 5; settings.userId = get('data-user') || null; - settings.version = get('data-version') || null; + settings.toolVersion = get('data-version') || null; settings.logDetails = get('data-log-details') === 'true' ? true : false; settings.resolution = +get('data-resolution') || 500; settings.toolName = get('data-tool') || null; @@ -52,6 +52,15 @@ export function getInitialSettings() { settings.authHeader = get('data-auth') || null; settings.custIndex = get('data-index') || null; settings.headers = get('data-headers') || null; + + if ((settings.toolName || "") === "") { + throw "Please set the tool name before use."; + } + + if ((settings.toolVersion || "") === "") { + throw "Please set the app version before use."; + } + return settings; } From 7953036ffa7f6839978b7f3f24794148b3224891 Mon Sep 17 00:00:00 2001 From: Rufus Knight Date: Mon, 12 Feb 2024 15:52:20 -0500 Subject: [PATCH 2/4] Minor js changes --- src/UserALEWebExtension/background.js | 4 ++-- src/getInitialSettings.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/UserALEWebExtension/background.js b/src/UserALEWebExtension/background.js index 09276e17..a01a3fee 100644 --- a/src/UserALEWebExtension/background.js +++ b/src/UserALEWebExtension/background.js @@ -42,11 +42,11 @@ const defaultConfig = { var urlWhitelist; function updateConfig(config) { - if ((config.toolName || "") === "") { + if (!config.toolName) { throw "Please set the tool name before use."; } - if ((config.toolVersion || "") === "") { + if (!config.toolVersion) { throw "Please set the app version before use."; } diff --git a/src/getInitialSettings.js b/src/getInitialSettings.js index aad90ab8..44b7c69b 100644 --- a/src/getInitialSettings.js +++ b/src/getInitialSettings.js @@ -53,11 +53,11 @@ export function getInitialSettings() { settings.custIndex = get('data-index') || null; settings.headers = get('data-headers') || null; - if ((settings.toolName || "") === "") { + if (!settings.toolName) { throw "Please set the tool name before use."; } - if ((settings.toolVersion || "") === "") { + if (!settings.toolVersion) { throw "Please set the app version before use."; } From fa8c00113d5608458f90c6ad9e5b56478449b278 Mon Sep 17 00:00:00 2001 From: Rufus Knight Date: Mon, 12 Feb 2024 16:30:11 -0500 Subject: [PATCH 3/4] Fixed test fixtures --- test/getInitialSettings_spec.js | 2 +- test/getInitialSettings_userParam.html | 2 ++ test/main.html | 2 +- test/main_spec.js | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/test/getInitialSettings_spec.js b/test/getInitialSettings_spec.js index ec128077..ebf0f33c 100644 --- a/test/getInitialSettings_spec.js +++ b/test/getInitialSettings_spec.js @@ -68,7 +68,7 @@ describe('getInitialSettings', () => { expect(config).to.have.property('transmitInterval', 100); expect(config).to.have.property('logCountThreshold', 10); expect(config).to.have.property('userId', 'testuser'); - expect(config).to.have.property('version', '1.0.0'); + expect(config).to.have.property('toolVersion', '1.0.0'); expect(config).to.have.property('logDetails', false); expect(config).to.have.property('resolution', 100); expect(config).to.have.property('toolName', 'testtool'); diff --git a/test/getInitialSettings_userParam.html b/test/getInitialSettings_userParam.html index f3314086..0ab2b25b 100644 --- a/test/getInitialSettings_userParam.html +++ b/test/getInitialSettings_userParam.html @@ -18,6 +18,8 @@ diff --git a/test/main.html b/test/main.html index 539c3203..eb8d1426 100644 --- a/test/main.html +++ b/test/main.html @@ -17,7 +17,7 @@ - + diff --git a/test/main_spec.js b/test/main_spec.js index 5bc045ab..efed001b 100644 --- a/test/main_spec.js +++ b/test/main_spec.js @@ -32,7 +32,7 @@ describe('Userale API', () => { 'logCountThreshold', 'userId', 'sessionID', - 'version', + 'toolVersion', 'logDetails', 'resolution', 'toolName', From 5b4f6637c3c4d5c0e132f6e8c5c1e34bc783578b Mon Sep 17 00:00:00 2001 From: Rufus Knight Date: Mon, 12 Feb 2024 17:07:59 -0500 Subject: [PATCH 4/4] version => toolVersion fixes --- README.md | 2 +- example/custom-non-user-events-example/index.js | 2 ++ example/index.js | 2 +- example/webpackUserAleExample/index.js | 4 ++-- src/packageLogs.js | 6 +++--- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ae4e83ee..3023d5ea 100644 --- a/README.md +++ b/README.md @@ -249,7 +249,7 @@ document.addEventListener('change', function(e) { customField1: 'foo', customField2: 'bar', userId: userale.options().userId, - toolVersion: userale.options().version, + toolVersion: userale.options().toolVersion, toolName: userale.options().toolName, useraleVersion: userale.options().useraleVersion, sessionID: userale.options().sessionID, diff --git a/example/custom-non-user-events-example/index.js b/example/custom-non-user-events-example/index.js index 252361e8..76008021 100644 --- a/example/custom-non-user-events-example/index.js +++ b/example/custom-non-user-events-example/index.js @@ -77,6 +77,8 @@ function getData(url, resolve) { userAction: 'false', details: JSON.parse(req.response), userId: userale.options().userId, + toolVersion: userale.options().toolVersion, + toolName: userale.options().toolName, useraleVersion: userale.options().useraleVersion, sessionID: userale.options().sessionID, traceId: trace.getSpan(context.active())._spanContext.traceId diff --git a/example/index.js b/example/index.js index 9139c3cb..91f4462a 100644 --- a/example/index.js +++ b/example/index.js @@ -101,7 +101,7 @@ document.addEventListener('change', function(e) { customField1: 'I can make this log look like anything I want', customField2: 'foo', userId: window.userale.options().userId, - toolVersion: window.userale.options().version, + toolVersion: window.userale.options().toolVersion, toolName: window.userale.options().toolName, useraleVersion: window.userale.options().useraleVersion, sessionID: window.userale.options().sessionID, diff --git a/example/webpackUserAleExample/index.js b/example/webpackUserAleExample/index.js index e41fbdd5..d13d4819 100644 --- a/example/webpackUserAleExample/index.js +++ b/example/webpackUserAleExample/index.js @@ -30,7 +30,7 @@ const changeMe = "me"; userale.options({ 'userId': changeMe, 'url': 'http://localhost:8000/', - 'version': '2.3.0', + 'toolVersion': '2.3.0', 'logDetails': true, 'toolName': 'Apache UserALE.js Example (Custom)', 'logCountThreshold': '1', @@ -112,7 +112,7 @@ document.addEventListener('change', function(e) { customField1: 'I can make this log look like anything I want', customField2: 'foo', userId: userale.options().userId, - toolVersion: userale.options().version, + toolVersion: userale.options().toolVersion, toolName: userale.options().toolName, useraleVersion: userale.options().useraleVersion, sessionID: userale.options().sessionID, diff --git a/src/packageLogs.js b/src/packageLogs.js index 637a986d..15d31ec4 100644 --- a/src/packageLogs.js +++ b/src/packageLogs.js @@ -140,7 +140,7 @@ export function packageLog(e, detailFcn) { 'userAction' : true, 'details' : details, 'userId' : config.userId, - 'toolVersion' : config.version, + 'toolVersion' : config.toolVersion, 'toolName' : config.toolName, 'useraleVersion': config.useraleVersion, 'sessionID': config.sessionID, @@ -195,7 +195,7 @@ export function packageCustomLog(customLog, detailFcn, userAction) { 'userAction' : userAction, 'details' : details, 'userId' : config.userId, - 'toolVersion' : config.version, + 'toolVersion' : config.toolVersion, 'toolName' : config.toolName, 'useraleVersion': config.useraleVersion, 'sessionID': config.sessionID @@ -279,7 +279,7 @@ export function packageIntervalLog(e) { 'typeChange': intervalType !== type, 'userAction': false, 'userId': config.userId, - 'toolVersion': config.version, + 'toolVersion': config.toolVersion, 'toolName': config.toolName, 'useraleVersion': config.useraleVersion, 'sessionID': config.sessionID