@adguard/agtree 2.2.0 → 3.0.0-alpha.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 (495) hide show
  1. package/README.md +1 -1
  2. package/dist/ast-utils/clone.js +61 -0
  3. package/dist/ast-utils/modifiers.js +53 -0
  4. package/dist/ast-utils/network-rules.js +41 -0
  5. package/dist/ast-utils/scriptlets.js +87 -0
  6. package/dist/common/abp-snippet-injection-body-common.js +23 -0
  7. package/dist/common/agent-common.js +56 -0
  8. package/dist/common/ubo-selector-common.js +17 -0
  9. package/dist/compatibility-tables/base.js +262 -0
  10. package/dist/compatibility-tables/compatibility-table-data.js +11 -0
  11. package/dist/compatibility-tables/modifiers.js +55 -0
  12. package/dist/compatibility-tables/platforms.js +76 -0
  13. package/dist/compatibility-tables/redirects.js +100 -0
  14. package/dist/compatibility-tables/schemas/base.js +111 -0
  15. package/dist/compatibility-tables/schemas/modifier.js +129 -0
  16. package/dist/compatibility-tables/schemas/platform.js +69 -0
  17. package/dist/compatibility-tables/schemas/redirect.js +29 -0
  18. package/dist/compatibility-tables/schemas/resource-type.js +36 -0
  19. package/dist/compatibility-tables/schemas/scriptlet.js +79 -0
  20. package/dist/compatibility-tables/scriptlets.js +28 -0
  21. package/dist/compatibility-tables/utils/platform-helpers.js +105 -0
  22. package/dist/compatibility-tables/utils/resource-type-helpers.js +61 -0
  23. package/dist/compatibility-tables/utils/zod-camelcase.js +25 -0
  24. package/dist/converter/base-interfaces/base-converter.js +59 -0
  25. package/dist/converter/base-interfaces/conversion-result.js +38 -0
  26. package/dist/converter/base-interfaces/rule-converter-base.js +60 -0
  27. package/dist/converter/comment/index.js +54 -0
  28. package/dist/converter/cosmetic/css.js +69 -0
  29. package/dist/converter/cosmetic/element-hiding.js +62 -0
  30. package/dist/converter/cosmetic/header-removal.js +123 -0
  31. package/dist/converter/cosmetic/html.js +379 -0
  32. package/dist/converter/cosmetic/index.js +118 -0
  33. package/dist/converter/cosmetic/rule-modifiers/adg.js +79 -0
  34. package/dist/converter/cosmetic/scriptlet.js +354 -0
  35. package/dist/converter/css/index.js +188 -0
  36. package/dist/converter/data/css.js +126 -0
  37. package/dist/converter/filter-list.js +88 -0
  38. package/dist/converter/index.js +8 -0
  39. package/dist/converter/misc/network-rule-modifier.js +311 -0
  40. package/dist/converter/network/index.js +99 -0
  41. package/dist/converter/raw-filter-list.js +56 -0
  42. package/dist/converter/rule.js +81 -0
  43. package/dist/deserializer/base-deserializer.js +29 -0
  44. package/dist/deserializer/comment/agent-comment-deserializer.js +79 -0
  45. package/dist/deserializer/comment/agent-deserializer.js +65 -0
  46. package/dist/deserializer/comment/comment-rule-deserializer.js +54 -0
  47. package/dist/deserializer/comment/config-comment-deserializer.js +111 -0
  48. package/dist/deserializer/comment/hint-comment-deserializer.js +72 -0
  49. package/dist/deserializer/comment/hint-deserializer.js +85 -0
  50. package/dist/deserializer/comment/metadata-comment-deserializer.js +69 -0
  51. package/dist/deserializer/comment/pre-processor-comment-deserializer.js +112 -0
  52. package/dist/deserializer/comment/simple-comment-deserializer.js +65 -0
  53. package/dist/deserializer/cosmetic/cosmetic-rule-deserializer.js +131 -0
  54. package/dist/deserializer/cosmetic/css-injection-body-deserializer.js +56 -0
  55. package/dist/deserializer/cosmetic/element-hiding-body-deserializer.js +48 -0
  56. package/dist/deserializer/cosmetic/scriptlet-body/abp-snippet-injection-body-deserializer.js +39 -0
  57. package/dist/deserializer/cosmetic/scriptlet-body/adg-scriptlet-injection-body-deserializer.js +40 -0
  58. package/dist/deserializer/cosmetic/scriptlet-body/scriptlet-body-deserializer.js +54 -0
  59. package/dist/deserializer/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-deserializer.js +38 -0
  60. package/dist/deserializer/empty-rule-deserializer.js +48 -0
  61. package/dist/deserializer/filterlist-deserializer.js +85 -0
  62. package/dist/deserializer/index.js +8 -0
  63. package/dist/deserializer/invalid-rule-deserializer.js +50 -0
  64. package/dist/deserializer/invalid-rule-error-node-deserializer.js +50 -0
  65. package/dist/deserializer/misc/domain-list-deserializer.js +64 -0
  66. package/dist/deserializer/misc/list-item-deserializer.js +69 -0
  67. package/dist/deserializer/misc/list-items-deserializer.js +30 -0
  68. package/dist/deserializer/misc/logical-expression-deserializer.js +196 -0
  69. package/dist/deserializer/misc/modifier-deserializer.js +87 -0
  70. package/dist/deserializer/misc/modifier-list-deserializer.js +61 -0
  71. package/dist/deserializer/misc/parameter-list-deserializer.js +64 -0
  72. package/dist/deserializer/misc/value-deserializer.js +50 -0
  73. package/dist/deserializer/network/host-rule-deserializer.js +67 -0
  74. package/dist/deserializer/network/hostname-list-deserializer.js +56 -0
  75. package/dist/deserializer/network/network-rule-deserializer.js +65 -0
  76. package/dist/deserializer/rule-deserializer.js +65 -0
  77. package/dist/deserializer/syntax-deserialization-map.js +21 -0
  78. package/dist/errors/adblock-syntax-error.js +39 -0
  79. package/dist/errors/binary-schema-mismatch-error.js +37 -0
  80. package/dist/errors/not-implemented-error.js +31 -0
  81. package/dist/errors/rule-conversion-error.js +26 -0
  82. package/dist/generator/base-generator.js +27 -0
  83. package/dist/generator/comment/agent-comment-generator.js +31 -0
  84. package/dist/generator/comment/agent-generator.js +36 -0
  85. package/dist/generator/comment/comment-rule-generator.js +47 -0
  86. package/dist/generator/comment/config-comment-generator.js +45 -0
  87. package/dist/generator/comment/hint-comment-generator.js +28 -0
  88. package/dist/generator/comment/hint-generator.js +33 -0
  89. package/dist/generator/comment/metadata-comment-generator.js +33 -0
  90. package/dist/generator/comment/pre-processor-comment-generator.js +48 -0
  91. package/dist/generator/comment/simple-comment-generator.js +29 -0
  92. package/dist/generator/cosmetic/body/abp-snippet-injection-body-generator.js +38 -0
  93. package/dist/generator/cosmetic/body/adg-scriptlet-injection-body-generator.js +43 -0
  94. package/dist/generator/cosmetic/body/ubo-scriptlet-injection-body-generator.js +45 -0
  95. package/dist/generator/cosmetic/cosmetic-rule-body-generator.js +94 -0
  96. package/dist/generator/cosmetic/cosmetic-rule-generator.js +54 -0
  97. package/dist/generator/cosmetic/cosmetic-rule-pattern-generator.js +42 -0
  98. package/dist/generator/css/adg-css-injection-generator.js +42 -0
  99. package/dist/generator/filterlist-generator.js +67 -0
  100. package/dist/generator/index.js +9 -0
  101. package/dist/generator/misc/domain-list-generator.js +26 -0
  102. package/dist/generator/misc/list-items-generator.js +39 -0
  103. package/dist/generator/misc/logical-expression-generator.js +48 -0
  104. package/dist/generator/misc/modifier-generator.js +34 -0
  105. package/dist/generator/misc/modifier-list-generator.js +29 -0
  106. package/dist/generator/misc/parameter-list-generator.js +41 -0
  107. package/dist/generator/misc/value-generator.js +24 -0
  108. package/dist/generator/network/host-rule-generator.js +39 -0
  109. package/dist/generator/network/network-rule-generator.js +38 -0
  110. package/dist/generator/rule-generator.js +65 -0
  111. package/dist/index.js +70 -0
  112. package/dist/marshalling-utils/comment/agent-comment-common.js +21 -0
  113. package/dist/marshalling-utils/comment/agent-common.js +40 -0
  114. package/dist/marshalling-utils/comment/config-comment-common.js +54 -0
  115. package/dist/marshalling-utils/comment/hint-comment-common.js +22 -0
  116. package/dist/marshalling-utils/comment/hint-common.js +56 -0
  117. package/dist/marshalling-utils/comment/metadata-comment-common.js +41 -0
  118. package/dist/marshalling-utils/comment/pre-processor-comment-common.js +59 -0
  119. package/dist/marshalling-utils/comment/simple-comment-common.js +22 -0
  120. package/dist/marshalling-utils/cosmetic/body/abp-snippet-injection-body-common.js +61 -0
  121. package/dist/marshalling-utils/cosmetic/body/adg-scriptlet-injection-body-common.js +66 -0
  122. package/dist/marshalling-utils/cosmetic/body/css-injection-body-common.js +24 -0
  123. package/dist/marshalling-utils/cosmetic/body/element-hiding-body-common.js +21 -0
  124. package/dist/marshalling-utils/cosmetic/body/ubo-scriptlet-injection-body-common.js +114 -0
  125. package/dist/marshalling-utils/cosmetic/cosmetic-rule-common.js +48 -0
  126. package/dist/marshalling-utils/empty-rule-common.js +20 -0
  127. package/dist/marshalling-utils/filter-list-common.js +21 -0
  128. package/dist/marshalling-utils/invalid-rule-common.js +21 -0
  129. package/dist/marshalling-utils/invalid-rule-error-node-common.js +22 -0
  130. package/dist/marshalling-utils/misc/binary-type-common.js +66 -0
  131. package/dist/marshalling-utils/misc/domain-list-common.js +36 -0
  132. package/dist/marshalling-utils/misc/host-rule-common.js +25 -0
  133. package/dist/marshalling-utils/misc/hostname-list-common.js +21 -0
  134. package/dist/marshalling-utils/misc/list-item-common.js +22 -0
  135. package/dist/marshalling-utils/misc/logical-expression-common.js +83 -0
  136. package/dist/marshalling-utils/misc/modifier-common.js +231 -0
  137. package/dist/marshalling-utils/misc/modifier-list-common.js +21 -0
  138. package/dist/marshalling-utils/misc/parameter-list-common.js +21 -0
  139. package/dist/marshalling-utils/misc/value-common.js +22 -0
  140. package/dist/marshalling-utils/network/network-rule-common.js +25 -0
  141. package/dist/marshalling-utils/syntax-serialization-map.js +30 -0
  142. package/dist/nodes/index.js +168 -0
  143. package/dist/package.json.js +9 -0
  144. package/dist/parser/base-parser.js +30 -0
  145. package/dist/parser/comment/agent-comment-parser.js +119 -0
  146. package/dist/parser/comment/agent-parser.js +110 -0
  147. package/dist/parser/comment/comment-parser.js +108 -0
  148. package/dist/parser/comment/config-comment-parser.js +137 -0
  149. package/dist/parser/comment/hint-comment-parser.js +117 -0
  150. package/dist/parser/comment/hint-parser.js +129 -0
  151. package/dist/parser/comment/metadata-comment-parser.js +129 -0
  152. package/dist/parser/comment/preprocessor-parser.js +199 -0
  153. package/dist/parser/comment/simple-comment-parser.js +106 -0
  154. package/dist/parser/cosmetic/body/abp-snippet-injection-body-parser.js +79 -0
  155. package/dist/parser/cosmetic/body/adg-scriptlet-injection-body-parser.js +149 -0
  156. package/dist/parser/cosmetic/body/ubo-scriptlet-injection-body-parser.js +110 -0
  157. package/dist/parser/cosmetic/cosmetic-rule-parser.js +453 -0
  158. package/dist/parser/css/adg-css-injection-parser.js +208 -0
  159. package/dist/parser/css/balancing.js +94 -0
  160. package/dist/parser/css/constants.js +18 -0
  161. package/dist/parser/css/css-token-stream.js +343 -0
  162. package/dist/parser/css/ubo-selector-parser.js +369 -0
  163. package/dist/parser/filterlist-parser.js +102 -0
  164. package/dist/parser/index.js +12 -0
  165. package/dist/parser/misc/app-list-parser.js +45 -0
  166. package/dist/parser/misc/domain-list-parser.js +52 -0
  167. package/dist/parser/misc/list-items-parser.js +116 -0
  168. package/dist/parser/misc/logical-expression-parser.js +279 -0
  169. package/dist/parser/misc/method-list-parser.js +46 -0
  170. package/dist/parser/misc/modifier-list.js +70 -0
  171. package/dist/parser/misc/modifier-parser.js +89 -0
  172. package/dist/parser/misc/parameter-list-parser.js +75 -0
  173. package/dist/parser/misc/stealth-option-list-parser.js +46 -0
  174. package/dist/parser/misc/ubo-parameter-list-parser.js +149 -0
  175. package/dist/parser/misc/value-parser.js +37 -0
  176. package/dist/parser/network/host-rule-parser.js +130 -0
  177. package/dist/parser/network/network-rule-parser.js +117 -0
  178. package/dist/parser/options.js +23 -0
  179. package/dist/parser/rule-parser.js +192 -0
  180. package/dist/serializer/base-serializer.js +29 -0
  181. package/dist/serializer/comment/agent-comment-serializer.js +74 -0
  182. package/dist/serializer/comment/agent-serializer.js +59 -0
  183. package/dist/serializer/comment/comment-rule-serializer.js +105 -0
  184. package/dist/serializer/comment/config-comment-serializer.js +82 -0
  185. package/dist/serializer/comment/hint-comment-serializer.js +65 -0
  186. package/dist/serializer/comment/hint-serializer.js +54 -0
  187. package/dist/serializer/comment/metadata-comment-serializer.js +73 -0
  188. package/dist/serializer/comment/pre-processor-comment-serializer.js +71 -0
  189. package/dist/serializer/comment/simple-comment-serializer.js +52 -0
  190. package/dist/serializer/cosmetic/body/abp-snippet-injection-body-serializer.js +36 -0
  191. package/dist/serializer/cosmetic/body/adg-scriptlet-injection-body-serializer.js +36 -0
  192. package/dist/serializer/cosmetic/body/scriptlet-body-serializer.js +50 -0
  193. package/dist/serializer/cosmetic/body/ubo-scriptlet-injection-body-serializer.js +36 -0
  194. package/dist/serializer/cosmetic/cosmetic-rule-serializer.js +120 -0
  195. package/dist/serializer/cosmetic/css-injection-body-serializer.js +51 -0
  196. package/dist/serializer/cosmetic/element-hiding-body-serializer.js +40 -0
  197. package/dist/serializer/empty-rule-serializer.js +37 -0
  198. package/dist/serializer/filterlist-serializer.js +45 -0
  199. package/dist/serializer/index.js +7 -0
  200. package/dist/serializer/invalid-rule-error-node-serializer.js +41 -0
  201. package/dist/serializer/invalid-rule-serializer.js +40 -0
  202. package/dist/serializer/misc/domain-list-serializer.js +64 -0
  203. package/dist/serializer/misc/list-item-serializer.js +58 -0
  204. package/dist/serializer/misc/list-items-serializer.js +29 -0
  205. package/dist/serializer/misc/logical-expression-serializer.js +136 -0
  206. package/dist/serializer/misc/modifier-list-serializer.js +58 -0
  207. package/dist/serializer/misc/modifier-serializer.js +49 -0
  208. package/dist/serializer/misc/parameter-list-serializer.js +52 -0
  209. package/dist/serializer/misc/value-serializer.js +50 -0
  210. package/dist/serializer/network/host-rule-serializer.js +70 -0
  211. package/dist/serializer/network/hostname-list-serializer.js +53 -0
  212. package/dist/serializer/network/network-rule-serializer.js +54 -0
  213. package/dist/serializer/rule-serializer.js +61 -0
  214. package/dist/types/ast-utils/clone.d.ts +26 -0
  215. package/dist/types/ast-utils/filter-list.d.ts +11 -0
  216. package/dist/types/ast-utils/modifiers.d.ts +20 -0
  217. package/dist/types/ast-utils/network-rules.d.ts +15 -0
  218. package/dist/types/ast-utils/scriptlets.d.ts +52 -0
  219. package/dist/types/common/abp-snippet-injection-body-common.d.ts +15 -0
  220. package/dist/types/common/agent-common.d.ts +10 -0
  221. package/dist/types/common/ubo-selector-common.d.ts +10 -0
  222. package/dist/types/compatibility-tables/base.d.ts +157 -0
  223. package/dist/types/compatibility-tables/compatibility-table-data.d.ts +68 -0
  224. package/dist/types/compatibility-tables/index.d.ts +13 -0
  225. package/dist/types/compatibility-tables/modifiers.d.ts +22 -0
  226. package/dist/types/compatibility-tables/platforms.d.ts +49 -0
  227. package/dist/types/compatibility-tables/redirects.d.ts +33 -0
  228. package/dist/types/compatibility-tables/schemas/base.d.ts +124 -0
  229. package/dist/types/compatibility-tables/schemas/index.d.ts +8 -0
  230. package/dist/types/compatibility-tables/schemas/modifier.d.ts +36 -0
  231. package/dist/types/compatibility-tables/schemas/platform.d.ts +16 -0
  232. package/dist/types/compatibility-tables/schemas/redirect.d.ts +25 -0
  233. package/dist/types/compatibility-tables/schemas/resource-type.d.ts +41 -0
  234. package/dist/types/compatibility-tables/schemas/scriptlet.d.ts +31 -0
  235. package/dist/types/compatibility-tables/scriptlets.d.ts +15 -0
  236. package/dist/types/compatibility-tables/types.d.ts +34 -0
  237. package/dist/types/compatibility-tables/utils/platform-helpers.d.ts +44 -0
  238. package/dist/types/compatibility-tables/utils/resource-type-helpers.d.ts +20 -0
  239. package/dist/types/compatibility-tables/utils/zod-camelcase.d.ts +15 -0
  240. package/dist/types/converter/base-interfaces/base-converter.d.ts +42 -0
  241. package/dist/types/converter/base-interfaces/conversion-result.d.ts +43 -0
  242. package/dist/types/converter/base-interfaces/rule-converter-base.d.ts +44 -0
  243. package/dist/types/converter/comment/index.d.ts +23 -0
  244. package/dist/types/converter/cosmetic/css.d.ts +23 -0
  245. package/dist/types/converter/cosmetic/element-hiding.d.ts +23 -0
  246. package/dist/types/converter/cosmetic/header-removal.d.ts +37 -0
  247. package/dist/types/converter/cosmetic/html.d.ts +54 -0
  248. package/dist/types/converter/cosmetic/index.d.ts +33 -0
  249. package/dist/types/converter/cosmetic/rule-modifiers/adg.d.ts +21 -0
  250. package/dist/types/converter/cosmetic/scriptlet.d.ts +33 -0
  251. package/dist/types/converter/css/index.d.ts +40 -0
  252. package/dist/types/converter/data/css.d.ts +48 -0
  253. package/dist/types/converter/filter-list.d.ts +31 -0
  254. package/dist/types/converter/index.d.ts +5 -0
  255. package/dist/types/converter/misc/network-rule-modifier.d.ts +35 -0
  256. package/dist/types/converter/network/index.d.ts +33 -0
  257. package/dist/types/converter/raw-filter-list.d.ts +31 -0
  258. package/dist/types/converter/raw-rule.d.ts +28 -0
  259. package/dist/types/converter/rule.d.ts +37 -0
  260. package/dist/types/deserializer/base-deserializer.d.ts +15 -0
  261. package/dist/types/deserializer/comment/agent-comment-deserializer.d.ts +34 -0
  262. package/dist/types/deserializer/comment/agent-deserializer.d.ts +25 -0
  263. package/dist/types/deserializer/comment/comment-rule-deserializer.d.ts +16 -0
  264. package/dist/types/deserializer/comment/config-comment-deserializer.d.ts +27 -0
  265. package/dist/types/deserializer/comment/hint-comment-deserializer.d.ts +24 -0
  266. package/dist/types/deserializer/comment/hint-deserializer.d.ts +26 -0
  267. package/dist/types/deserializer/comment/metadata-comment-deserializer.d.ts +26 -0
  268. package/dist/types/deserializer/comment/pre-processor-comment-deserializer.d.ts +29 -0
  269. package/dist/types/deserializer/comment/simple-comment-deserializer.d.ts +26 -0
  270. package/dist/types/deserializer/cosmetic/cosmetic-rule-deserializer.d.ts +18 -0
  271. package/dist/types/deserializer/cosmetic/css-injection-body-deserializer.d.ts +15 -0
  272. package/dist/types/deserializer/cosmetic/element-hiding-body-deserializer.d.ts +16 -0
  273. package/dist/types/deserializer/cosmetic/scriptlet-body/abp-snippet-injection-body-deserializer.d.ts +17 -0
  274. package/dist/types/deserializer/cosmetic/scriptlet-body/adg-scriptlet-injection-body-deserializer.d.ts +18 -0
  275. package/dist/types/deserializer/cosmetic/scriptlet-body/scriptlet-body-deserializer.d.ts +19 -0
  276. package/dist/types/deserializer/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-deserializer.d.ts +17 -0
  277. package/dist/types/deserializer/empty-rule-deserializer.d.ts +16 -0
  278. package/dist/types/deserializer/filterlist-deserializer.d.ts +34 -0
  279. package/dist/types/deserializer/index.d.ts +2 -0
  280. package/dist/types/deserializer/invalid-rule-deserializer.d.ts +16 -0
  281. package/dist/types/deserializer/invalid-rule-error-node-deserializer.d.ts +16 -0
  282. package/dist/types/deserializer/misc/domain-list-deserializer.d.ts +15 -0
  283. package/dist/types/deserializer/misc/list-item-deserializer.d.ts +19 -0
  284. package/dist/types/deserializer/misc/list-items-deserializer.d.ts +16 -0
  285. package/dist/types/deserializer/misc/logical-expression-deserializer.d.ts +55 -0
  286. package/dist/types/deserializer/misc/modifier-deserializer.d.ts +18 -0
  287. package/dist/types/deserializer/misc/modifier-list-deserializer.d.ts +20 -0
  288. package/dist/types/deserializer/misc/parameter-list-deserializer.d.ts +18 -0
  289. package/dist/types/deserializer/misc/value-deserializer.d.ts +17 -0
  290. package/dist/types/deserializer/network/host-rule-deserializer.d.ts +18 -0
  291. package/dist/types/deserializer/network/hostname-list-deserializer.d.ts +15 -0
  292. package/dist/types/deserializer/network/network-rule-deserializer.d.ts +18 -0
  293. package/dist/types/deserializer/rule-deserializer.d.ts +17 -0
  294. package/dist/types/deserializer/syntax-deserialization-map.d.ts +2 -0
  295. package/dist/types/errors/adblock-syntax-error.d.ts +25 -0
  296. package/dist/types/errors/binary-schema-mismatch-error.d.ts +23 -0
  297. package/dist/types/errors/not-implemented-error.d.ts +14 -0
  298. package/dist/types/errors/rule-conversion-error.d.ts +14 -0
  299. package/dist/types/generator/base-generator.d.ts +12 -0
  300. package/dist/types/generator/comment/agent-comment-generator.d.ts +14 -0
  301. package/dist/types/generator/comment/agent-generator.d.ts +15 -0
  302. package/dist/types/generator/comment/comment-rule-generator.d.ts +14 -0
  303. package/dist/types/generator/comment/config-comment-generator.d.ts +14 -0
  304. package/dist/types/generator/comment/hint-comment-generator.d.ts +14 -0
  305. package/dist/types/generator/comment/hint-generator.d.ts +14 -0
  306. package/dist/types/generator/comment/index.d.ts +1 -0
  307. package/dist/types/generator/comment/metadata-comment-generator.d.ts +14 -0
  308. package/dist/types/generator/comment/pre-processor-comment-generator.d.ts +14 -0
  309. package/dist/types/generator/comment/simple-comment-generator.d.ts +14 -0
  310. package/dist/types/generator/cosmetic/body/abp-snippet-injection-body-generator.d.ts +15 -0
  311. package/dist/types/generator/cosmetic/body/adg-scriptlet-injection-body-generator.d.ts +21 -0
  312. package/dist/types/generator/cosmetic/body/ubo-scriptlet-injection-body-generator.d.ts +21 -0
  313. package/dist/types/generator/cosmetic/cosmetic-rule-body-generator.d.ts +20 -0
  314. package/dist/types/generator/cosmetic/cosmetic-rule-generator.d.ts +28 -0
  315. package/dist/types/generator/cosmetic/cosmetic-rule-pattern-generator.d.ts +18 -0
  316. package/dist/types/generator/cosmetic/index.d.ts +1 -0
  317. package/dist/types/generator/css/adg-css-injection-generator.d.ts +15 -0
  318. package/dist/types/generator/css/ubo-selector-generator.d.ts +14 -0
  319. package/dist/types/generator/filterlist-generator.d.ts +18 -0
  320. package/dist/types/generator/index.d.ts +3 -0
  321. package/dist/types/generator/misc/domain-list-generator.d.ts +15 -0
  322. package/dist/types/generator/misc/list-items-generator.d.ts +25 -0
  323. package/dist/types/generator/misc/logical-expression-generator.d.ts +14 -0
  324. package/dist/types/generator/misc/modifier-generator.d.ts +14 -0
  325. package/dist/types/generator/misc/modifier-list-generator.d.ts +14 -0
  326. package/dist/types/generator/misc/parameter-list-generator.d.ts +15 -0
  327. package/dist/types/generator/misc/value-generator.d.ts +14 -0
  328. package/dist/types/generator/network/host-rule-generator.d.ts +14 -0
  329. package/dist/types/generator/network/index.d.ts +2 -0
  330. package/dist/types/generator/network/network-rule-generator.d.ts +14 -0
  331. package/dist/types/generator/rule-generator.d.ts +24 -0
  332. package/dist/types/index.d.ts +55 -0
  333. package/dist/types/marshalling-utils/comment/agent-comment-common.d.ts +14 -0
  334. package/dist/types/marshalling-utils/comment/agent-common.d.ts +20 -0
  335. package/dist/types/marshalling-utils/comment/config-comment-common.d.ts +42 -0
  336. package/dist/types/marshalling-utils/comment/hint-comment-common.d.ts +15 -0
  337. package/dist/types/marshalling-utils/comment/hint-common.d.ts +33 -0
  338. package/dist/types/marshalling-utils/comment/metadata-comment-common.d.ts +21 -0
  339. package/dist/types/marshalling-utils/comment/pre-processor-comment-common.d.ts +37 -0
  340. package/dist/types/marshalling-utils/comment/simple-comment-common.d.ts +15 -0
  341. package/dist/types/marshalling-utils/cosmetic/body/abp-snippet-injection-body-common.d.ts +23 -0
  342. package/dist/types/marshalling-utils/cosmetic/body/adg-scriptlet-injection-body-common.d.ts +9 -0
  343. package/dist/types/marshalling-utils/cosmetic/body/css-injection-body-common.d.ts +17 -0
  344. package/dist/types/marshalling-utils/cosmetic/body/element-hiding-body-common.d.ts +14 -0
  345. package/dist/types/marshalling-utils/cosmetic/body/ubo-scriptlet-injection-body-common.d.ts +9 -0
  346. package/dist/types/marshalling-utils/cosmetic/cosmetic-rule-common.d.ts +28 -0
  347. package/dist/types/marshalling-utils/empty-rule-common.d.ts +13 -0
  348. package/dist/types/marshalling-utils/filter-list-common.d.ts +14 -0
  349. package/dist/types/marshalling-utils/invalid-rule-common.d.ts +14 -0
  350. package/dist/types/marshalling-utils/invalid-rule-error-node-common.d.ts +15 -0
  351. package/dist/types/marshalling-utils/misc/binary-type-common.d.ts +57 -0
  352. package/dist/types/marshalling-utils/misc/domain-list-common.d.ts +24 -0
  353. package/dist/types/marshalling-utils/misc/host-rule-common.d.ts +18 -0
  354. package/dist/types/marshalling-utils/misc/hostname-list-common.d.ts +14 -0
  355. package/dist/types/marshalling-utils/misc/list-item-common.d.ts +15 -0
  356. package/dist/types/marshalling-utils/misc/logical-expression-common.d.ts +47 -0
  357. package/dist/types/marshalling-utils/misc/modifier-common.d.ts +41 -0
  358. package/dist/types/marshalling-utils/misc/modifier-list-common.d.ts +14 -0
  359. package/dist/types/marshalling-utils/misc/parameter-list-common.d.ts +14 -0
  360. package/dist/types/marshalling-utils/misc/value-common.d.ts +15 -0
  361. package/dist/types/marshalling-utils/network/network-rule-common.d.ts +18 -0
  362. package/dist/types/marshalling-utils/syntax-serialization-map.d.ts +2 -0
  363. package/dist/types/nodes/index.d.ts +1183 -0
  364. package/dist/types/parser/base-parser.d.ts +16 -0
  365. package/dist/types/parser/comment/agent-comment-parser.d.ts +42 -0
  366. package/dist/types/parser/comment/agent-parser.d.ts +33 -0
  367. package/dist/types/parser/comment/comment-parser.d.ts +76 -0
  368. package/dist/types/parser/comment/config-comment-parser.d.ts +31 -0
  369. package/dist/types/parser/comment/hint-comment-parser.d.ts +33 -0
  370. package/dist/types/parser/comment/hint-parser.d.ts +30 -0
  371. package/dist/types/parser/comment/metadata-comment-parser.d.ts +29 -0
  372. package/dist/types/parser/comment/preprocessor-parser.d.ts +43 -0
  373. package/dist/types/parser/comment/simple-comment-parser.d.ts +33 -0
  374. package/dist/types/parser/cosmetic/body/abp-snippet-injection-body-parser.d.ts +34 -0
  375. package/dist/types/parser/cosmetic/body/adg-scriptlet-injection-body-parser.d.ts +47 -0
  376. package/dist/types/parser/cosmetic/body/ubo-scriptlet-injection-body-parser.d.ts +44 -0
  377. package/dist/types/parser/cosmetic/cosmetic-rule-parser.d.ts +51 -0
  378. package/dist/types/parser/css/adg-css-injection-parser.d.ts +28 -0
  379. package/dist/types/parser/css/balancing.d.ts +36 -0
  380. package/dist/types/parser/css/constants.d.ts +10 -0
  381. package/dist/types/parser/css/css-token-stream.d.ts +210 -0
  382. package/dist/types/parser/css/ubo-selector-parser.d.ts +46 -0
  383. package/dist/types/parser/filterlist-parser.d.ts +29 -0
  384. package/dist/types/parser/index.d.ts +6 -0
  385. package/dist/types/parser/misc/app-list-parser.d.ts +22 -0
  386. package/dist/types/parser/misc/domain-list-parser.d.ts +26 -0
  387. package/dist/types/parser/misc/list-items-parser.d.ts +37 -0
  388. package/dist/types/parser/misc/logical-expression-parser.d.ts +42 -0
  389. package/dist/types/parser/misc/method-list-parser.d.ts +22 -0
  390. package/dist/types/parser/misc/modifier-list.d.ts +24 -0
  391. package/dist/types/parser/misc/modifier-parser.d.ts +21 -0
  392. package/dist/types/parser/misc/parameter-list-parser.d.ts +17 -0
  393. package/dist/types/parser/misc/stealth-option-list-parser.d.ts +22 -0
  394. package/dist/types/parser/misc/ubo-parameter-list-parser.d.ts +21 -0
  395. package/dist/types/parser/misc/value-parser.d.ts +18 -0
  396. package/dist/types/parser/network/host-rule-parser.d.ts +35 -0
  397. package/dist/types/parser/network/network-rule-parser.d.ts +31 -0
  398. package/dist/types/parser/options.d.ts +41 -0
  399. package/dist/types/parser/rule-parser.d.ts +78 -0
  400. package/dist/types/serializer/base-serializer.d.ts +15 -0
  401. package/dist/types/serializer/comment/agent-comment-serializer.d.ts +34 -0
  402. package/dist/types/serializer/comment/agent-serializer.d.ts +15 -0
  403. package/dist/types/serializer/comment/comment-rule-serializer.d.ts +68 -0
  404. package/dist/types/serializer/comment/config-comment-serializer.d.ts +25 -0
  405. package/dist/types/serializer/comment/hint-comment-serializer.d.ts +23 -0
  406. package/dist/types/serializer/comment/hint-serializer.d.ts +24 -0
  407. package/dist/types/serializer/comment/metadata-comment-serializer.d.ts +25 -0
  408. package/dist/types/serializer/comment/pre-processor-comment-serializer.d.ts +28 -0
  409. package/dist/types/serializer/comment/simple-comment-serializer.d.ts +24 -0
  410. package/dist/types/serializer/cosmetic/body/abp-snippet-injection-body-serializer.d.ts +25 -0
  411. package/dist/types/serializer/cosmetic/body/adg-scriptlet-injection-body-serializer.d.ts +25 -0
  412. package/dist/types/serializer/cosmetic/body/scriptlet-body-serializer.d.ts +17 -0
  413. package/dist/types/serializer/cosmetic/body/ubo-scriptlet-injection-body-serializer.d.ts +25 -0
  414. package/dist/types/serializer/cosmetic/cosmetic-rule-serializer.d.ts +19 -0
  415. package/dist/types/serializer/cosmetic/css-injection-body-serializer.d.ts +15 -0
  416. package/dist/types/serializer/cosmetic/element-hiding-body-serializer.d.ts +15 -0
  417. package/dist/types/serializer/empty-rule-serializer.d.ts +15 -0
  418. package/dist/types/serializer/filterlist-serializer.d.ts +15 -0
  419. package/dist/types/serializer/index.d.ts +1 -0
  420. package/dist/types/serializer/invalid-rule-error-node-serializer.d.ts +15 -0
  421. package/dist/types/serializer/invalid-rule-serializer.d.ts +15 -0
  422. package/dist/types/serializer/misc/domain-list-serializer.d.ts +21 -0
  423. package/dist/types/serializer/misc/list-item-serializer.d.ts +16 -0
  424. package/dist/types/serializer/misc/list-items-serializer.d.ts +15 -0
  425. package/dist/types/serializer/misc/logical-expression-serializer.d.ts +52 -0
  426. package/dist/types/serializer/misc/modifier-list-serializer.d.ts +20 -0
  427. package/dist/types/serializer/misc/modifier-serializer.d.ts +18 -0
  428. package/dist/types/serializer/misc/parameter-list-serializer.d.ts +17 -0
  429. package/dist/types/serializer/misc/value-serializer.d.ts +17 -0
  430. package/dist/types/serializer/network/host-rule-serializer.d.ts +30 -0
  431. package/dist/types/serializer/network/hostname-list-serializer.d.ts +15 -0
  432. package/dist/types/serializer/network/network-rule-serializer.d.ts +18 -0
  433. package/dist/types/serializer/rule-serializer.d.ts +17 -0
  434. package/dist/types/utils/adblockers.d.ts +49 -0
  435. package/dist/types/utils/binary-schema-version.d.ts +9 -0
  436. package/dist/types/utils/byte-buffer.d.ts +54 -0
  437. package/dist/types/utils/categorizer.d.ts +14 -0
  438. package/dist/types/utils/clone.d.ts +15 -0
  439. package/dist/types/utils/constants.d.ts +188 -0
  440. package/dist/types/utils/cosmetic-rule-separator.d.ts +45 -0
  441. package/dist/types/utils/deep-freeze.d.ts +13 -0
  442. package/dist/types/utils/domain.d.ts +29 -0
  443. package/dist/types/utils/error.d.ts +8 -0
  444. package/dist/types/utils/index.d.ts +15 -0
  445. package/dist/types/utils/input-byte-buffer.d.ts +146 -0
  446. package/dist/types/utils/is-chromium.d.ts +7 -0
  447. package/dist/types/utils/logical-expression.d.ts +45 -0
  448. package/dist/types/utils/multi-value-map.d.ts +16 -0
  449. package/dist/types/utils/output-byte-buffer.d.ts +132 -0
  450. package/dist/types/utils/position-provider.d.ts +46 -0
  451. package/dist/types/utils/quotes.d.ts +94 -0
  452. package/dist/types/utils/regexp.d.ts +54 -0
  453. package/dist/types/utils/storage-interface.d.ts +23 -0
  454. package/dist/types/utils/string.d.ts +280 -0
  455. package/dist/types/utils/text-decoder-polyfill.d.ts +14 -0
  456. package/dist/types/utils/text-encoder-polyfill.d.ts +18 -0
  457. package/dist/types/utils/type-guards.d.ts +47 -0
  458. package/dist/types/validator/constants.d.ts +89 -0
  459. package/dist/types/validator/helpers.d.ts +37 -0
  460. package/dist/types/validator/index.d.ts +38 -0
  461. package/dist/types/validator/value.d.ts +12 -0
  462. package/dist/types/version.d.ts +5 -0
  463. package/dist/utils/adblockers.js +56 -0
  464. package/dist/utils/binary-schema-version.js +17 -0
  465. package/dist/utils/byte-buffer.js +91 -0
  466. package/dist/utils/categorizer.js +44 -0
  467. package/dist/utils/clone.js +28 -0
  468. package/dist/utils/constants.js +249 -0
  469. package/dist/utils/cosmetic-rule-separator.js +127 -0
  470. package/dist/utils/deep-freeze.js +32 -0
  471. package/dist/utils/domain.js +59 -0
  472. package/dist/utils/error.js +49 -0
  473. package/dist/utils/index.js +21 -0
  474. package/dist/utils/input-byte-buffer.js +265 -0
  475. package/dist/utils/is-chromium.js +20 -0
  476. package/dist/utils/logical-expression.js +92 -0
  477. package/dist/utils/multi-value-map.js +33 -0
  478. package/dist/utils/output-byte-buffer.js +231 -0
  479. package/dist/utils/position-provider.js +73 -0
  480. package/dist/utils/quotes.js +214 -0
  481. package/dist/utils/regexp.js +176 -0
  482. package/dist/utils/string.js +559 -0
  483. package/dist/utils/text-decoder-polyfill.js +107 -0
  484. package/dist/utils/text-encoder-polyfill.js +78 -0
  485. package/dist/utils/type-guards.js +47 -0
  486. package/dist/validator/constants.js +210 -0
  487. package/dist/validator/helpers.js +45 -0
  488. package/dist/validator/index.js +174 -0
  489. package/dist/validator/value.js +568 -0
  490. package/dist/version.js +18 -0
  491. package/package.json +61 -39
  492. package/dist/agtree.d.ts +0 -4155
  493. package/dist/agtree.js +0 -15819
  494. package/dist/agtree.mjs +0 -15720
  495. package/dist/compatibility-table-data.js +0 -12782
@@ -0,0 +1,568 @@
1
+ /*
2
+ * AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
3
+ * (c) 2024 Adguard Software Ltd.
4
+ * Released under the MIT license
5
+ * https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
6
+ */
7
+ import { AdblockSyntaxError } from '../errors/adblock-syntax-error.js';
8
+ import { AppListParser } from '../parser/misc/app-list-parser.js';
9
+ import { DomainListParser } from '../parser/misc/domain-list-parser.js';
10
+ import { MethodListParser } from '../parser/misc/method-list-parser.js';
11
+ import { StealthOptionListParser } from '../parser/misc/stealth-option-list-parser.js';
12
+ import { DomainUtils } from '../utils/domain.js';
13
+ import { QuoteUtils, QuoteType } from '../utils/quotes.js';
14
+ import { SEMICOLON, SPACE, BACKSLASH, COMMA, PIPE, EQUALS, WILDCARD, DOT, OPEN_PARENTHESIS, CLOSE_PARENTHESIS } from '../utils/constants.js';
15
+ import { getValueRequiredValidationResult, getInvalidValidationResult } from './helpers.js';
16
+ import { SOURCE_DATA_ERROR_PREFIX, VALIDATION_ERROR_PREFIX, ALLOWED_CSP_DIRECTIVES, REFERRER_POLICY_DIRECTIVES, ALLOWED_PERMISSION_DIRECTIVES, ALLOWED_METHODS, ALLOWED_STEALTH_OPTIONS, EMPTY_PERMISSIONS_ALLOWLIST, APP_NAME_ALLOWED_CHARS, PERMISSIONS_TOKEN_SELF } from './constants.js';
17
+ import { defaultParserOptions } from '../parser/options.js';
18
+ import { isString } from '../utils/type-guards.js';
19
+
20
+ /**
21
+ * Pre-defined available validators for modifiers with custom `value_format`.
22
+ */
23
+ const CustomValueFormatValidatorName = {
24
+ App: 'pipe_separated_apps',
25
+ Csp: 'csp_value',
26
+ // there are some differences between $domain and $denyallow
27
+ DenyAllow: 'pipe_separated_denyallow_domains',
28
+ Domain: 'pipe_separated_domains',
29
+ Method: 'pipe_separated_methods',
30
+ Permissions: 'permissions_value',
31
+ ReferrerPolicy: 'referrerpolicy_value',
32
+ StealthOption: 'pipe_separated_stealth_options',
33
+ };
34
+ /**
35
+ * Checks whether the `chunk` of app name (which if splitted by dot `.`) is valid.
36
+ * Only letters, numbers, and underscore `_` are allowed.
37
+ *
38
+ * @param chunk Chunk of app name to check.
39
+ *
40
+ * @returns True if the `chunk` is valid part of app name, false otherwise.
41
+ */
42
+ const isValidAppNameChunk = (chunk) => {
43
+ // e.g. 'Example..exe'
44
+ if (chunk.length === 0) {
45
+ return false;
46
+ }
47
+ for (let i = 0; i < chunk.length; i += 1) {
48
+ const char = chunk[i];
49
+ if (!APP_NAME_ALLOWED_CHARS.has(char)) {
50
+ return false;
51
+ }
52
+ }
53
+ return true;
54
+ };
55
+ /**
56
+ * Checks whether the given `value` is valid app name as $app modifier value.
57
+ *
58
+ * @param value App name to check.
59
+ *
60
+ * @returns True if the `value` is valid app name, false otherwise.
61
+ */
62
+ const isValidAppModifierValue = (value) => {
63
+ // $app modifier does not support wildcard tld
64
+ // https://adguard.app/kb/general/ad-filtering/create-own-filters/#app-modifier
65
+ if (value.includes(WILDCARD)) {
66
+ return false;
67
+ }
68
+ return value
69
+ .split(DOT)
70
+ .every((chunk) => isValidAppNameChunk(chunk));
71
+ };
72
+ /**
73
+ * Checks whether the given `value` is valid HTTP method as $method modifier value.
74
+ *
75
+ * @param value Method to check.
76
+ *
77
+ * @returns True if the `value` is valid HTTP method, false otherwise.
78
+ */
79
+ const isValidMethodModifierValue = (value) => {
80
+ return ALLOWED_METHODS.has(value);
81
+ };
82
+ /**
83
+ * Checks whether the given `value` is valid option as $stealth modifier value.
84
+ *
85
+ * @param value Stealth option to check.
86
+ *
87
+ * @returns True if the `value` is valid stealth option, false otherwise.
88
+ */
89
+ const isValidStealthModifierValue = (value) => {
90
+ return ALLOWED_STEALTH_OPTIONS.has(value);
91
+ };
92
+ /**
93
+ * Checks whether the given `rawOrigin` is valid as Permissions Allowlist origin.
94
+ *
95
+ * @see {@link https://w3c.github.io/webappsec-permissions-policy/#allowlists}
96
+ *
97
+ * @param rawOrigin The raw origin.
98
+ *
99
+ * @returns True if the origin is valid, false otherwise.
100
+ */
101
+ const isValidPermissionsOrigin = (rawOrigin) => {
102
+ // origins should be quoted by double quote
103
+ const actualQuoteType = QuoteUtils.getStringQuoteType(rawOrigin);
104
+ if (actualQuoteType !== QuoteType.Double) {
105
+ return false;
106
+ }
107
+ const origin = QuoteUtils.removeQuotes(rawOrigin);
108
+ try {
109
+ // validate the origin by URL constructor
110
+ // https://w3c.github.io/webappsec-permissions-policy/#algo-parse-policy-directive
111
+ new URL(origin);
112
+ }
113
+ catch (e) {
114
+ return false;
115
+ }
116
+ return true;
117
+ };
118
+ /**
119
+ * Checks whether the given `value` is valid domain as $denyallow modifier value.
120
+ * Important: wildcard tld are not supported, compared to $domain.
121
+ *
122
+ * @param value Value to check.
123
+ *
124
+ * @returns True if the `value` is valid domain and does not contain wildcard `*`, false otherwise.
125
+ */
126
+ const isValidDenyAllowModifierValue = (value) => {
127
+ // $denyallow modifier does not support wildcard tld
128
+ // https://adguard.app/kb/general/ad-filtering/create-own-filters/#denyallow-modifier
129
+ // but here we are simply checking whether the value contains wildcard `*`, not ends with `.*`
130
+ if (value.includes(WILDCARD)) {
131
+ return false;
132
+ }
133
+ // TODO: add cache for domains validation
134
+ return DomainUtils.isValidDomainOrHostname(value);
135
+ };
136
+ /**
137
+ * Checks whether the given `value` is valid domain as $domain modifier value.
138
+ *
139
+ * @param value Value to check.
140
+ *
141
+ * @returns True if the `value` is valid domain, false otherwise.
142
+ */
143
+ const isValidDomainModifierValue = (value) => {
144
+ // TODO: add cache for domains validation
145
+ return DomainUtils.isValidDomainOrHostname(value);
146
+ };
147
+ /**
148
+ * Checks whether the all list items' exceptions are `false`.
149
+ * Those items which `exception` is `true` is to be specified in the validation result error message.
150
+ *
151
+ * @param modifierName Modifier name.
152
+ * @param listItems List items to check.
153
+ *
154
+ * @returns Validation result.
155
+ */
156
+ const customNoNegatedListItemsValidator = (modifierName, listItems) => {
157
+ const negatedValues = [];
158
+ listItems.forEach((listItem) => {
159
+ if (listItem.exception) {
160
+ negatedValues.push(listItem.value);
161
+ }
162
+ });
163
+ if (negatedValues.length > 0) {
164
+ const valuesToStr = QuoteUtils.quoteAndJoinStrings(negatedValues);
165
+ return getInvalidValidationResult(`${VALIDATION_ERROR_PREFIX.NOT_NEGATABLE_VALUE}: '${modifierName}': ${valuesToStr}`);
166
+ }
167
+ return { valid: true };
168
+ };
169
+ /**
170
+ * Checks whether the all list items' exceptions are consistent,
171
+ * i.e. all items are either negated or not negated.
172
+ *
173
+ * The `exception` value of the first item is used as a reference, and all other items are checked against it.
174
+ * Those items which `exception` is not consistent with the first item
175
+ * is to be specified in the validation result error message.
176
+ *
177
+ * @see {@link https://adguard.com/kb/general/ad-filtering/create-own-filters/#method-modifier}
178
+ *
179
+ * @param modifierName Modifier name.
180
+ * @param listItems List items to check.
181
+ *
182
+ * @returns Validation result.
183
+ */
184
+ const customConsistentExceptionsValidator = (modifierName, listItems) => {
185
+ const firstException = listItems[0].exception;
186
+ const nonConsistentItemValues = [];
187
+ listItems.forEach((listItem) => {
188
+ if (listItem.exception !== firstException) {
189
+ nonConsistentItemValues.push(listItem.value);
190
+ }
191
+ });
192
+ if (nonConsistentItemValues.length > 0) {
193
+ const valuesToStr = QuoteUtils.quoteAndJoinStrings(nonConsistentItemValues);
194
+ return getInvalidValidationResult(`${VALIDATION_ERROR_PREFIX.MIXED_NEGATIONS}: '${modifierName}': ${valuesToStr}`);
195
+ }
196
+ return { valid: true };
197
+ };
198
+ /**
199
+ * Checks whether the given `modifier` value is valid.
200
+ * Supposed to validate the value of modifiers which values are lists separated by pipe `|` —
201
+ * $app, $domain, $denyallow, $method.
202
+ *
203
+ * @param modifier Modifier AST node.
204
+ * @param listParser Parser function for parsing modifier value
205
+ * which is supposed to be a list separated by pipe `|`.
206
+ * @param isValidListItem Predicate function for checking of modifier's list item validity,
207
+ * e.g. $denyallow modifier does not support wildcard tld, but $domain does.
208
+ * @param customListValidator Optional; custom validator for specific modifier,
209
+ * e.g. $denyallow modifier does not support negated domains.
210
+ *
211
+ * @returns Result of modifier domains validation.
212
+ */
213
+ const validateListItemsModifier = (modifier, listParser, isValidListItem, customListValidator) => {
214
+ const modifierName = modifier.name.value;
215
+ const defaultInvalidValueResult = getValueRequiredValidationResult(modifierName);
216
+ if (!modifier.value?.value) {
217
+ return defaultInvalidValueResult;
218
+ }
219
+ let theList;
220
+ try {
221
+ theList = listParser(modifier.value.value, defaultParserOptions, 0, PIPE);
222
+ }
223
+ catch (e) {
224
+ if (e instanceof AdblockSyntaxError) {
225
+ return {
226
+ valid: false,
227
+ error: e.message,
228
+ };
229
+ }
230
+ return defaultInvalidValueResult;
231
+ }
232
+ const invalidListItems = [];
233
+ theList.children.forEach((item) => {
234
+ // different validators are used for $denyallow and $domain modifiers
235
+ // because of different requirements and restrictions
236
+ if (!isValidListItem(item.value)) {
237
+ invalidListItems.push(item.value);
238
+ }
239
+ });
240
+ if (invalidListItems.length > 0) {
241
+ const itemsToStr = QuoteUtils.quoteAndJoinStrings(invalidListItems);
242
+ return getInvalidValidationResult(`${VALIDATION_ERROR_PREFIX.INVALID_LIST_VALUES}: '${modifierName}': ${itemsToStr}`);
243
+ }
244
+ // IMPORTANT: run custom validator after all other checks
245
+ // Some lists should be fully checked, not just the list items:
246
+ // e.g. Safari does not support allowed and disallowed domains for $domain in the same list
247
+ // or domains cannot be negated for $denyallow modifier
248
+ if (customListValidator) {
249
+ return customListValidator(modifierName, theList.children);
250
+ }
251
+ return { valid: true };
252
+ };
253
+ /**
254
+ * Validates 'pipe_separated_apps' custom value format.
255
+ * Used for $app modifier.
256
+ *
257
+ * @param modifier Modifier AST node.
258
+ *
259
+ * @returns Validation result.
260
+ */
261
+ const validatePipeSeparatedApps = (modifier) => {
262
+ return validateListItemsModifier(modifier, (raw) => AppListParser.parse(raw), isValidAppModifierValue);
263
+ };
264
+ /**
265
+ * Validates 'pipe_separated_denyallow_domains' custom value format.
266
+ * Used for $denyallow modifier.
267
+ *
268
+ * @param modifier Modifier AST node.
269
+ *
270
+ * @returns Validation result.
271
+ */
272
+ const validatePipeSeparatedDenyAllowDomains = (modifier) => {
273
+ return validateListItemsModifier(modifier, DomainListParser.parse, isValidDenyAllowModifierValue, customNoNegatedListItemsValidator);
274
+ };
275
+ /**
276
+ * Validates 'pipe_separated_domains' custom value format.
277
+ * Used for $domains modifier.
278
+ *
279
+ * @param modifier Modifier AST node.
280
+ *
281
+ * @returns Validation result.
282
+ */
283
+ const validatePipeSeparatedDomains = (modifier) => {
284
+ return validateListItemsModifier(modifier, DomainListParser.parse, isValidDomainModifierValue);
285
+ };
286
+ /**
287
+ * Validates 'pipe_separated_methods' custom value format.
288
+ * Used for $method modifier.
289
+ *
290
+ * @param modifier Modifier AST node.
291
+ *
292
+ * @returns Validation result.
293
+ */
294
+ const validatePipeSeparatedMethods = (modifier) => {
295
+ return validateListItemsModifier(modifier, (raw) => MethodListParser.parse(raw), isValidMethodModifierValue, customConsistentExceptionsValidator);
296
+ };
297
+ /**
298
+ * Validates 'pipe_separated_stealth_options' custom value format.
299
+ * Used for $stealth modifier.
300
+ *
301
+ * @param modifier Modifier AST node.
302
+ *
303
+ * @returns Validation result.
304
+ */
305
+ const validatePipeSeparatedStealthOptions = (modifier) => {
306
+ return validateListItemsModifier(modifier, (raw) => StealthOptionListParser.parse(raw), isValidStealthModifierValue, customNoNegatedListItemsValidator);
307
+ };
308
+ /**
309
+ * Validates `csp_value` custom value format.
310
+ * Used for $csp modifier.
311
+ *
312
+ * @param modifier Modifier AST node.
313
+ *
314
+ * @returns Validation result.
315
+ */
316
+ const validateCspValue = (modifier) => {
317
+ const modifierName = modifier.name.value;
318
+ if (!modifier.value?.value) {
319
+ return getValueRequiredValidationResult(modifierName);
320
+ }
321
+ // $csp modifier value may contain multiple directives
322
+ // e.g. "csp=child-src 'none'; frame-src 'self' *; worker-src 'none'"
323
+ const policyDirectives = modifier.value.value
324
+ .split(SEMICOLON)
325
+ // rule with $csp modifier may end with semicolon
326
+ // e.g. "$csp=sandbox allow-same-origin;"
327
+ // TODO: add predicate helper for `(i) => !!i`
328
+ .filter((i) => !!i);
329
+ const invalidValueValidationResult = getInvalidValidationResult(`${VALIDATION_ERROR_PREFIX.VALUE_INVALID}: '${modifierName}': "${modifier.value.value}"`);
330
+ if (policyDirectives.length === 0) {
331
+ return invalidValueValidationResult;
332
+ }
333
+ const invalidDirectives = [];
334
+ for (let i = 0; i < policyDirectives.length; i += 1) {
335
+ const policyDirective = policyDirectives[i].trim();
336
+ if (!policyDirective) {
337
+ return invalidValueValidationResult;
338
+ }
339
+ const chunks = policyDirective.split(SPACE);
340
+ const [directive, ...valueChunks] = chunks;
341
+ // e.g. "csp=child-src 'none'; ; worker-src 'none'"
342
+ // validator it here ↑
343
+ if (!directive) {
344
+ return invalidValueValidationResult;
345
+ }
346
+ if (!ALLOWED_CSP_DIRECTIVES.has(directive)) {
347
+ // e.g. "csp='child-src' 'none'"
348
+ if (ALLOWED_CSP_DIRECTIVES.has(QuoteUtils.removeQuotes(directive))) {
349
+ return getInvalidValidationResult(`${VALIDATION_ERROR_PREFIX.NO_CSP_DIRECTIVE_QUOTE}: '${modifierName}': ${directive}`);
350
+ }
351
+ invalidDirectives.push(directive);
352
+ continue;
353
+ }
354
+ if (valueChunks.length === 0) {
355
+ return getInvalidValidationResult(`${VALIDATION_ERROR_PREFIX.NO_CSP_VALUE}: '${modifierName}': '${directive}'`);
356
+ }
357
+ }
358
+ if (invalidDirectives.length > 0) {
359
+ const directivesToStr = QuoteUtils.quoteAndJoinStrings(invalidDirectives, QuoteType.Double);
360
+ return getInvalidValidationResult(`${VALIDATION_ERROR_PREFIX.INVALID_CSP_DIRECTIVES}: '${modifierName}': ${directivesToStr}`);
361
+ }
362
+ return { valid: true };
363
+ };
364
+ /**
365
+ * Validates permission allowlist origins in the value of $permissions modifier.
366
+ *
367
+ * @see {@link https://w3c.github.io/webappsec-permissions-policy/#allowlists}
368
+ *
369
+ * @param allowlistChunks Array of allowlist chunks.
370
+ * @param directive Permission directive name.
371
+ * @param modifierName Modifier name.
372
+ *
373
+ * @returns Validation result.
374
+ */
375
+ const validatePermissionAllowlistOrigins = (allowlistChunks, directive, modifierName) => {
376
+ const invalidOrigins = [];
377
+ for (let i = 0; i < allowlistChunks.length; i += 1) {
378
+ const chunk = allowlistChunks[i].trim();
379
+ // skip few spaces between origins (they were splitted by space)
380
+ // e.g. 'geolocation=("https://example.com" "https://*.example.com")'
381
+ if (chunk.length === 0) {
382
+ continue;
383
+ }
384
+ /**
385
+ * 'self' should be checked case-insensitively
386
+ *
387
+ * @see {@link https://w3c.github.io/webappsec-permissions-policy/#algo-parse-policy-directive}
388
+ *
389
+ * @example 'geolocation=(self)'
390
+ */
391
+ if (chunk.toLowerCase() === PERMISSIONS_TOKEN_SELF) {
392
+ continue;
393
+ }
394
+ if (QuoteUtils.getStringQuoteType(chunk) !== QuoteType.Double) {
395
+ return getInvalidValidationResult(
396
+ // eslint-disable-next-line max-len
397
+ `${VALIDATION_ERROR_PREFIX.INVALID_PERMISSION_ORIGIN_QUOTES}: '${modifierName}': '${directive}': '${QuoteUtils.removeQuotes(chunk)}'`);
398
+ }
399
+ if (!isValidPermissionsOrigin(chunk)) {
400
+ invalidOrigins.push(chunk);
401
+ }
402
+ }
403
+ if (invalidOrigins.length > 0) {
404
+ const originsToStr = QuoteUtils.quoteAndJoinStrings(invalidOrigins);
405
+ return getInvalidValidationResult(
406
+ // eslint-disable-next-line max-len
407
+ `${VALIDATION_ERROR_PREFIX.INVALID_PERMISSION_ORIGINS}: '${modifierName}': '${directive}': ${originsToStr}`);
408
+ }
409
+ return { valid: true };
410
+ };
411
+ /**
412
+ * Validates permission allowlist in the modifier value.
413
+ *
414
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Permissions_Policy#allowlists}
415
+ * @see {@link https://w3c.github.io/webappsec-permissions-policy/#allowlists}
416
+ *
417
+ * @param allowlist Allowlist value.
418
+ * @param directive Permission directive name.
419
+ * @param modifierName Modifier name.
420
+ *
421
+ * @returns Validation result.
422
+ */
423
+ const validatePermissionAllowlist = (allowlist, directive, modifierName) => {
424
+ // `*` is one of available permissions tokens
425
+ // e.g. 'fullscreen=*'
426
+ // https://w3c.github.io/webappsec-permissions-policy/#structured-header-serialization
427
+ if (allowlist === WILDCARD
428
+ // e.g. 'autoplay=()'
429
+ || allowlist === EMPTY_PERMISSIONS_ALLOWLIST) {
430
+ return { valid: true };
431
+ }
432
+ if (!(allowlist.startsWith(OPEN_PARENTHESIS) && allowlist.endsWith(CLOSE_PARENTHESIS))) {
433
+ return getInvalidValidationResult(`${VALIDATION_ERROR_PREFIX.VALUE_INVALID}: '${modifierName}'`);
434
+ }
435
+ const allowlistChunks = allowlist.slice(1, -1).split(SPACE);
436
+ return validatePermissionAllowlistOrigins(allowlistChunks, directive, modifierName);
437
+ };
438
+ /**
439
+ * Validates single permission in the modifier value.
440
+ *
441
+ * @param permission Single permission value.
442
+ * @param modifierName Modifier name.
443
+ * @param modifierValue Modifier value.
444
+ *
445
+ * @returns Validation result.
446
+ */
447
+ const validateSinglePermission = (permission, modifierName, modifierValue) => {
448
+ // empty permission in the rule
449
+ // e.g. 'permissions=storage-access=()\\, \\, camera=()'
450
+ // the validator is here ↑
451
+ if (!permission) {
452
+ return getInvalidValidationResult(`${VALIDATION_ERROR_PREFIX.VALUE_INVALID}: '${modifierName}'`);
453
+ }
454
+ if (permission.includes(COMMA)) {
455
+ return getInvalidValidationResult(`${VALIDATION_ERROR_PREFIX.NO_UNESCAPED_PERMISSION_COMMA}: '${modifierName}': '${modifierValue}'`);
456
+ }
457
+ const [directive, allowlist] = permission.split(EQUALS);
458
+ if (!ALLOWED_PERMISSION_DIRECTIVES.has(directive)) {
459
+ return getInvalidValidationResult(`${VALIDATION_ERROR_PREFIX.INVALID_PERMISSION_DIRECTIVE}: '${modifierName}': '${directive}'`);
460
+ }
461
+ return validatePermissionAllowlist(allowlist, directive, modifierName);
462
+ };
463
+ /**
464
+ * Validates `permissions_value` custom value format.
465
+ * Used for $permissions modifier.
466
+ *
467
+ * @param modifier Modifier AST node.
468
+ *
469
+ * @returns Validation result.
470
+ */
471
+ const validatePermissions = (modifier) => {
472
+ if (!modifier.value?.value) {
473
+ return getValueRequiredValidationResult(modifier.name.value);
474
+ }
475
+ const modifierName = modifier.name.value;
476
+ const modifierValue = modifier.value.value;
477
+ // multiple permissions may be separated by escaped commas
478
+ const permissions = modifier.value.value.split(`${BACKSLASH}${COMMA}`);
479
+ for (let i = 0; i < permissions.length; i += 1) {
480
+ const permission = permissions[i].trim();
481
+ const singlePermissionValidationResult = validateSinglePermission(permission, modifierName, modifierValue);
482
+ if (!singlePermissionValidationResult.valid) {
483
+ return singlePermissionValidationResult;
484
+ }
485
+ }
486
+ return { valid: true };
487
+ };
488
+ /**
489
+ * Validates `referrerpolicy_value` custom value format.
490
+ * Used for $referrerpolicy modifier.
491
+ *
492
+ * @param modifier Modifier AST node.
493
+ *
494
+ * @returns Validation result.
495
+ */
496
+ const validateReferrerPolicy = (modifier) => {
497
+ if (!modifier.value?.value) {
498
+ return getValueRequiredValidationResult(modifier.name.value);
499
+ }
500
+ const modifierName = modifier.name.value;
501
+ const modifierValue = modifier.value.value;
502
+ if (!REFERRER_POLICY_DIRECTIVES.has(modifierValue)) {
503
+ // eslint-disable-next-line max-len
504
+ return getInvalidValidationResult(`${VALIDATION_ERROR_PREFIX.INVALID_REFERRER_POLICY_DIRECTIVE}: '${modifierName}': '${modifierValue}'`);
505
+ }
506
+ return { valid: true };
507
+ };
508
+ /**
509
+ * Map of all available pre-defined validators for modifiers with custom `value_format`.
510
+ */
511
+ const CUSTOM_VALUE_FORMAT_MAP = {
512
+ [CustomValueFormatValidatorName.App]: validatePipeSeparatedApps,
513
+ [CustomValueFormatValidatorName.Csp]: validateCspValue,
514
+ [CustomValueFormatValidatorName.DenyAllow]: validatePipeSeparatedDenyAllowDomains,
515
+ [CustomValueFormatValidatorName.Domain]: validatePipeSeparatedDomains,
516
+ [CustomValueFormatValidatorName.Method]: validatePipeSeparatedMethods,
517
+ [CustomValueFormatValidatorName.Permissions]: validatePermissions,
518
+ [CustomValueFormatValidatorName.ReferrerPolicy]: validateReferrerPolicy,
519
+ [CustomValueFormatValidatorName.StealthOption]: validatePipeSeparatedStealthOptions,
520
+ };
521
+ /**
522
+ * Returns whether the given `valueFormat` is a valid custom value format validator name.
523
+ *
524
+ * @param valueFormat Value format for the modifier.
525
+ *
526
+ * @returns True if `valueFormat` is a supported pre-defined value format validator name, false otherwise.
527
+ */
528
+ const isCustomValueFormatValidator = (valueFormat) => {
529
+ return Object.keys(CUSTOM_VALUE_FORMAT_MAP).includes(valueFormat);
530
+ };
531
+ /**
532
+ * Checks whether the value for given `modifier` is valid.
533
+ *
534
+ * @param modifier Modifier AST node.
535
+ * @param valueFormat Value format for the modifier.
536
+ * @param valueFormatFlags Optional; RegExp flags for the value format.
537
+ *
538
+ * @returns Validation result.
539
+ */
540
+ const validateValue = (modifier, valueFormat, valueFormatFlags) => {
541
+ if (isCustomValueFormatValidator(valueFormat)) {
542
+ const validator = CUSTOM_VALUE_FORMAT_MAP[valueFormat];
543
+ return validator(modifier);
544
+ }
545
+ const modifierName = modifier.name.value;
546
+ if (!modifier.value?.value) {
547
+ return getValueRequiredValidationResult(modifierName);
548
+ }
549
+ let regExp;
550
+ try {
551
+ if (isString(valueFormatFlags)) {
552
+ regExp = new RegExp(valueFormat, valueFormatFlags);
553
+ }
554
+ else {
555
+ regExp = new RegExp(valueFormat);
556
+ }
557
+ }
558
+ catch (e) {
559
+ throw new Error(`${SOURCE_DATA_ERROR_PREFIX.INVALID_VALUE_FORMAT_REGEXP}: '${modifierName}'`);
560
+ }
561
+ const isValid = regExp.test(modifier.value?.value);
562
+ if (!isValid) {
563
+ return getInvalidValidationResult(`${VALIDATION_ERROR_PREFIX.VALUE_INVALID}: '${modifierName}'`);
564
+ }
565
+ return { valid: true };
566
+ };
567
+
568
+ export { validateValue };
@@ -0,0 +1,18 @@
1
+ /*
2
+ * AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
3
+ * (c) 2024 Adguard Software Ltd.
4
+ * Released under the MIT license
5
+ * https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
6
+ */
7
+ import { version } from './package.json.js';
8
+
9
+ /**
10
+ * @file AGTree version
11
+ */
12
+ // ! Notice:
13
+ // Don't export version from package.json directly, because if you run
14
+ // `tsc` in the root directory, it will generate `dist/types/src/version.d.ts`
15
+ // with wrong relative path to `package.json`. So we need this little "hack"
16
+ const AGTREE_VERSION = version;
17
+
18
+ export { AGTREE_VERSION };