Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code changes for toolName and toolVersion constraints #411

Open
wants to merge 4 commits into
base: test
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions example/custom-non-user-events-example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const changeMe = "me";
window.userale.options({
'userId': changeMe,
'logDetails': true,
'toolVersion': '2.3.0',
'toolName': 'Apache UserALE.js Example (Custom)'
});

Expand Down Expand Up @@ -100,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,
Expand Down
4 changes: 2 additions & 2 deletions example/webpackUserAleExample/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions src/UserALEWebExtension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const defaultConfig = {
userId: 'pluginUser',
authHeader: null,
toolName: 'useralePlugin',
toolVersion: '2.4.0',
version: userale.version,
},
pluginConfig: {
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/UserALEWebExtension/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion src/getInitialSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is where I was referencing changing the script tag to match the setting name.

so it'd be:
get('data-tool-version')

This is a breaking change, because it changes the script-tag api. And since toolVersion is required, the script would throw if users did not set this field.

We should add a default besides null to keep it from breaking (e.g. '1.0').

settings.logDetails = get('data-log-details') === 'true' ? true : false;
settings.resolution = +get('data-resolution') || 500;
settings.toolName = get('data-tool') || null;
Expand All @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions src/packageLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/getInitialSettings_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 2 additions & 0 deletions test/getInitialSettings_userParam.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<html>
<head>
<script data-user-from-params='user'
data-version='1.0.0'
data-tool='testtool'
src="../build/userale-2.4.0.min.js">
</script>
</head>
Expand Down
2 changes: 1 addition & 1 deletion test/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<!DOCTYPE HTML>
<html>
<head>
<script src="../build/userale-2.4.0.min.js"></script>
<script src="../build/userale-2.4.0.min.js" data-version='1.0.0' data-tool='testtool'></script>
</head>

<body>
Expand Down
2 changes: 1 addition & 1 deletion test/main_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Userale API', () => {
'logCountThreshold',
'userId',
'sessionID',
'version',
'toolVersion',
'logDetails',
'resolution',
'toolName',
Expand Down
Loading