Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.

Commit 1a643a4

Browse files
authored
Merge pull request #403 from UMD-ARLIS/jsonschema
Jsonschema
2 parents 053590e + d4469e3 commit 1a643a4

File tree

8 files changed

+160
-5
lines changed

8 files changed

+160
-5
lines changed

build/UserALEWebExtension/content.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,6 @@ function setup(config) {
10831083
started = config.on = true;
10841084
packageCustomLog({
10851085
type: 'load',
1086-
logType: 'raw',
10871086
details: {
10881087
pageLoadTime: endLoadTimestamp - startLoadTimestamp
10891088
}

build/userale-2.4.0.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,6 @@
12181218
exports.started = config.on = true;
12191219
packageCustomLog({
12201220
type: 'load',
1221-
logType: 'raw',
12221221
details: {
12231222
pageLoadTime: endLoadTimestamp - startLoadTimestamp
12241223
}

build/userale-2.4.0.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/log.schema.json

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://flagon.incubator.apache.org/log.schema.json",
4+
"title": "Log",
5+
"description": "A raw or custom log produced by userale",
6+
"type": "object",
7+
"properties": {
8+
"target": {
9+
"type": "string"
10+
},
11+
"path": {
12+
"type": "array",
13+
"items": {
14+
"type": "string"
15+
},
16+
"minItems": 1
17+
},
18+
"pageUrl": {
19+
"type": "string"
20+
},
21+
"pageTitle": {
22+
"type": "string"
23+
},
24+
"browser": {
25+
"type": "object",
26+
"properties": {
27+
"browser": {
28+
"type": "string"
29+
},
30+
"version": {
31+
"type": "string"
32+
}
33+
},
34+
"required" : ["browser", "version"]
35+
},
36+
"clientTime": {
37+
"type": "integer"
38+
},
39+
"microTime": {
40+
"type": "number",
41+
"minimum": 0,
42+
"maxmaximumi": 1
43+
},
44+
"location": {
45+
"type": "object",
46+
"properties": {
47+
"x": {
48+
"type": ["integer", "null"]
49+
},
50+
"y": {
51+
"type": ["integer", "null"]
52+
}
53+
},
54+
"required" : ["x", "y"]
55+
},
56+
"scrnRes": {
57+
"type": "object",
58+
"properties": {
59+
"height": {
60+
"type": "integer"
61+
},
62+
"width": {
63+
"type": "integer"
64+
}
65+
},
66+
"required" : ["height", "width"]
67+
},
68+
"type": {
69+
"type": "string"
70+
},
71+
"logType": {
72+
"type": "string",
73+
"enum": ["raw", "custom"]
74+
},
75+
"userAction": {
76+
"type": "boolean"
77+
},
78+
"details": {
79+
"type": "object"
80+
},
81+
"userId": {
82+
"type": "string"
83+
},
84+
"toolVersion": {
85+
"type": "string"
86+
},
87+
"toolName": {
88+
"type": "string"
89+
},
90+
"useraleVersion": {
91+
"type": "string"
92+
},
93+
"sessionID": {
94+
"type": "string"
95+
}
96+
},
97+
"required": [
98+
"pageUrl",
99+
"pageTitle",
100+
"pageReferrer",
101+
"browser",
102+
"clientTime",
103+
"scrnRes",
104+
"logType",
105+
"userAction",
106+
"details",
107+
"userId",
108+
"toolVersion",
109+
"toolName",
110+
"useraleVersion",
111+
"sessionID"
112+
],
113+
"if": {
114+
"properties": { "logType": { "const": "raw" } }
115+
},
116+
"then": {
117+
"required": [
118+
"target",
119+
"path",
120+
"microTime",
121+
"location",
122+
"type"
123+
]
124+
}
125+
}

journey/userale.journey.cy.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
import { validate } from 'jsonschema';
18+
1719
describe('Userale logging', () => {
1820
beforeEach(() => {
1921
cy.intercept('POST', 'http://localhost:8000/').as('backend')
@@ -26,7 +28,7 @@ describe('Userale logging', () => {
2628
const pageLoadLog = body[0]
2729
expect(pageLoadLog['details']['pageLoadTime']).to.be.greaterThan(0)
2830
expect(pageLoadLog).to.contain({
29-
logType: 'raw',
31+
logType: 'custom',
3032
type: 'load'
3133
})
3234
})
@@ -62,4 +64,24 @@ describe('Userale logging', () => {
6264
expect(actualValue).to.equal(expectedValue)
6365
})
6466
});
67+
68+
it('produces valid logs', () => {
69+
cy.visit('http://localhost:8000');
70+
cy.wait('@backend').then(xhr => {
71+
var schema = require('../example/log.schema.json');
72+
for(const log of xhr.request.body) {
73+
const result = validate(log, schema);
74+
expect(result.valid, result.errors).to.equal(true);
75+
}
76+
})
77+
cy.contains(/click me/i).click();
78+
cy.wait('@backend').then(xhr => {
79+
var schema = require('../example/log.schema.json');
80+
for(const log of xhr.request.body) {
81+
const result = validate(log, schema);
82+
expect(result.valid, result.errors).to.equal(true);
83+
}
84+
})
85+
});
86+
6587
});

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"express": "^4.18.2",
7070
"global-jsdom": "^9.1.0",
7171
"jsdom": "^22.1.0",
72+
"jsonschema": "^1.4.1",
7273
"mocha": "^10.2.0",
7374
"nodemon": "^3.0.2",
7475
"rollup": "^4.6.1",

src/main.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ function setup(config) {
7070
started = config.on = true;
7171
packageCustomLog({
7272
type: 'load',
73-
logType: 'raw',
7473
details: {pageLoadTime: endLoadTimestamp - startLoadTimestamp}
7574
}, () => {},false)
7675
} else {

0 commit comments

Comments
 (0)