@guardian/consent-management-platform
Advanced tools
Comparing version 0.0.0-beta-20240129162949 to 0.0.0-beta-20240129231944
import type { CMP } from './types'; | ||
export { checkTopAdHasLoaded, clickAcceptAllCookies } from './testing/common-functions'; | ||
export declare const cmp: CMP; | ||
@@ -3,0 +4,0 @@ export declare const onConsent: () => Promise<import("./types").ConsentState>; |
@@ -1111,2 +1111,43 @@ import { log, removeCookie, storage } from '@guardian/libs'; | ||
const log_info = (message) => { | ||
console.log(`(cmp monitoring) info: ${message}`); | ||
}; | ||
const clickAcceptAllCookies = async (page, textToPrintToConsole = "Accept All") => { | ||
log_info(`Clicking on "${textToPrintToConsole}" on CMP`); | ||
const acceptAllButton = page.frameLocator('[id*="sp_message_iframe"]').locator('button.sp_choice_type_ACCEPT_ALL'); | ||
await acceptAllButton.click(); | ||
log_info(`Clicked on "${textToPrintToConsole}"`); | ||
}; | ||
const checkTopAdHasLoaded = async (page) => { | ||
log_info(`Waiting for interaction with GAM: Start`); | ||
const gamUrl = /https:\/\/securepubads.g.doubleclick.net\/gampad\/ads/; | ||
const getEncodedParamsFromRequest = (request, paramName) => { | ||
const url = new URL(request.url()); | ||
const param = url.searchParams.get(paramName); | ||
if (!param) | ||
return null; | ||
const paramDecoded = decodeURIComponent(param); | ||
const searchParams = new URLSearchParams(paramDecoded); | ||
return searchParams; | ||
}; | ||
const assertOnSlotFromRequest = (request, expectedSlot) => { | ||
const isURL = request.url().match(gamUrl); | ||
if (!isURL) | ||
return false; | ||
const searchParams = getEncodedParamsFromRequest(request, 'prev_scp'); | ||
if (searchParams === null) | ||
return false; | ||
const slot = searchParams.get('slot'); | ||
if (slot !== expectedSlot) | ||
return false; | ||
return true; | ||
}; | ||
const waitForGAMRequestForSlot = (page, slotExpected) => { | ||
return page.waitForRequest((request) => assertOnSlotFromRequest(request, slotExpected)); | ||
}; | ||
const gamRequestPromise = waitForGAMRequestForSlot(page, 'top-above-nav'); | ||
await gamRequestPromise; | ||
log_info(`Waiting for interaction with GAM: Complete`); | ||
}; | ||
if (!isServerSide) { | ||
@@ -1125,5 +1166,5 @@ window.guCmpHotFix ||= {}; | ||
if (window.guCmpHotFix.initialised) { | ||
if (window.guCmpHotFix.cmp?.version !== "0.0.0-beta-20240129162949") | ||
if (window.guCmpHotFix.cmp?.version !== "0.0.0-beta-20240129231944") | ||
console.warn('Two different versions of the CMP are running:', [ | ||
"0.0.0-beta-20240129162949", | ||
"0.0.0-beta-20240129231944", | ||
window.guCmpHotFix.cmp?.version, | ||
@@ -1166,3 +1207,3 @@ ]); | ||
showPrivacyManager, | ||
version: "0.0.0-beta-20240129162949", | ||
version: "0.0.0-beta-20240129231944", | ||
__isDisabled: isDisabled, | ||
@@ -1182,2 +1223,2 @@ __enable: enable, | ||
export { cmp, getConsentFor, onConsent, onConsentChange }; | ||
export { checkTopAdHasLoaded, clickAcceptAllCookies, cmp, getConsentFor, onConsent, onConsentChange }; |
@@ -1115,2 +1115,43 @@ 'use strict'; | ||
const log_info = (message) => { | ||
console.log(`(cmp monitoring) info: ${message}`); | ||
}; | ||
const clickAcceptAllCookies = async (page, textToPrintToConsole = "Accept All") => { | ||
log_info(`Clicking on "${textToPrintToConsole}" on CMP`); | ||
const acceptAllButton = page.frameLocator('[id*="sp_message_iframe"]').locator('button.sp_choice_type_ACCEPT_ALL'); | ||
await acceptAllButton.click(); | ||
log_info(`Clicked on "${textToPrintToConsole}"`); | ||
}; | ||
const checkTopAdHasLoaded = async (page) => { | ||
log_info(`Waiting for interaction with GAM: Start`); | ||
const gamUrl = /https:\/\/securepubads.g.doubleclick.net\/gampad\/ads/; | ||
const getEncodedParamsFromRequest = (request, paramName) => { | ||
const url = new URL(request.url()); | ||
const param = url.searchParams.get(paramName); | ||
if (!param) | ||
return null; | ||
const paramDecoded = decodeURIComponent(param); | ||
const searchParams = new URLSearchParams(paramDecoded); | ||
return searchParams; | ||
}; | ||
const assertOnSlotFromRequest = (request, expectedSlot) => { | ||
const isURL = request.url().match(gamUrl); | ||
if (!isURL) | ||
return false; | ||
const searchParams = getEncodedParamsFromRequest(request, 'prev_scp'); | ||
if (searchParams === null) | ||
return false; | ||
const slot = searchParams.get('slot'); | ||
if (slot !== expectedSlot) | ||
return false; | ||
return true; | ||
}; | ||
const waitForGAMRequestForSlot = (page, slotExpected) => { | ||
return page.waitForRequest((request) => assertOnSlotFromRequest(request, slotExpected)); | ||
}; | ||
const gamRequestPromise = waitForGAMRequestForSlot(page, 'top-above-nav'); | ||
await gamRequestPromise; | ||
log_info(`Waiting for interaction with GAM: Complete`); | ||
}; | ||
if (!isServerSide) { | ||
@@ -1129,5 +1170,5 @@ window.guCmpHotFix ||= {}; | ||
if (window.guCmpHotFix.initialised) { | ||
if (window.guCmpHotFix.cmp?.version !== "0.0.0-beta-20240129162949") | ||
if (window.guCmpHotFix.cmp?.version !== "0.0.0-beta-20240129231944") | ||
console.warn('Two different versions of the CMP are running:', [ | ||
"0.0.0-beta-20240129162949", | ||
"0.0.0-beta-20240129231944", | ||
window.guCmpHotFix.cmp?.version, | ||
@@ -1170,3 +1211,3 @@ ]); | ||
showPrivacyManager, | ||
version: "0.0.0-beta-20240129162949", | ||
version: "0.0.0-beta-20240129231944", | ||
__isDisabled: isDisabled, | ||
@@ -1186,2 +1227,4 @@ __enable: enable, | ||
exports.checkTopAdHasLoaded = checkTopAdHasLoaded; | ||
exports.clickAcceptAllCookies = clickAcceptAllCookies; | ||
exports.cmp = cmp; | ||
@@ -1188,0 +1231,0 @@ exports.getConsentFor = getConsentFor; |
{ | ||
"name": "@guardian/consent-management-platform", | ||
"version": "0.0.0-beta-20240129162949", | ||
"version": "0.0.0-beta-20240129231944", | ||
"description": "Consent management for *.theguardian.com.", | ||
@@ -42,56 +42,59 @@ "homepage": "https://github.com/guardian/consent-management-platform.git", | ||
"devDependencies": { | ||
"@babel/core": "^7.23.9", | ||
"@babel/core": "^7.23.2", | ||
"@babel/plugin-proposal-class-properties": "^7", | ||
"@babel/plugin-transform-runtime": "~7.23.9", | ||
"@babel/preset-env": "^7.23.9", | ||
"@babel/preset-typescript": "^7.23.3", | ||
"@babel/runtime": "^7.23.9", | ||
"@changesets/cli": "^2.27.1", | ||
"@guardian/eslint-config-typescript": "^9.0.2", | ||
"@guardian/libs": "16.0.1", | ||
"@guardian/prettier": "^8.0.0", | ||
"@babel/plugin-transform-runtime": "~7.23.2", | ||
"@babel/preset-env": "^7.23.2", | ||
"@babel/preset-typescript": "^7.23.2", | ||
"@babel/runtime": "^7.23.2", | ||
"@changesets/cli": "^2.26.2", | ||
"@guardian/eslint-config-typescript": "^7.0.0", | ||
"@guardian/libs": "15.0.0", | ||
"@guardian/prettier": "^4.0.0", | ||
"@guardian/tsconfig": "^0.2.0", | ||
"@rollup/plugin-babel": "^6.0.4", | ||
"@rollup/plugin-commonjs": "^25.0.7", | ||
"@rollup/plugin-html": "^1.0.3", | ||
"@rollup/plugin-node-resolve": "^15.2.3", | ||
"@rollup/plugin-replace": "^5.0.5", | ||
"@rollup/plugin-strip": "^3.0.4", | ||
"@rollup/plugin-terser": "^0.4.4", | ||
"@rollup/plugin-typescript": "^11.1.6", | ||
"@types/jest": "^29.5.11", | ||
"@types/mime": "^3.0.4", | ||
"@types/node": "^20.11.8", | ||
"axios": "^1.6.7", | ||
"conventional-changelog-conventionalcommits": "^7.0.2", | ||
"cypress": "^13.6.3", | ||
"@rollup/plugin-babel": "^6.0.3", | ||
"@rollup/plugin-commonjs": "^25.0.1", | ||
"@rollup/plugin-html": "^1.0.2", | ||
"@rollup/plugin-node-resolve": "^15.1.0", | ||
"@rollup/plugin-replace": "^5.0.2", | ||
"@rollup/plugin-strip": "^3.0.2", | ||
"@rollup/plugin-terser": "^0.4.3", | ||
"@rollup/plugin-typescript": "^11.1.1", | ||
"@types/jest": "^29.5.2", | ||
"@types/mime": "^3.0.1", | ||
"@types/node": "^20.3.3", | ||
"axios": "^1.6.3", | ||
"conventional-changelog-conventionalcommits": "^6.0.0", | ||
"cypress": "^12.14.0", | ||
"cypress-wait-until": "^3.0.1", | ||
"eslint": "^8.56.0", | ||
"eslint-plugin-cypress": "^2.15.1", | ||
"eslint": "^8.44.0", | ||
"eslint-plugin-cypress": "^2.13.3", | ||
"eslint-plugin-svelte3": "^4.0.0", | ||
"gh-pages": "^6.1.1", | ||
"husky": "^9.0.6", | ||
"jest": "^29.7.0", | ||
"gh-pages": "^5.0.0", | ||
"husky": "^8.0.3", | ||
"jest": "^29.5.0", | ||
"jest-environment-jsdom": "^29.5.0", | ||
"locate-character": "^3.0.0", | ||
"locate-character": "^2", | ||
"markdown-toc": "^1", | ||
"np": "^9.2.0", | ||
"np": "^8.0.4", | ||
"npm-run-all": "^4", | ||
"prettier": "^3.2.4", | ||
"prettier-plugin-svelte": "^3.1.2", | ||
"prettier": "^2.8.8", | ||
"prettier-plugin-svelte": "^2.10.1", | ||
"rollup": "^2.70.1", | ||
"rollup-plugin-css-only": "^4.5.2", | ||
"rollup-plugin-css-only": "^4.3.0", | ||
"rollup-plugin-livereload": "^2", | ||
"rollup-plugin-serve": "^2.0.2", | ||
"rollup-plugin-svelte": "^7.1.6", | ||
"serve": "^14.2.1", | ||
"start-server-and-test": "~2.0.3", | ||
"rollup-plugin-svelte": "^7.1.5", | ||
"serve": "^14.2.0", | ||
"start-server-and-test": "~2.0.0", | ||
"svelte": "~3.59.1", | ||
"tslib": "^2.6.2", | ||
"typescript": "~5.3.3", | ||
"wait-for-expect": "^3" | ||
"tslib": "^2.5.3", | ||
"typescript": "~5.1.3", | ||
"wait-for-expect": "^3", | ||
"playwright-core": "^1.40.1" | ||
}, | ||
"peerDependencies": { | ||
"@guardian/libs": "^15.0.0 || ^16.0.0" | ||
} | ||
"@guardian/libs": "^15.0.0", | ||
"playwright-core": "^1.40.1" | ||
}, | ||
"packageManager": "yarn@1.22.19" | ||
} |
112750
58
2899
2
51