Skip to content

Commit f25a9ad

Browse files
committed
Split generate-rule-schema out of rule-syntax-check
1 parent 7e7c6f6 commit f25a9ad

File tree

6 files changed

+360
-15
lines changed

6 files changed

+360
-15
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ package-lock.json
66
addon/manifest.*.json
77
**/*.md
88
**/*.har
9+
rules/schema.json

lib/rules.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { snippets } from './eval-snippets';
33

44
export type AutoConsentCMPRule = {
5+
$schema?: string;
56
name: string;
67
vendorUrl?: string;
78
prehideSelectors?: string[];

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"clean": "rm -r dist",
2121
"lint": "eslint . && prettier . --check && npm run rule-syntax-check",
2222
"bundle": "./build.sh",
23-
"rule-syntax-check": "node scripts/validate-json-rules.js",
23+
"generate-rule-schema": "node scripts/generate-rule-schema.mjs",
24+
"rule-syntax-check": "npm run generate-rule-schema && node scripts/validate-json-rules.js",
2425
"watch": "npm run prepublish && chokidar \"lib\" \"addon\" \"rules/autoconsent\" \"rules/filterlist.txt\" --ignore 'lib/filterlist-engine.ts' -c \"npm run prepublish\"",
2526
"create-rule": "node rules/create-rule.mjs",
2627
"test": "playwright test",

rules/schema.json

Lines changed: 333 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,333 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$ref": "#/definitions/AutoConsentCMPRule",
4+
"definitions": {
5+
"AutoConsentCMPRule": {
6+
"type": "object",
7+
"properties": {
8+
"name": {
9+
"type": "string"
10+
},
11+
"vendorUrl": {
12+
"type": "string"
13+
},
14+
"prehideSelectors": {
15+
"type": "array",
16+
"items": {
17+
"type": "string"
18+
}
19+
},
20+
"runContext": {
21+
"$ref": "#/definitions/RunContext"
22+
},
23+
"intermediate": {
24+
"type": "boolean"
25+
},
26+
"cosmetic": {
27+
"type": "boolean"
28+
},
29+
"detectCmp": {
30+
"type": "array",
31+
"items": {
32+
"$ref": "#/definitions/AutoConsentRuleStep"
33+
}
34+
},
35+
"detectPopup": {
36+
"type": "array",
37+
"items": {
38+
"$ref": "#/definitions/AutoConsentRuleStep"
39+
}
40+
},
41+
"optOut": {
42+
"type": "array",
43+
"items": {
44+
"$ref": "#/definitions/AutoConsentRuleStep"
45+
}
46+
},
47+
"optIn": {
48+
"type": "array",
49+
"items": {
50+
"$ref": "#/definitions/AutoConsentRuleStep"
51+
}
52+
},
53+
"openCmp": {
54+
"type": "array",
55+
"items": {
56+
"$ref": "#/definitions/AutoConsentRuleStep"
57+
}
58+
},
59+
"test": {
60+
"type": "array",
61+
"items": {
62+
"$ref": "#/definitions/AutoConsentRuleStep"
63+
}
64+
},
65+
"comment": {
66+
"type": "string"
67+
}
68+
},
69+
"required": [
70+
"name",
71+
"detectCmp",
72+
"detectPopup",
73+
"optOut",
74+
"optIn"
75+
],
76+
"additionalProperties": false
77+
},
78+
"RunContext": {
79+
"type": "object",
80+
"properties": {
81+
"main": {
82+
"type": "boolean"
83+
},
84+
"frame": {
85+
"type": "boolean"
86+
},
87+
"urlPattern": {
88+
"type": "string"
89+
}
90+
},
91+
"additionalProperties": false
92+
},
93+
"AutoConsentRuleStep": {
94+
"type": "object",
95+
"additionalProperties": false,
96+
"properties": {
97+
"any": {
98+
"type": "array",
99+
"items": {
100+
"$ref": "#/definitions/AutoConsentRuleStep"
101+
}
102+
},
103+
"if": {
104+
"type": "object",
105+
"additionalProperties": false,
106+
"properties": {
107+
"visible": {
108+
"$ref": "#/definitions/ElementSelector"
109+
},
110+
"check": {
111+
"$ref": "#/definitions/VisibilityCheck"
112+
},
113+
"exists": {
114+
"$ref": "#/definitions/ElementSelector"
115+
}
116+
}
117+
},
118+
"then": {
119+
"type": "array",
120+
"items": {
121+
"$ref": "#/definitions/AutoConsentRuleStep"
122+
}
123+
},
124+
"else": {
125+
"type": "array",
126+
"items": {
127+
"$ref": "#/definitions/AutoConsentRuleStep"
128+
}
129+
},
130+
"hide": {
131+
"type": "string"
132+
},
133+
"method": {
134+
"$ref": "#/definitions/HideMethod"
135+
},
136+
"wait": {
137+
"type": "number"
138+
},
139+
"waitForThenClick": {
140+
"$ref": "#/definitions/ElementSelector"
141+
},
142+
"timeout": {
143+
"type": "number"
144+
},
145+
"all": {
146+
"type": "boolean"
147+
},
148+
"click": {
149+
"$ref": "#/definitions/ElementSelector"
150+
},
151+
"waitForVisible": {
152+
"$ref": "#/definitions/ElementSelector"
153+
},
154+
"check": {
155+
"$ref": "#/definitions/VisibilityCheck"
156+
},
157+
"waitFor": {
158+
"$ref": "#/definitions/ElementSelector"
159+
},
160+
"eval": {
161+
"type": "string",
162+
"enum": [
163+
"EVAL_0",
164+
"EVAL_CONSENTMANAGER_1",
165+
"EVAL_CONSENTMANAGER_2",
166+
"EVAL_CONSENTMANAGER_3",
167+
"EVAL_CONSENTMANAGER_4",
168+
"EVAL_CONSENTMANAGER_5",
169+
"EVAL_COOKIEBOT_1",
170+
"EVAL_COOKIEBOT_2",
171+
"EVAL_COOKIEBOT_3",
172+
"EVAL_COOKIEBOT_4",
173+
"EVAL_COOKIEBOT_5",
174+
"EVAL_KLARO_1",
175+
"EVAL_KLARO_OPEN_POPUP",
176+
"EVAL_KLARO_TRY_API_OPT_OUT",
177+
"EVAL_ONETRUST_1",
178+
"EVAL_TRUSTARC_TOP",
179+
"EVAL_TRUSTARC_FRAME_TEST",
180+
"EVAL_TRUSTARC_FRAME_GTM",
181+
"EVAL_ABC_TEST",
182+
"EVAL_ADROLL_0",
183+
"EVAL_AFFINITY_SERIF_COM_0",
184+
"EVAL_ARBEITSAGENTUR_TEST",
185+
"EVAL_AXEPTIO_0",
186+
"EVAL_BAHN_TEST",
187+
"EVAL_BING_0",
188+
"EVAL_BLOCKSY_0",
189+
"EVAL_BORLABS_0",
190+
"EVAL_BUNDESREGIERUNG_DE_0",
191+
"EVAL_CANVA_0",
192+
"EVAL_CC_BANNER2_0",
193+
"EVAL_CLICKIO_0",
194+
"EVAL_CLINCH_0",
195+
"EVAL_COOKIECONSENT2_TEST",
196+
"EVAL_COOKIECONSENT3_TEST",
197+
"EVAL_COINBASE_0",
198+
"EVAL_COMPLIANZ_BANNER_0",
199+
"EVAL_COOKIE_LAW_INFO_0",
200+
"EVAL_COOKIE_LAW_INFO_1",
201+
"EVAL_COOKIE_LAW_INFO_DETECT",
202+
"EVAL_COOKIE_MANAGER_POPUP_0",
203+
"EVAL_COOKIEALERT_0",
204+
"EVAL_COOKIEALERT_1",
205+
"EVAL_COOKIEALERT_2",
206+
"EVAL_COOKIEFIRST_0",
207+
"EVAL_COOKIEFIRST_1",
208+
"EVAL_COOKIEINFORMATION_0",
209+
"EVAL_COOKIEINFORMATION_1",
210+
"EVAL_COOKIEINFORMATION_2",
211+
"EVAL_COOKIEYES_0",
212+
"EVAL_DAILYMOTION_0",
213+
"EVAL_DNDBEYOND_TEST",
214+
"EVAL_DSGVO_0",
215+
"EVAL_DUNELM_0",
216+
"EVAL_ETSY_0",
217+
"EVAL_ETSY_1",
218+
"EVAL_EU_COOKIE_COMPLIANCE_0",
219+
"EVAL_EU_COOKIE_LAW_0",
220+
"EVAL_EZOIC_0",
221+
"EVAL_EZOIC_1",
222+
"EVAL_FIDES_DETECT_POPUP",
223+
"EVAL_GOOGLE_0",
224+
"EVAL_GRAVITO_TEST",
225+
"EVAL_HEMA_TEST_0",
226+
"EVAL_IUBENDA_0",
227+
"EVAL_IUBENDA_1",
228+
"EVAL_IWINK_TEST",
229+
"EVAL_JQUERY_COOKIEBAR_0",
230+
"EVAL_KETCH_TEST",
231+
"EVAL_MEDIAVINE_0",
232+
"EVAL_MICROSOFT_0",
233+
"EVAL_MICROSOFT_1",
234+
"EVAL_MICROSOFT_2",
235+
"EVAL_MOOVE_0",
236+
"EVAL_ONENINETWO_0",
237+
"EVAL_OPENAI_TEST",
238+
"EVAL_OPERA_0",
239+
"EVAL_PAYPAL_0",
240+
"EVAL_PRIMEBOX_0",
241+
"EVAL_POSTNL_TEST",
242+
"EVAL_PUBTECH_0",
243+
"EVAL_REDDIT_0",
244+
"EVAL_ROBLOX_TEST",
245+
"EVAL_SHOPIFY_TEST",
246+
"EVAL_SKYSCANNER_TEST",
247+
"EVAL_SIRDATA_UNBLOCK_SCROLL",
248+
"EVAL_SNIGEL_0",
249+
"EVAL_SQUIZ_TEST",
250+
"EVAL_STEAMPOWERED_0",
251+
"EVAL_SVT_TEST",
252+
"EVAL_TAKEALOT_0",
253+
"EVAL_TARTEAUCITRON_0",
254+
"EVAL_TARTEAUCITRON_1",
255+
"EVAL_TARTEAUCITRON_2",
256+
"EVAL_TAUNTON_TEST",
257+
"EVAL_TEALIUM_0",
258+
"EVAL_TEALIUM_1",
259+
"EVAL_TEALIUM_DONOTSELL",
260+
"EVAL_TEALIUM_2",
261+
"EVAL_TEALIUM_3",
262+
"EVAL_TEALIUM_DONOTSELL_CHECK",
263+
"EVAL_TESLA_TEST",
264+
"EVAL_TESTCMP_STEP",
265+
"EVAL_TESTCMP_0",
266+
"EVAL_TESTCMP_COSMETIC_0",
267+
"EVAL_THEFREEDICTIONARY_0",
268+
"EVAL_THEFREEDICTIONARY_1",
269+
"EVAL_THEVERGE_0",
270+
"EVAL_TWCC_TEST",
271+
"EVAL_UBUNTU_COM_0",
272+
"EVAL_UK_COOKIE_CONSENT_0",
273+
"EVAL_USERCENTRICS_API_0",
274+
"EVAL_USERCENTRICS_API_1",
275+
"EVAL_USERCENTRICS_API_2",
276+
"EVAL_USERCENTRICS_API_3",
277+
"EVAL_USERCENTRICS_API_4",
278+
"EVAL_USERCENTRICS_API_5",
279+
"EVAL_USERCENTRICS_API_6",
280+
"EVAL_USERCENTRICS_BUTTON_0",
281+
"EVAL_WAITROSE_0",
282+
"EVAL_WAITROSE_1",
283+
"EVAL_WP_COOKIE_NOTICE_0",
284+
"EVAL_XE_TEST",
285+
"EVAL_XING_0",
286+
"EVAL_YOUTUBE_DESKTOP_0",
287+
"EVAL_YOUTUBE_MOBILE_0"
288+
]
289+
},
290+
"visible": {
291+
"$ref": "#/definitions/ElementSelector"
292+
},
293+
"exists": {
294+
"$ref": "#/definitions/ElementSelector"
295+
},
296+
"optional": {
297+
"type": "boolean"
298+
},
299+
"comment": {
300+
"type": "string"
301+
}
302+
}
303+
},
304+
"ElementSelector": {
305+
"anyOf": [
306+
{
307+
"type": "string"
308+
},
309+
{
310+
"type": "array",
311+
"items": {
312+
"type": "string"
313+
}
314+
}
315+
]
316+
},
317+
"VisibilityCheck": {
318+
"type": "string",
319+
"enum": [
320+
"any",
321+
"all",
322+
"none"
323+
]
324+
},
325+
"HideMethod": {
326+
"type": "string",
327+
"enum": [
328+
"display",
329+
"opacity"
330+
]
331+
}
332+
}
333+
}

scripts/generate-rule-schema.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { writeFileSync } from 'fs';
2+
import path from 'path';
3+
import { createGenerator } from 'ts-json-schema-generator';
4+
import { fileURLToPath } from 'url';
5+
6+
const rootDir = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
7+
8+
const config = {
9+
path: path.join(rootDir, 'lib/rules.ts'),
10+
type: 'AutoConsentCMPRule',
11+
};
12+
13+
const schema = createGenerator(config).createSchema(config.type);
14+
const schemaPath = path.join(rootDir, 'rules/schema.json');
15+
writeFileSync(schemaPath, JSON.stringify(schema, null, 4));
16+
console.log(`Schema generated and saved to ${schemaPath}`);

0 commit comments

Comments
 (0)