@duckduckgo/autoconsent 1.0.8 → 2.0.0

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 (154) hide show
  1. package/.eslintrc.cjs +14 -0
  2. package/.vscode/settings.json +7 -0
  3. package/Jenkinsfile +68 -39
  4. package/api.md +104 -0
  5. package/dist/autoconsent.cjs.js +1 -1387
  6. package/dist/autoconsent.esm.js +1 -1379
  7. package/dist/autoconsent.playwright.js +1 -0
  8. package/dist/autoconsent.standalone.js +1 -0
  9. package/lib/cmps/all.ts +15 -10
  10. package/lib/cmps/base.ts +91 -91
  11. package/lib/cmps/consentmanager.ts +31 -19
  12. package/lib/cmps/consentomatic.ts +89 -0
  13. package/lib/cmps/cookiebot.ts +58 -55
  14. package/lib/cmps/evidon.ts +29 -18
  15. package/lib/cmps/onetrust.ts +32 -20
  16. package/lib/cmps/sourcepoint-frame.ts +102 -0
  17. package/lib/cmps/sourcepoint-top.ts +47 -0
  18. package/lib/cmps/trustarc-frame.ts +115 -0
  19. package/lib/cmps/trustarc-top.ts +91 -0
  20. package/lib/consentomatic/index.ts +233 -70
  21. package/lib/{web/consentomatic → consentomatic}/tools.ts +0 -0
  22. package/lib/eval-handler.ts +58 -0
  23. package/lib/index.ts +0 -2
  24. package/lib/messages.ts +100 -0
  25. package/lib/rule-executors.ts +108 -0
  26. package/lib/rules.ts +82 -0
  27. package/lib/types.ts +35 -0
  28. package/lib/utils.ts +64 -0
  29. package/lib/web.ts +283 -74
  30. package/package.json +17 -14
  31. package/playwright/content.ts +27 -0
  32. package/playwright/runner.ts +131 -0
  33. package/playwright/standalone.ts +36 -0
  34. package/playwright.config.ts +7 -0
  35. package/readme.md +57 -47
  36. package/rollup.config.js +23 -15
  37. package/rules/autoconsent/baden-wuerttemberg-de.json +7 -3
  38. package/rules/autoconsent/bundesregierung-de.json +5 -1
  39. package/rules/autoconsent/cc-banner.json +0 -1
  40. package/rules/autoconsent/cookie-notice.json +0 -1
  41. package/rules/autoconsent/cookieconsent.json +5 -6
  42. package/rules/autoconsent/destatis-de.json +0 -1
  43. package/rules/autoconsent/etsy.json +3 -2
  44. package/rules/autoconsent/eu-cookie-compliance.json +0 -1
  45. package/rules/autoconsent/hl-co-uk.json +8 -9
  46. package/rules/autoconsent/johnlewis.json +5 -2
  47. package/rules/autoconsent/notice-cookie.json +0 -1
  48. package/rules/autoconsent/osano.json +0 -1
  49. package/rules/autoconsent/tealium.json +4 -5
  50. package/rules/rules.json +44 -37
  51. package/tests/192.spec.ts +1 -1
  52. package/tests/arzt-auskunft.spec.ts +1 -1
  53. package/tests/asus.spec.ts +1 -1
  54. package/tests/ausopen.spec.ts +1 -1
  55. package/tests/aws.amazon.spec.ts +1 -1
  56. package/tests/baden-wuerttemberg.spec.ts +1 -1
  57. package/tests/borlabs.spec.ts +1 -1
  58. package/tests/bundesregierung.spec.ts +5 -2
  59. package/tests/ccbanner.spec.ts +1 -1
  60. package/tests/consentmanager.spec.ts +3 -3
  61. package/tests/cookiebot.spec.ts +8 -2
  62. package/tests/cookieconsent.spec.ts +1 -1
  63. package/tests/cookielawinfo.spec.ts +1 -1
  64. package/tests/cookienotice.spec.ts +1 -1
  65. package/tests/corona-in-zahlen.spec.ts +1 -1
  66. package/tests/deepl.spec.ts +1 -1
  67. package/tests/destatis.spec.ts +1 -1
  68. package/tests/didomi.spec.ts +6 -2
  69. package/tests/drupal.spec.ts +8 -0
  70. package/tests/dunelm.spec.ts +1 -1
  71. package/tests/etsy.spec.ts +1 -1
  72. package/tests/eu-cookie-compliance-banner.spec.ts +1 -1
  73. package/tests/evidon.spec.ts +1 -1
  74. package/tests/fundingchoices.spec.ts +2 -1
  75. package/tests/gov-uk.spec.ts +1 -1
  76. package/tests/hl-co-uk.spec.ts +1 -1
  77. package/tests/hubspot.spec.ts +1 -1
  78. package/tests/ionos.spec.ts +1 -1
  79. package/tests/johnlewis.spec.ts +2 -2
  80. package/tests/klaro.spec.ts +1 -1
  81. package/tests/marksandspencer.spec.ts +1 -1
  82. package/tests/mediamarkt.spec.ts +1 -1
  83. package/tests/metoffice-gov-uk.spec.ts +1 -1
  84. package/tests/microsoft.spec.ts +1 -1
  85. package/tests/moneysavingexpert.spec.ts +1 -1
  86. package/tests/motor-talk.spec.ts +1 -1
  87. package/tests/national-lottery.spec.ts +1 -1
  88. package/tests/netflix.spec.ts +1 -1
  89. package/tests/nhs.spec.ts +1 -1
  90. package/tests/notice-cookie.spec.ts +1 -1
  91. package/tests/obi.spec.ts +1 -1
  92. package/tests/oil.spec.ts +1 -1
  93. package/tests/onetrust.spec.ts +10 -1
  94. package/tests/osano.spec.ts +1 -1
  95. package/tests/otto.spec.ts +1 -1
  96. package/tests/paypal.spec.ts +1 -1
  97. package/tests/quantcast.spec.ts +4 -1
  98. package/tests/snigel.spec.ts +1 -1
  99. package/tests/sourcepoint.spec.ts +8 -8
  100. package/tests/springer.spec.ts +1 -1
  101. package/tests/steampowered.spec.ts +1 -1
  102. package/tests/tealium.spec.ts +1 -1
  103. package/tests/testcmp.spec.ts +1 -1
  104. package/tests/thalia.spec.ts +1 -1
  105. package/tests/thefreedictionary.spec.ts +1 -1
  106. package/tests/trustarc.spec.ts +25 -4
  107. package/tests/usercentrics-1.spec.ts +1 -1
  108. package/tests/uswitch.spec.ts +1 -1
  109. package/tests/vodafone.spec.ts +1 -1
  110. package/tests/waitrose.spec.ts +1 -1
  111. package/tests/wetransfer.spec.ts +1 -1
  112. package/tests/wordpressgdpr.spec.ts +1 -1
  113. package/tests/xing.spec.ts +1 -1
  114. package/tsconfig.json +2 -2
  115. package/.eslintrc +0 -12
  116. package/cosmetics/rules.json +0 -110
  117. package/dist/autoconsent.puppet.js +0 -1078
  118. package/lib/cmps/all.js +0 -19
  119. package/lib/cmps/base.js +0 -174
  120. package/lib/cmps/consentmanager.js +0 -31
  121. package/lib/cmps/cookiebot.js +0 -77
  122. package/lib/cmps/evidon.js +0 -26
  123. package/lib/cmps/onetrust.js +0 -34
  124. package/lib/cmps/sourcepoint.js +0 -82
  125. package/lib/cmps/sourcepoint.ts +0 -95
  126. package/lib/cmps/trustarc.js +0 -106
  127. package/lib/cmps/trustarc.ts +0 -147
  128. package/lib/config.js +0 -1
  129. package/lib/consentomatic/index.js +0 -52
  130. package/lib/detector.js +0 -33
  131. package/lib/detector.ts +0 -34
  132. package/lib/hider.js +0 -13
  133. package/lib/hider.ts +0 -16
  134. package/lib/index.js +0 -4
  135. package/lib/messages.d.ts +0 -61
  136. package/lib/node.js +0 -35
  137. package/lib/node.ts +0 -43
  138. package/lib/puppet/tab.js +0 -121
  139. package/lib/puppet/tab.ts +0 -146
  140. package/lib/rules.d.ts +0 -80
  141. package/lib/tabwrapper.js +0 -67
  142. package/lib/tabwrapper.ts +0 -74
  143. package/lib/types.d.ts +0 -61
  144. package/lib/web/consentomatic/index.js +0 -188
  145. package/lib/web/consentomatic/index.ts +0 -249
  146. package/lib/web/consentomatic/tools.js +0 -177
  147. package/lib/web/content-utils.js +0 -29
  148. package/lib/web/content-utils.ts +0 -31
  149. package/lib/web/content.js +0 -89
  150. package/lib/web/content.ts +0 -80
  151. package/lib/web/tab.js +0 -112
  152. package/lib/web/tab.ts +0 -178
  153. package/lib/web.js +0 -95
  154. package/tests/runner.ts +0 -61
package/.eslintrc.cjs ADDED
@@ -0,0 +1,14 @@
1
+ module.exports = {
2
+ root: true,
3
+ parser: '@typescript-eslint/parser',
4
+ plugins: [
5
+ '@typescript-eslint',
6
+ ],
7
+ extends: [
8
+ 'eslint:recommended',
9
+ 'plugin:@typescript-eslint/recommended',
10
+ ],
11
+ rules: {
12
+ "@typescript-eslint/no-explicit-any": 0,
13
+ }
14
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "eslint.format.enable": true,
3
+ "eslint.validate": [
4
+ "typescript"
5
+ ],
6
+ "editor.tabSize": 2,
7
+ }
package/Jenkinsfile CHANGED
@@ -1,50 +1,79 @@
1
- properties([
2
- parameters([
3
- choice(name: 'CHANNEL', defaultValue: 'staging', choices: 'staging\nproduction')
4
- ]),
5
- ])
6
-
7
- node('docker && !gpu') {
8
-
9
- def img
10
- def commitHash
1
+ def runPlaywrightTests(resultDir) {
2
+ sh 'mkdir -p ./test-results'
3
+ sh """
4
+ PLAYWRIGHT_JUNIT_OUTPUT_NAME=results.xml npx playwright test --project webkit --reporter=junit || true
5
+ """
6
+ junit 'results.xml'
7
+ sh """
8
+ mkdir -p ${resultDir}/results/${BRANCH_NAME}/${BUILD_NUMBER}/$REGION/
9
+ mkdir -p ./test-results
10
+ mv ./test-results/ ${resultDir}/results/${BRANCH_NAME}/${BUILD_NUMBER}/$REGION/
11
+ """
12
+ }
11
13
 
12
- stage('Checkout') {
13
- checkout scm
14
- commitHash = sh(returnStdout: true, script: 'git log --pretty=format:\'%h\' -n 1').trim()
15
- currentBuild.description = "${commitHash}-${params.CHANNEL}"
14
+ def withEnvFile(envfile, Closure cb) {
15
+ def props = readProperties(file: envfile)
16
+ withEnv(props.collect{ entry -> "${entry.key}=${entry.value}" }) {
17
+ cb()
16
18
  }
19
+ }
17
20
 
18
- stage('Build Docker Image') {
19
- img = docker.build('autoconsent/build')
21
+ pipeline {
22
+ agent { label 'crawler-worker' }
23
+ parameters {
24
+ string(name: 'TEST_RESULT_ROOT', defaultValue: '/mnt/efs/users/smacbeth/autoconsent/ci', description: 'Where test results and configuration are stored')
20
25
  }
21
-
22
- img.inside() {
23
-
26
+ environment {
27
+ NODENV_VERSION = "14.15.4"
28
+ NODENV_ROOT = "/opt/nodeenv"
29
+ PATH = "/opt/nodenv/shims:/opt/nodenv/bin:$PATH"
30
+ }
31
+ stages {
32
+ stage('Checkout') {
33
+ steps {
34
+ checkout scm
35
+ }
36
+ }
37
+
24
38
  stage('Build') {
25
- sh 'cp -r /app/node_modules ./'
26
- sh 'npm run bundle'
39
+ steps {
40
+ sh '''
41
+ npm ci
42
+ npx playwright install webkit
43
+ '''
44
+ }
27
45
  }
28
-
29
- stage('Build rules') {
30
- sh 'node rules/build.js'
31
- sh 'rm -f rules/rules.min.*'
32
- sh "jq -c '. + { version: \"${commitHash}\" }' rules/rules.json > rules/rules.min.json"
33
- sh 'brotli --input rules/rules.min.json --output rules/rules.min.json.br'
34
- sh "gzip -9 rules/rules.min.json"
46
+
47
+ stage('Test: DE') {
48
+ steps {
49
+ withEnvFile("${params.TEST_RESULT_ROOT}/de.env") {
50
+ runPlaywrightTests(params.TEST_RESULT_ROOT)
51
+ }
52
+ }
35
53
  }
36
- }
37
-
38
- if (env.BRANCH_NAME == 'master') {
39
- stage('Publish') {
40
- sh "aws s3 cp rules/rules.min.json.br s3://cdn.cliqz.com/autoconsent/rules/${commitHash}.json.br --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-encoding br --content-type application/json --cache-control \"immutable\""
41
- sh "aws s3 cp rules/rules.min.json.gz s3://cdn.cliqz.com/autoconsent/rules/${commitHash}.json.gz --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-encoding gzip --content-type application/json --cache-control \"immutable\""
42
- sh "echo '{\"ruleVersion\":\"${commitHash}\",\"disabled\":[]}' > config.json"
43
- def fileName = 'config.json'
44
- if (params.CHANNEL == 'staging') {
45
- fileName = 'staging-config.json'
54
+
55
+ stage('Test: US') {
56
+ steps {
57
+ withEnvFile("${params.TEST_RESULT_ROOT}/us.env") {
58
+ runPlaywrightTests(params.TEST_RESULT_ROOT)
59
+ }
60
+ }
61
+ }
62
+
63
+ stage('Test: GB') {
64
+ steps {
65
+ withEnvFile("${params.TEST_RESULT_ROOT}/gb.env") {
66
+ runPlaywrightTests(params.TEST_RESULT_ROOT)
67
+ }
68
+ }
69
+ }
70
+
71
+ stage('Test: FR') {
72
+ steps {
73
+ withEnvFile("${params.TEST_RESULT_ROOT}/fr.env") {
74
+ runPlaywrightTests(params.TEST_RESULT_ROOT)
75
+ }
46
76
  }
47
- sh "aws s3 cp config.json s3://cdn.cliqz.com/autoconsent/${fileName} --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type application/json --cache-control \"max-age=3600\""
48
77
  }
49
78
  }
50
79
  }
package/api.md ADDED
@@ -0,0 +1,104 @@
1
+ # API
2
+
3
+ ## Content script
4
+ Most of autoconsent logic is contained in a content script that should be injected into every page. However, the high-level orchestration is controlled externally by a background service worker (in case of a web extension), or a native browser integration. Autoconsent sends and receives messages to the background worker using provided callables which mimic postMessage API:
5
+
6
+ ```typescript
7
+ const consent = new AutoConsent( // make sure not to leak anything to the page globals
8
+ chrome.runtime.sendMessage, // pass a function to send messages to the background worker
9
+ { // optionally, pass a config object
10
+ enabled: true,
11
+ autoAction: 'optOut',
12
+ disabledCmps: [],
13
+ enablePrehide: true,
14
+ detectRetries: 20,
15
+ },
16
+ { // optionally, pass JSON rules
17
+ autoconsent: [ ... ],
18
+ consentomatic: [ ... ],
19
+ }
20
+ );
21
+
22
+ // connect .receiveMessageCallback() to a platform-specific message receiver
23
+ chrome.runtime.onMessage.addListener((message: BackgroundMessage) => {
24
+ return Promise.resolve(
25
+ consent.receiveMessageCallback(message)
26
+ );
27
+ });
28
+ ```
29
+
30
+ ## Messaging API
31
+
32
+ For concrete message format, refer to [messages.ts](/lib/messages.ts).
33
+
34
+ The overall workflow is described below:
35
+
36
+ ```mermaid
37
+
38
+ sequenceDiagram
39
+ participant BG as Browser (e.g. background service worker)
40
+ participant CS as Autoconsent content script in page (isolated) world
41
+
42
+ Note over BG: Fetch declarative JSON rules and user settings
43
+ Note over CS: Autoconsent class is instantiated.<br/>Optionally, initConfig is passed to constructor
44
+
45
+ CS -->>+ BG: (if initConfig is not passed already)<br/>init
46
+ BG -->>- CS: initResp<br/>(contains user settings and JSON rules)
47
+
48
+ activate CS
49
+ Note right of CS: Parse rules and initialize autoconsent code
50
+ Note right of CS: apply prehideSelectors
51
+ Note right of CS: wait for DOMContentLoaded
52
+ Note right of CS: detect a CMP presence (not necessarily visible)
53
+
54
+ CS ->> BG: cmpDetected
55
+ Note right of CS: detect a visible cookie popup
56
+ CS ->> BG: popupFound
57
+ deactivate CS
58
+ activate BG
59
+ alt if config.autoAction is NOT defined
60
+ Note left of BG: decide when to trigger opt-in / opt-out
61
+ BG -->> CS: optIn / optOut
62
+ else if config.autoAction IS defined
63
+ Note right of CS: <br/>proceed immediately
64
+ end
65
+
66
+ deactivate BG
67
+
68
+ Note right of CS: execute opt-in / opt-out rules
69
+ CS ->> BG: optOutResult / optInResult
70
+
71
+ opt if not intermediate ruleset
72
+ CS ->> BG: autoconsentDone
73
+ end
74
+
75
+ opt optional
76
+ BG -->>+ CS: (optional) selfTest
77
+ Note right of CS: execute self-test rules
78
+ CS -->>- BG: selfTestResult
79
+ end
80
+ ```
81
+
82
+ ### Asynchronous eval rules
83
+
84
+ Some rulesets rely on [eval rules](/readme.md#eval) executed in page main context. Since the content script lives in an isolated world, it passes those calls to the more powerful background worker.
85
+
86
+ **Warning**: eval rules are potentially dangerous and should be avoided when possible.
87
+
88
+ ```mermaid
89
+ sequenceDiagram
90
+ participant P as Page main world
91
+ participant BG as Browser (e.g. background service worker)
92
+ participant CS as Autoconsent content script in page (isolated) world
93
+
94
+ Note over CS: Needs to evaluate <PAYLOAD> in the main world (e.g. interact with API)
95
+
96
+ CS ->> BG: { type: "eval", id: <UUID>, code: <PAYLOAD> }
97
+ activate BG
98
+ BG ->>+ P: evaluate <PAYLOAD> using platform-specific APIs<br/>e.g. chrome.scripting.executeScript()
99
+ P ->>- BG: evaluation <RESULT>
100
+ BG ->> CS: { type: "evalResp", id: <UUID>, result: <RESULT> }
101
+ deactivate BG
102
+
103
+ Note over CS: Continue rule execution (or fail with timeout)
104
+ ```