@opentermsarchive/engine 7.2.0 → 7.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. package/package.json +2 -2
  2. package/scripts/declarations/validate/definitions.js +1 -1
  3. package/scripts/declarations/validate/fixtures/invalid/additional-properties.json +10 -0
  4. package/scripts/declarations/validate/fixtures/invalid/invalid-filter-object.json +17 -0
  5. package/scripts/declarations/validate/fixtures/invalid/invalid-terms-type.json +9 -0
  6. package/scripts/declarations/validate/fixtures/invalid/invalid-url.json +9 -0
  7. package/scripts/declarations/validate/fixtures/invalid/missing-fetch.json +8 -0
  8. package/scripts/declarations/validate/fixtures/invalid/missing-name.json +8 -0
  9. package/scripts/declarations/validate/fixtures/invalid/missing-select.json +8 -0
  10. package/scripts/declarations/validate/fixtures/invalid/missing-terms.json +3 -0
  11. package/scripts/declarations/validate/fixtures/invalid/non-pdf-url-for-pdf.json +8 -0
  12. package/scripts/declarations/validate/fixtures/invalid-history/invalid-date.json +9 -0
  13. package/scripts/declarations/validate/fixtures/invalid-history/missing-valid-until.json +8 -0
  14. package/scripts/declarations/validate/fixtures/valid/complex-service.json +30 -0
  15. package/scripts/declarations/validate/fixtures/valid/minimal-service.json +9 -0
  16. package/scripts/declarations/validate/fixtures/valid/multiple-source-documents.json +24 -0
  17. package/scripts/declarations/validate/fixtures/valid/pdf-document.json +8 -0
  18. package/scripts/declarations/validate/fixtures/valid/range-selectors.json +19 -0
  19. package/scripts/declarations/validate/fixtures/valid/service-with-filters.json +22 -0
  20. package/scripts/declarations/validate/fixtures/valid-history/pdf-history.json +8 -0
  21. package/scripts/declarations/validate/fixtures/valid-history/simple-history.json +9 -0
  22. package/scripts/declarations/validate/schemas.test.js +84 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentermsarchive/engine",
3
- "version": "7.2.0",
3
+ "version": "7.2.2",
4
4
  "description": "Tracks and makes visible changes to the terms of online services",
5
5
  "homepage": "https://opentermsarchive.org",
6
6
  "bugs": {
@@ -63,7 +63,7 @@
63
63
  "chai-as-promised": "^7.1.1",
64
64
  "chai-exclude": "^2.1.0",
65
65
  "commander": "^9.4.1",
66
- "config": "^3.3.6",
66
+ "config": "^4.1.1",
67
67
  "croner": "^8.0.2",
68
68
  "cronstrue": "^2.50.0",
69
69
  "cross-env": "^7.0.3",
@@ -38,7 +38,7 @@ const definitions = {
38
38
  {
39
39
  type: 'object',
40
40
  description: 'Filter function with parameters. The key is the filter function name, the value is the parameters.',
41
- additionalProperties: false,
41
+ additionalProperties: true,
42
42
  minProperties: 1,
43
43
  maxProperties: 1,
44
44
  },
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "Service with additional properties",
3
+ "terms": {
4
+ "Privacy Policy": {
5
+ "fetch": "https://example.com/privacy",
6
+ "select": "div.content"
7
+ }
8
+ },
9
+ "unexpectedProperty": "value"
10
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "Service with invalid filter object",
3
+ "terms": {
4
+ "Privacy Policy": {
5
+ "fetch": "https://example.com/privacy",
6
+ "select": "div.content",
7
+ "filter": [
8
+ {
9
+ "filterName": {
10
+ "param": "value"
11
+ },
12
+ "unexpectedAdditionalProperty": "value"
13
+ }
14
+ ]
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "Service with invalid terms type",
3
+ "terms": {
4
+ "Invalid Terms Type": {
5
+ "fetch": "https://example.com/privacy",
6
+ "select": "div.content"
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "Service with invalid URL",
3
+ "terms": {
4
+ "Privacy Policy": {
5
+ "fetch": "not-a-valid-url",
6
+ "select": "div.content"
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "Service without fetch",
3
+ "terms": {
4
+ "Privacy Policy": {
5
+ "select": "div.content"
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "terms": {
3
+ "Privacy Policy": {
4
+ "fetch": "https://example.com/privacy",
5
+ "select": "div.content"
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "Service without select",
3
+ "terms": {
4
+ "Privacy Policy": {
5
+ "fetch": "https://example.com/privacy"
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "name": "Service without terms"
3
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "Service with non-PDF URL for PDF document",
3
+ "terms": {
4
+ "Privacy Policy": {
5
+ "fetch": "https://example.com/privacy.html"
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "Privacy Policy": [
3
+ {
4
+ "fetch": "https://example.com/privacy",
5
+ "select": "div.content",
6
+ "validUntil": "2023-12-31"
7
+ }
8
+ ]
9
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "Privacy Policy": [
3
+ {
4
+ "fetch": "https://example.com/privacy",
5
+ "select": "div.content"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "Complex service",
3
+ "terms": {
4
+ "Privacy Policy": {
5
+ "fetch": "https://example.com/privacy",
6
+ "select": [
7
+ "div.content",
8
+ ".privacy-section"
9
+ ],
10
+ "filter": [
11
+ "removeLinks",
12
+ {
13
+ "customTransform": {
14
+ "options": {
15
+ "cleanup": true
16
+ }
17
+ }
18
+ }
19
+ ],
20
+ "remove": [
21
+ ".ads",
22
+ ".tracking"
23
+ ],
24
+ "executeClientScripts": true
25
+ },
26
+ "Terms of Service": {
27
+ "fetch": "https://example.com/terms.pdf"
28
+ }
29
+ }
30
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "Minimal service",
3
+ "terms": {
4
+ "Privacy Policy": {
5
+ "fetch": "https://example.com/privacy",
6
+ "select": "div.content"
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "Multiple source documents service",
3
+ "terms": {
4
+ "Privacy Policy": {
5
+ "combine": [
6
+ {
7
+ "fetch": "https://example.com/privacy1",
8
+ "select": "div.content",
9
+ "filter": [
10
+ "removeLinks"
11
+ ]
12
+ },
13
+ {
14
+ "fetch": "https://example.com/privacy2",
15
+ "select": ".privacy-section"
16
+ }
17
+ ],
18
+ "select": "body",
19
+ "filter": [
20
+ "trimWhitespace"
21
+ ]
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "Service with PDF terms",
3
+ "terms": {
4
+ "Privacy Policy": {
5
+ "fetch": "https://example.com/privacy.pdf"
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "Service with range selectors",
3
+ "terms": {
4
+ "Privacy Policy": {
5
+ "fetch": "https://example.com/privacy",
6
+ "select": [
7
+ "div.content",
8
+ {
9
+ "startBefore": "h1",
10
+ "endAfter": "footer"
11
+ },
12
+ {
13
+ "startAfter": "h2",
14
+ "endBefore": ".end-marker"
15
+ }
16
+ ]
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "Service with filters",
3
+ "terms": {
4
+ "Privacy Policy": {
5
+ "fetch": "https://example.com/privacy",
6
+ "select": "div.content",
7
+ "filter": [
8
+ "removeLinks",
9
+ {
10
+ "customFilter": {
11
+ "param": "value"
12
+ }
13
+ },
14
+ {
15
+ "anotherFilter": {
16
+ "setting": true
17
+ }
18
+ }
19
+ ]
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "Privacy Policy": [
3
+ {
4
+ "fetch": "https://example.com/privacy.pdf",
5
+ "validUntil": "2023-12-31T23:59:59Z"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "Privacy Policy": [
3
+ {
4
+ "fetch": "https://example.com/privacy",
5
+ "select": "div.content",
6
+ "validUntil": "2023-12-31T23:59:59Z"
7
+ }
8
+ ]
9
+ }
@@ -0,0 +1,84 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+
5
+ import Ajv from 'ajv';
6
+ import addFormats from 'ajv-formats';
7
+ import { expect } from 'chai';
8
+
9
+ import serviceHistorySchema from './service.history.schema.js';
10
+ import serviceSchema from './service.schema.js';
11
+
12
+ describe('Schema validation', () => {
13
+ let validator;
14
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
15
+ const fixturesDir = path.join(__dirname, 'fixtures');
16
+
17
+ before(() => {
18
+ validator = new Ajv({ allErrors: true });
19
+ addFormats(validator);
20
+ });
21
+
22
+ const loadFixture = filePath => {
23
+ const content = fs.readFileSync(filePath, 'utf8');
24
+
25
+ return JSON.parse(content);
26
+ };
27
+
28
+ const getJsonFiles = dir => {
29
+ const files = fs.readdirSync(dir);
30
+
31
+ return files.filter(file => file.endsWith('.json'));
32
+ };
33
+
34
+ const validateDeclaration = (schema, declaration, file, shouldBeValid) => {
35
+ const valid = validator.validate(schema, declaration);
36
+
37
+ if (!valid && shouldBeValid) {
38
+ console.error(`Validation errors for ${file}:`, validator.errors);
39
+ }
40
+
41
+ return valid;
42
+ };
43
+
44
+ const createValidationTests = (schema, directory, shouldBeValid) => {
45
+ const files = getJsonFiles(directory);
46
+ const action = shouldBeValid ? 'validates' : 'rejects';
47
+
48
+ files.forEach(file => {
49
+ it(`${action} ${file}`, () => {
50
+ const filePath = path.join(directory, file);
51
+ const declaration = loadFixture(filePath);
52
+ const valid = validateDeclaration(schema, declaration, file, shouldBeValid);
53
+
54
+ expect(valid, `${file} should be ${shouldBeValid ? 'valid' : 'invalid'}`).to.equal(shouldBeValid);
55
+ });
56
+ });
57
+ };
58
+
59
+ describe('Service schema', () => {
60
+ const validDir = path.join(fixturesDir, 'valid');
61
+ const invalidDir = path.join(fixturesDir, 'invalid');
62
+
63
+ describe('with valid declarations', () => {
64
+ createValidationTests(serviceSchema, validDir, true);
65
+ });
66
+
67
+ describe('with invalid declarations', () => {
68
+ createValidationTests(serviceSchema, invalidDir, false);
69
+ });
70
+ });
71
+
72
+ describe('Service history schema', () => {
73
+ const validHistoryDir = path.join(fixturesDir, 'valid-history');
74
+ const invalidHistoryDir = path.join(fixturesDir, 'invalid-history');
75
+
76
+ describe('with valid history declarations', () => {
77
+ createValidationTests(serviceHistorySchema, validHistoryDir, true);
78
+ });
79
+
80
+ describe('with invalid history declarations', () => {
81
+ createValidationTests(serviceHistorySchema, invalidHistoryDir, false);
82
+ });
83
+ });
84
+ });